animate whip (only visual; no collision detection)

This commit is contained in:
2025-02-28 14:11:57 +00:00
parent 54a4ed6d64
commit 39f4614f13
5 changed files with 65 additions and 72 deletions

View File

@@ -24,7 +24,7 @@ struct
val recoilLimit = 15
val attackedLimit = 55
val maxCharge = 60
val attackLengthLimit = 59
val mainAttackLimit = 19
(* constants for projectiles *)
val projectilePi: Real32.real = Real32.Math.pi / 180.0

View File

@@ -56,6 +56,7 @@ struct
open PlayerType
val {x, y, facing, mainAttack, ...} = player
in
(* todo: bring back attack
case mainAttack of
MAIN_ATTACKING {length, ...} =>
let
@@ -89,6 +90,8 @@ struct
(player, enemyMap, fallingMap)
end
| _ => (player, enemyMap, fallingMap)
*)
(player, enemyMap, fallingMap)
end
(* - Handle collisions when player's projectile hits enemy - *)

View File

@@ -6,7 +6,7 @@ struct
datatype main_attack =
MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool}
| MAIN_ATTACKING of int
| MAIN_THROWING
type defeated_enemies = {angle: int}

View File

@@ -87,7 +87,7 @@ struct
let
val attack =
if attackHeld andalso not mainAttackPressed then
MAIN_ATTACKING {length = 3, growing = true}
MAIN_ATTACKING 1
else
MAIN_NOT_ATTACKING
in
@@ -159,30 +159,19 @@ struct
getThrowPatches (defeteadEnemies, projectiles, player, acc)
else
helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc)
| MAIN_ATTACKING {length, growing} =>
| MAIN_ATTACKING amt =>
let
val mainAttack =
if growing then
if length < Constants.attackLengthLimit then
let val newLength = length + Constants.moveProjectileBy
in MAIN_ATTACKING {length = newLength, growing = true}
end
else
let
val newLength = length - Constants.moveProjectileBy
in
if newLength <= 0 then MAIN_NOT_ATTACKING
else MAIN_ATTACKING {length = newLength, growing = false}
end
val acc =
if amt = Constants.mainAttackLimit then
W_MAIN_ATTACK MAIN_NOT_ATTACKING :: acc
else
let
val newLength = length - Constants.moveProjectileBy
val amt = amt + 1
in
if newLength <= 0 then MAIN_NOT_ATTACKING
else MAIN_ATTACKING {length = newLength, growing = false}
W_MAIN_ATTACK (MAIN_ATTACKING amt) :: acc
end
in
W_MAIN_ATTACK_PRESSED true :: W_MAIN_ATTACK mainAttack :: acc
W_MAIN_ATTACK_PRESSED true :: acc
end
| MAIN_THROWING =>
if attackHeld then
@@ -469,17 +458,32 @@ struct
end
(*** DRAWING FUNCTIONS ***)
fun helpGetWhipVec (tlx, tly, ratio, xOffset, yOffset, pos, boxes, width, height, acc) =
if pos = Vector.length boxes then
Vector.concat acc
else
let
val {x, y} = Vector.sub (boxes, pos)
val x = tlx + x
val y = tly + y
val x = Real32.fromInt x * ratio + xOffset
val y = Real32.fromInt y * ratio + yOffset
val size = Whip.sizeReal
val acc = Box.lerp (x, y, size, size, width, height) :: acc
in
helpGetWhipVec (tlx, tly, ratio, xOffset, yOffset, pos + 1, boxes, width, height, acc)
end
fun getFieldVec (player: player, width, height) =
case #mainAttack player of
MAIN_ATTACKING {length, ...} =>
MAIN_ATTACKING amt =>
let
val frame = amt div 2
val {x, y, facing, ...} = player
val wratio = width / Constants.worldWidthReal
val hratio = height / Constants.worldHeightReal
val x =
case #facing player of
FACING_RIGHT => x + Constants.playerWidth
| FACING_LEFT => x - length
in
if wratio < hratio then
let
@@ -489,22 +493,15 @@ struct
else if height < scale then (scale - height) / 2.0
else 0.0
val x = Real32.fromInt x * wratio
val y = Real32.fromInt y * wratio + yOffset
val realLength = Real32.fromInt length * wratio
val realHeight = Constants.playerHeightReal * wratio
val {charge, ...} = player
val alpha = Real32.fromInt charge / 60.0
val boxes =
case facing of
FACING_RIGHT =>
Vector.sub (Whip.rightFrames, frame)
| FACING_LEFT =>
(* todo: change to leftFrames once that is implemented *)
Vector.sub (Whip.rightFrames, frame)
in
case facing of
FACING_RIGHT =>
ChainEdgeRight.lerp
(x, y, realLength, realHeight, width, height, 0.5, 0.5, 0.5)
| FACING_LEFT =>
ChainEdgeLeft.lerp
(x, y, realLength, realHeight, width, height, 0.5, 0.5, 0.5)
helpGetWhipVec (x, y, wratio, 0.0, yOffset, 0, boxes, width, height, [])
end
else
let
@@ -514,22 +511,15 @@ struct
else if width < scale then (scale - width) / 2.0
else 0.0
val x = Real32.fromInt x * hratio + xOffset
val y = Real32.fromInt y * hratio
val realLength = Real32.fromInt length * hratio
val realHeight = Constants.playerHeightReal * hratio
val {charge, ...} = player
val alpha = Real32.fromInt charge / 60.0
val boxes =
case facing of
FACING_RIGHT =>
Vector.sub (Whip.rightFrames, frame)
| FACING_LEFT =>
(* todo: change to leftFrames once that is implemented *)
Vector.sub (Whip.rightFrames, frame)
in
case facing of
FACING_RIGHT =>
ChainEdgeRight.lerp
(x, y, realLength, realHeight, width, height, 0.5, 0.5, 0.5)
| FACING_LEFT =>
ChainEdgeLeft.lerp
(x, y, realLength, realHeight, width, height, 0.5, 0.5, 0.5)
helpGetWhipVec (x, y, hratio, xOffset, 0.0, 0, boxes, width, height, [])
end
end
| _ => Vector.fromList []

View File

@@ -27,43 +27,43 @@ struct
]
val rf4 =
#[ {x = 192, y = 10}
, {x = 128, y = 15}
#[ {x = 96, y = 10}
, {x = 80, y = 15}
, {x = 64, y = 20}
, {x = 49, y = 25}
]
val rf5 =
#[ {x = 305, y = 25}
, {x = 241, y = 28}
, {x = 177, y = 25}
, {x = 113, y = 22}
#[ {x = 112, y = 25}
, {x = 96, y = 28}
, {x = 80, y = 25}
, {x = 64, y = 22}
, {x = 49, y = 25}
]
val rf6 =
#[ {x = 305, y = 25}
, {x = 241, y = 28}
, {x = 177, y = 25}
, {x = 113, y = 25}
#[ {x = 112, y = 25}
, {x = 96, y = 28}
, {x = 80, y = 25}
, {x = 64, y = 25}
, {x = 49, y = 25}
]
val rf7 =
#[ {x = 241, y = 31}
, {x = 177, y = 29}
, {x = 113, y = 27}
#[ {x = 96, y = 31}
, {x = 80, y = 29}
, {x = 64, y = 27}
, {x = 49, y = 25}
]
val rf8 =
#[ {x = 177, y = 33}
, {x = 113, y = 29}
#[ {x = 80, y = 33}
, {x = 64, y = 29}
, {x = 49, y = 25}
]
val rf9 =
#[ {x = 113, y = 31}
#[ {x = 64, y = 31}
, {x = 49, y = 25}
]