progress shooting off enemies as projectiles
This commit is contained in:
@@ -55,6 +55,7 @@ sig
|
|||||||
| W_JUMP_PRESSED of bool
|
| W_JUMP_PRESSED of bool
|
||||||
| W_ENEMIES of defeated_enemies vector
|
| W_ENEMIES of defeated_enemies vector
|
||||||
| W_CHARGE of int
|
| W_CHARGE of int
|
||||||
|
| W_PROJECTILES of player_projectile vector
|
||||||
|
|
||||||
type enemy = {id: int, health: int, x: int, y: int}
|
type enemy = {id: int, health: int, x: int, y: int}
|
||||||
|
|
||||||
@@ -129,6 +130,7 @@ struct
|
|||||||
| W_JUMP_PRESSED of bool
|
| W_JUMP_PRESSED of bool
|
||||||
| W_ENEMIES of defeated_enemies vector
|
| W_ENEMIES of defeated_enemies vector
|
||||||
| W_CHARGE of int
|
| W_CHARGE of int
|
||||||
|
| W_PROJECTILES of player_projectile vector
|
||||||
|
|
||||||
type enemy = {id: int, health: int, x: int, y: int}
|
type enemy = {id: int, health: int, x: int, y: int}
|
||||||
|
|
||||||
|
|||||||
@@ -150,15 +150,8 @@ struct
|
|||||||
|
|
||||||
fun update (game, input) =
|
fun update (game, input) =
|
||||||
let
|
let
|
||||||
val
|
val {player, walls, wallTree, platforms, platformTree, enemies, enemyTree} =
|
||||||
{ player
|
game
|
||||||
, walls
|
|
||||||
, wallTree
|
|
||||||
, platforms
|
|
||||||
, platformTree
|
|
||||||
, enemies
|
|
||||||
, enemyTree
|
|
||||||
} = game
|
|
||||||
|
|
||||||
val player = Player.runPhysicsAndInput (game, input)
|
val player = Player.runPhysicsAndInput (game, input)
|
||||||
|
|
||||||
|
|||||||
@@ -495,11 +495,28 @@ struct
|
|||||||
end
|
end
|
||||||
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
|
if attackHeld andalso charge > 0 then MAIN_ATTACKING
|
||||||
else if chargeHeld andalso not attackHeld then MAIN_CHARGING
|
else if chargeHeld andalso not attackHeld then MAIN_CHARGING
|
||||||
else MAIN_NOT_ATTACKING
|
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) =
|
fun getInputPatches (player: player, input) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
@@ -511,6 +528,8 @@ struct
|
|||||||
, mainAttack
|
, mainAttack
|
||||||
, mainAttackPressed
|
, mainAttackPressed
|
||||||
, charge
|
, charge
|
||||||
|
, enemies
|
||||||
|
, projectiles
|
||||||
, ...
|
, ...
|
||||||
} = player
|
} = player
|
||||||
|
|
||||||
@@ -519,7 +538,9 @@ struct
|
|||||||
|
|
||||||
val xAxis = getXAxis (leftHeld, rightHeld)
|
val xAxis = getXAxis (leftHeld, rightHeld)
|
||||||
val facing = getFacing (facing, xAxis)
|
val facing = getFacing (facing, xAxis)
|
||||||
val mainAttack = getMainAttackPatches (attackHeld, chargeHeld, charge)
|
|
||||||
|
val mainAttack = getMainAttackPatches
|
||||||
|
(mainAttack, enemies, projectiles, attackHeld, chargeHeld, charge)
|
||||||
|
|
||||||
val charge =
|
val charge =
|
||||||
case mainAttack of
|
case mainAttack of
|
||||||
@@ -613,12 +634,9 @@ struct
|
|||||||
val player =
|
val player =
|
||||||
let
|
let
|
||||||
val e = #enemies player
|
val e = #enemies player
|
||||||
val e = Vector.map (fn {angle} =>
|
val e =
|
||||||
{
|
Vector.map
|
||||||
angle =
|
(fn {angle} => {angle = if angle < 360 then angle + 5 else 0}) e
|
||||||
if angle < 360 then angle + 5 else 0
|
|
||||||
})
|
|
||||||
e
|
|
||||||
val patches = [W_ENEMIES e]
|
val patches = [W_ENEMIES e]
|
||||||
in
|
in
|
||||||
withPatches (player, patches)
|
withPatches (player, patches)
|
||||||
|
|||||||
Reference in New Issue
Block a user