progress shooting off enemies as projectiles

This commit is contained in:
2025-01-07 13:31:17 +00:00
parent c080398dd5
commit 29de4ea4b6
3 changed files with 31 additions and 18 deletions

View File

@@ -55,6 +55,7 @@ sig
| W_JUMP_PRESSED of bool
| W_ENEMIES of defeated_enemies vector
| W_CHARGE of int
| W_PROJECTILES of player_projectile vector
type enemy = {id: int, health: int, x: int, y: int}
@@ -129,6 +130,7 @@ struct
| W_JUMP_PRESSED of bool
| W_ENEMIES of defeated_enemies vector
| W_CHARGE of int
| W_PROJECTILES of player_projectile vector
type enemy = {id: int, health: int, x: int, y: int}

View File

@@ -150,15 +150,8 @@ struct
fun update (game, input) =
let
val
{ player
, walls
, wallTree
, platforms
, platformTree
, enemies
, enemyTree
} = game
val {player, walls, wallTree, platforms, platformTree, enemies, enemyTree} =
game
val player = Player.runPhysicsAndInput (game, input)

View File

@@ -495,11 +495,28 @@ struct
end
end
fun getMainAttackPatches (attackHeld, chargeHeld, charge) =
fun prevWasNotAttacking prevAttack = prevAttack <> MAIN_ATTACKING
(* called only when player has no projectiles or was not previously attacking *)
fun helpGetMainAttackPatches (attackHeld, chargeHeld, charge) =
if attackHeld andalso charge > 0 then MAIN_ATTACKING
else if chargeHeld andalso not attackHeld then MAIN_CHARGING
else MAIN_NOT_ATTACKING
fun getMainAttackPatches
(prevAttack, defeteadEnemies, projectiles, attackHeld, chargeHeld, charge) =
if attackHeld then
if
prevWasNotAttacking prevAttack andalso Vector.length defeteadEnemies > 0
then
(* shoot projectiles if player was not attacking previously,
* and there is more than one enemy *)
raise Match
else
helpGetMainAttackPatches (attackHeld, chargeHeld, charge)
else
helpGetMainAttackPatches (attackHeld, chargeHeld, charge)
fun getInputPatches (player: player, input) =
let
val
@@ -511,6 +528,8 @@ struct
, mainAttack
, mainAttackPressed
, charge
, enemies
, projectiles
, ...
} = player
@@ -519,7 +538,9 @@ struct
val xAxis = getXAxis (leftHeld, rightHeld)
val facing = getFacing (facing, xAxis)
val mainAttack = getMainAttackPatches (attackHeld, chargeHeld, charge)
val mainAttack = getMainAttackPatches
(mainAttack, enemies, projectiles, attackHeld, chargeHeld, charge)
val charge =
case mainAttack of
@@ -613,12 +634,9 @@ struct
val player =
let
val e = #enemies player
val e = Vector.map (fn {angle} =>
{
angle =
if angle < 360 then angle + 5 else 0
})
e
val e =
Vector.map
(fn {angle} => {angle = if angle < 360 then angle + 5 else 0}) e
val patches = [W_ENEMIES e]
in
withPatches (player, patches)
@@ -831,7 +849,7 @@ struct
if height > scale then (height - scale) / 2.0
else if height < scale then (scale - height) / 2.0
else 0.0
in
in
helpGetPelletVec
(x, y, 0, enemies, width, height, wratio, 0.0, yOffset, [])
end