remove some references to charging when/ife we don't need it, and also only trigger throw/attack on new button press (if held, throw/attack is not repeated)

This commit is contained in:
2025-02-07 12:32:38 +00:00
parent 283962c176
commit 7734496a8c
3 changed files with 37 additions and 48 deletions

View File

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

View File

@@ -11,6 +11,7 @@ sig
| W_X of int | W_X of int
| W_Y of int | W_Y of int
| W_JUMP_PRESSED of bool | W_JUMP_PRESSED of bool
| W_MAIN_ATTACK_PRESSED of bool
| W_ENEMIES of GameType.defeated_enemies vector | W_ENEMIES of GameType.defeated_enemies vector
| W_CHARGE of int | W_CHARGE of int
| W_PROJECTILES of GameType.player_projectile vector | W_PROJECTILES of GameType.player_projectile vector
@@ -33,6 +34,7 @@ struct
| W_X of int | W_X of int
| W_Y of int | W_Y of int
| W_JUMP_PRESSED of bool | W_JUMP_PRESSED of bool
| W_MAIN_ATTACK_PRESSED of bool
| W_ENEMIES of GameType.defeated_enemies vector | W_ENEMIES of GameType.defeated_enemies vector
| W_CHARGE of int | W_CHARGE of int
| W_PROJECTILES of GameType.player_projectile vector | W_PROJECTILES of GameType.player_projectile vector
@@ -273,6 +275,24 @@ struct
, projectiles , projectiles
, platID , platID
) )
| W_MAIN_ATTACK_PRESSED mainAttackPressed =>
mkPlayer
( health
, xAxis
, yAxis
, x
, y
, jumpPressed
, recoil
, attacked
, mainAttack
, facing
, mainAttackPressed
, enemies
, charge
, projectiles
, platID
)
| W_ENEMIES enemies => | W_ENEMIES enemies =>
mkPlayer mkPlayer
( health ( health

View File

@@ -82,17 +82,16 @@ 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, chargeHeld, charge) = fun helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) =
let let
val attack = val attack =
if attackHeld andalso charge > 0 then if attackHeld andalso not mainAttackPressed then
MAIN_ATTACKING {length = 3, growing = true} MAIN_ATTACKING {length = 3, growing = true}
else if chargeHeld andalso not attackHeld then
MAIN_CHARGING
else else
MAIN_NOT_ATTACKING MAIN_NOT_ATTACKING
in in
W_MAIN_ATTACK attack W_MAIN_ATTACK_PRESSED (attackHeld andalso mainAttackPressed)
:: W_MAIN_ATTACK attack :: acc
end end
fun degreesToRadians degrees = Real32.fromInt degrees * Constants.projectilePi fun degreesToRadians degrees = Real32.fromInt degrees * Constants.projectilePi
@@ -146,30 +145,19 @@ struct
, charge , charge
, player , player
, acc , acc
, mainAttackPressed
) = ) =
case prevAttack of case prevAttack of
MAIN_NOT_ATTACKING => MAIN_NOT_ATTACKING =>
if attackHeld andalso Vector.length defeteadEnemies > 0 then if
attackHeld andalso not mainAttackPressed
andalso Vector.length defeteadEnemies > 0
then
(* shoot projectiles if player was not attacking previously, (* shoot projectiles if player was not attacking previously,
* 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
let helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc)
val mainAttack =
helpGetMainAttackPatches (attackHeld, chargeHeld, charge)
in
mainAttack :: acc
end
| MAIN_CHARGING =>
if attackHeld andalso Vector.length defeteadEnemies > 0 then
getThrowPatches (defeteadEnemies, projectiles, player, acc)
else
let
val mainAttack =
helpGetMainAttackPatches (attackHeld, chargeHeld, charge)
in
mainAttack :: acc
end
| MAIN_ATTACKING {length, growing} => | MAIN_ATTACKING {length, growing} =>
let let
val mainAttack = val mainAttack =
@@ -193,18 +181,13 @@ struct
else MAIN_ATTACKING {length = newLength, growing = false} else MAIN_ATTACKING {length = newLength, growing = false}
end end
in in
W_MAIN_ATTACK mainAttack :: acc W_MAIN_ATTACK_PRESSED true :: W_MAIN_ATTACK mainAttack :: acc
end end
| MAIN_THROWING => | MAIN_THROWING =>
if attackHeld then if attackHeld then
acc acc
else else
let helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc)
val mainAttack =
helpGetMainAttackPatches (attackHeld, chargeHeld, charge)
in
mainAttack :: acc
end
fun getInputPatches (player: player, input) = fun getInputPatches (player: player, input) =
let let
@@ -228,11 +211,7 @@ struct
val xAxis = getXAxis (leftHeld, rightHeld) val xAxis = getXAxis (leftHeld, rightHeld)
val facing = getFacing (facing, xAxis) val facing = getFacing (facing, xAxis)
val charge = val charge = (* todo: rework charge *) charge
case mainAttack of
MAIN_CHARGING => Int.min (charge + 1, Constants.maxCharge)
| MAIN_ATTACKING _ => (* todo: rework charge *) Int.max (charge - 1, 0)
| _ => charge
val acc = [W_X_AXIS xAxis, W_FACING facing, W_CHARGE charge] val acc = [W_X_AXIS xAxis, W_FACING facing, W_CHARGE charge]
@@ -245,6 +224,7 @@ struct
, charge , charge
, player , player
, acc , acc
, mainAttackPressed
) )
val acc = getJumpPatches (player, upHeld, downHeld, acc) val acc = getJumpPatches (player, upHeld, downHeld, acc)
@@ -467,7 +447,7 @@ struct
val {x, y, facing, enemies, ...} = player val {x, y, facing, enemies, ...} = player
val x = val x =
(case facing of (case facing of
FACING_RIGHT => x + length FACING_RIGHT => x + Constants.playerSize
| FACING_LEFT => x - length) | FACING_LEFT => x - length)
val state = [] val state = []
@@ -525,15 +505,6 @@ struct
Block.lerp (x, y, size, size, width, height, 1.0, 0.9, 0.9) Block.lerp (x, y, size, size, width, height, 1.0, 0.9, 0.9)
else else
Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5)) Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5))
| MAIN_CHARGING =>
(case attacked of
NOT_ATTACKED =>
Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5)
| ATTACKED amt =>
if amt mod 5 = 0 then
Block.lerp (x, y, size, size, width, height, 1.0, 0.9, 0.9)
else
Block.lerp (x, y, size, size, width, height, 1.0, 0.5, 0.5))
fun getDrawVec (player: player, width, height) = fun getDrawVec (player: player, width, height) =
let let
@@ -583,7 +554,7 @@ struct
val x = val x =
case #facing player of case #facing player of
FACING_RIGHT => x + Constants.playerSize FACING_RIGHT => x + Constants.playerSize
| FACING_LEFT => x - Constants.playerSize - length | FACING_LEFT => x - length
in in
if wratio < hratio then if wratio < hratio then
let let
@@ -626,7 +597,7 @@ struct
val x = Real32.fromInt x * hratio + xOffset val x = Real32.fromInt x * hratio + xOffset
val y = Real32.fromInt y * hratio val y = Real32.fromInt y * hratio
val realLength = Real32.fromInt length * wratio + xOffset val realLength = Real32.fromInt length * hratio
val realSize = Constants.playerSizeReal * hratio val realSize = Constants.playerSizeReal * hratio
val {charge, ...} = player val {charge, ...} = player