record pressedTime when player is performing mainAttack

This commit is contained in:
2025-08-29 12:46:41 +01:00
parent a58953e90d
commit 1f726539da
4 changed files with 18 additions and 13 deletions

View File

@@ -13,7 +13,7 @@ struct
, fallingEnemies , fallingEnemies
} = level } = level
val player = Player.runPhysicsAndInput (level, input) val player = Player.runPhysicsAndInput (level, input, time)
val enemyTree = Enemy.generateTree enemies val enemyTree = Enemy.generateTree enemies
val player = Player.checkEnemyCollisions (player, enemies, enemyTree) val player = Player.checkEnemyCollisions (player, enemies, enemyTree)

View File

@@ -6,7 +6,7 @@ struct
datatype main_attack = datatype main_attack =
MAIN_NOT_ATTACKING MAIN_NOT_ATTACKING
| MAIN_ATTACKING of int | MAIN_ATTACKING of {animTimer: int, timePressed: Time.time}
| MAIN_THROWING | MAIN_THROWING
type defeated_enemies = {angle: int} type defeated_enemies = {angle: int}

View File

@@ -148,7 +148,7 @@ struct
fun helpGet (player: player, x, y, xOffset, yOffset, ratio, rx, ry, windowWidth, windowHeight) = fun helpGet (player: player, x, y, xOffset, yOffset, ratio, rx, ry, windowWidth, windowHeight) =
case #mainAttack player of case #mainAttack player of
MAIN_ATTACKING amt => MAIN_ATTACKING {animTimer = amt, ...} =>
(case #facing player of (case #facing player of
FACING_RIGHT => FACING_RIGHT =>
let let

View File

@@ -91,11 +91,13 @@ struct
end end
(* called only when player has no projectiles or was not previously attacking *) (* called only when player has no projectiles or was not previously attacking *)
fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) = fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc, time) =
let let
val attack = val attack =
if attackHeld andalso not mainAttackPressed then MAIN_ATTACKING 0 if attackHeld andalso not mainAttackPressed then
else MAIN_NOT_ATTACKING MAIN_ATTACKING {animTimer = 0, timePressed = time}
else
MAIN_NOT_ATTACKING
in in
W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed) W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed)
:: W_MAIN_ATTACK attack :: acc :: W_MAIN_ATTACK attack :: acc
@@ -153,6 +155,7 @@ struct
, player , player
, acc , acc
, mainAttackPressed , mainAttackPressed
, time
) = ) =
case prevAttack of case prevAttack of
MAIN_NOT_ATTACKING => MAIN_NOT_ATTACKING =>
@@ -164,15 +167,16 @@ struct
* and there is more than one enemy *) * and there is more than one enemy *)
getThrowPatches (defeteadEnemies, projectiles, player, acc) getThrowPatches (defeteadEnemies, projectiles, player, acc)
else else
helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc, time)
| MAIN_ATTACKING amt => | MAIN_ATTACKING {animTimer = amt, timePressed} =>
let let
val acc = val acc =
if amt = Constants.mainAttackLimit then if amt = Constants.mainAttackLimit then
W_MAIN_ATTACK MAIN_NOT_ATTACKING :: acc W_MAIN_ATTACK MAIN_NOT_ATTACKING :: acc
else else
let val amt = amt + 1 let val amt = amt + 1
in W_MAIN_ATTACK (MAIN_ATTACKING amt) :: acc val attack = MAIN_ATTACKING {animTimer = amt, timePressed = timePressed}
in W_MAIN_ATTACK attack :: acc
end end
in in
W_MAIN_ATTACK_PRESSED true :: acc W_MAIN_ATTACK_PRESSED true :: acc
@@ -181,9 +185,9 @@ struct
if attackHeld then if attackHeld then
acc acc
else else
helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc, time)
fun getInputPatches (player: player, input: FrameInputType.t, wallTree) = fun getInputPatches (player: player, input: FrameInputType.t, wallTree, time) =
let let
val val
{ x { x
@@ -218,6 +222,7 @@ struct
, player , player
, acc , acc
, mainAttackPressed , mainAttackPressed
, time
) )
val acc = getJumpPatches (player, jumpHeld, downHeld, acc, wallTree) val acc = getJumpPatches (player, jumpHeld, downHeld, acc, wallTree)
@@ -361,7 +366,7 @@ struct
end end
end) end)
fun runPhysicsAndInput (game: LevelType.level_type, input) = fun runPhysicsAndInput (game: LevelType.level_type, input, time) =
let let
val {player, walls, wallTree, platforms, platformTree, ...} = game val {player, walls, wallTree, platforms, platformTree, ...} = game
@@ -378,7 +383,7 @@ struct
* It's important to apply the recoil patches after handling input * It's important to apply the recoil patches after handling input
* because we want to act on the latest recoil state straight away. *) * because we want to act on the latest recoil state straight away. *)
case #recoil player of case #recoil player of
NO_RECOIL => getInputPatches (player, input, wallTree) NO_RECOIL => getInputPatches (player, input, wallTree, time)
| _ => [] | _ => []
val patches = val patches =