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 recoilLimit = 15
val attackedLimit = 55 val attackedLimit = 55
val maxCharge = 60 val maxCharge = 60
val attackLengthLimit = 59 val mainAttackLimit = 19
(* constants for projectiles *) (* constants for projectiles *)
val projectilePi: Real32.real = Real32.Math.pi / 180.0 val projectilePi: Real32.real = Real32.Math.pi / 180.0

View File

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

View File

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

View File

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

View File

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