a little more deliberate about timing of when player's patches should be applied

This commit is contained in:
2025-02-05 19:33:56 +00:00
parent e1e1228983
commit 7142f5dc66

View File

@@ -228,16 +228,16 @@ struct
acc acc
end end
fun getRecoilPatches player = fun getRecoilPatches (player, patches) =
case #recoil player of case #recoil player of
NO_RECOIL => [] NO_RECOIL => patches
| RECOIL_LEFT recoiled => | RECOIL_LEFT recoiled =>
(* if player is recoiling, don't accept or adjust any input. (* if player is recoiling, don't accept or adjust any input.
* However, if player has reached the recoil limit, exit the recoil * However, if player has reached the recoil limit, exit the recoil
* state and accept input. * state and accept input.
* *) * *)
if recoiled = Constants.recoilLimit then if recoiled = Constants.recoilLimit then
[W_RECOIL NO_RECOIL] W_RECOIL NO_RECOIL :: patches
else else
let let
val {x, y, health, attacked, facing, xAxis, ...} = player val {x, y, health, attacked, facing, xAxis, ...} = player
@@ -252,17 +252,13 @@ struct
val recoil = RECOIL_LEFT recoiled val recoil = RECOIL_LEFT recoiled
val facing = getFacing (facing, xAxis) val facing = getFacing (facing, xAxis)
in in
[ W_X x W_X x :: W_X_AXIS xAxis :: W_Y_AXIS yAxis
, W_X_AXIS xAxis :: W_JUMP_PRESSED jumpPressed :: W_RECOIL recoil :: W_FACING facing
, W_Y_AXIS yAxis :: patches
, W_JUMP_PRESSED jumpPressed
, W_RECOIL recoil
, W_FACING facing
]
end end
| RECOIL_RIGHT recoiled => | RECOIL_RIGHT recoiled =>
if recoiled = Constants.recoilLimit then if recoiled = Constants.recoilLimit then
[W_RECOIL NO_RECOIL] W_RECOIL NO_RECOIL :: patches
else else
let let
val {x, y, health, attacked, facing, xAxis, ...} = player val {x, y, health, attacked, facing, xAxis, ...} = player
@@ -275,13 +271,9 @@ struct
val recoil = RECOIL_RIGHT recoiled val recoil = RECOIL_RIGHT recoiled
val facing = getFacing (facing, xAxis) val facing = getFacing (facing, xAxis)
in in
[ W_X x W_X x :: W_X_AXIS xAxis :: W_Y_AXIS yAxis
, W_X_AXIS xAxis :: W_JUMP_PRESSED jumpPressed :: W_RECOIL recoil :: W_FACING facing
, W_Y_AXIS yAxis :: patches
, W_JUMP_PRESSED jumpPressed
, W_RECOIL recoil
, W_FACING facing
]
end end
fun helpMoveProjectiles (pos, projectiles, acc) = fun helpMoveProjectiles (pos, projectiles, acc) =
@@ -321,27 +313,25 @@ struct
val player = #player game val player = #player game
val patches = getProjectilePatches player val patches = getProjectilePatches player
val patches = getRecoilPatches (player, patches)
val player = PlayerPatch.withPatches (player, patches) val player = PlayerPatch.withPatches (player, patches)
val patches = getRecoilPatches player val patches =
val player = PlayerPatch.withPatches (player, patches) (* we only accept and handle input if player is not recoiling.
* It's important to apply the recoil patches after handling input
val player = * because we want to act on the latest recoil state straight away. *)
(* we only accept and handle input if player is not recoiling *)
case #recoil player of case #recoil player of
NO_RECOIL => NO_RECOIL => getInputPatches (player, input)
let val patches = getInputPatches (player, input) | _ => []
in PlayerPatch.withPatches (player, patches)
end
| _ => player
(* animate projectiles *)
val player = val player =
let let
val e = #enemies player val e = #enemies player
val e = val e =
Vector.map Vector.map
(fn {angle} => {angle = if angle < 360 then angle + 5 else 0}) e (fn {angle} => {angle = if angle < 360 then angle + 5 else 0}) e
val patches = [W_ENEMIES e] val patches = W_ENEMIES e :: patches
in in
PlayerPatch.withPatches (player, patches) PlayerPatch.withPatches (player, patches)
end end