differentiate 'upHeld' from 'jumpHeld' (we may want a different button for going up/down menu and a different button for jumping)

This commit is contained in:
2025-02-16 13:51:52 +00:00
parent 0df453f9c9
commit 291ee2f7f2
2 changed files with 7 additions and 5 deletions

View File

@@ -50,11 +50,11 @@ struct
if jumpPressed then (* apply gravity *) FALLING else JUMPING 0 if jumpPressed then (* apply gravity *) FALLING else JUMPING 0
| _ => prevAxis | _ => prevAxis
fun getJumpPatches (player, upHeld, downHeld, acc) = fun getJumpPatches (player, jumpHeld, downHeld, acc) =
let let
val {yAxis, jumpPressed, ...} = player val {yAxis, jumpPressed, ...} = player
in in
case (upHeld, downHeld) of case (jumpHeld, downHeld) of
(false, false) => (false, false) =>
let let
val yAxis = defaultYAxis yAxis val yAxis = defaultYAxis yAxis
@@ -205,7 +205,7 @@ struct
, ... , ...
} = player } = player
val {leftHeld, rightHeld, upHeld, downHeld, attackHeld} = input val {leftHeld, rightHeld, upHeld, downHeld, attackHeld, jumpHeld} = input
val xAxis = getXAxis (leftHeld, rightHeld) val xAxis = getXAxis (leftHeld, rightHeld)
val facing = getFacing (facing, xAxis) val facing = getFacing (facing, xAxis)
@@ -225,7 +225,7 @@ struct
, mainAttackPressed , mainAttackPressed
) )
val acc = getJumpPatches (player, upHeld, downHeld, acc) val acc = getJumpPatches (player, jumpHeld, downHeld, acc)
in in
acc acc
end end

View File

@@ -15,6 +15,7 @@ struct
, rightHeld = ref false , rightHeld = ref false
, upHeld = ref false , upHeld = ref false
, downHeld = ref false , downHeld = ref false
, jumpHeld = ref false
, attackHeld = ref false , attackHeld = ref false
, width = ref (1920.0 : Real32.real) , width = ref (1920.0 : Real32.real)
, height = ref (1080.0 : Real32.real) , height = ref (1080.0 : Real32.real)
@@ -26,6 +27,7 @@ struct
, upHeld = !(#upHeld state) , upHeld = !(#upHeld state)
, downHeld = !(#downHeld state) , downHeld = !(#downHeld state)
, attackHeld = !(#attackHeld state) , attackHeld = !(#attackHeld state)
, jumpHeld = !(#jumpHeld state)
} }
fun actionToBool action = action = Input.PRESS fun actionToBool action = action = Input.PRESS
@@ -42,7 +44,7 @@ struct
else if code = right then #rightHeld state := action else if code = right then #rightHeld state := action
else if code = down then #downHeld state := action else if code = down then #downHeld state := action
else if code = attack then #attackHeld state := action else if code = attack then #attackHeld state := action
else if code = jump then #upHeld state := action else if code = jump then #jumpHeld state := action
else () else ()
end end
| NONE => () | NONE => ()