reimplement attack patches (todo: add an int to the MAIN_ATTACKING variant to make the attack grow past some limit, and a bool to indicate whether the attack should grow in length or shrink)
This commit is contained in:
@@ -18,6 +18,7 @@ struct
|
|||||||
val recoilLimit = 15
|
val recoilLimit = 15
|
||||||
val attackedLimit = 55
|
val attackedLimit = 55
|
||||||
val maxCharge = 60
|
val maxCharge = 60
|
||||||
|
val attackLengthLimit = 99
|
||||||
|
|
||||||
(* constants for projectiles *)
|
(* constants for projectiles *)
|
||||||
val projectilePi: Real32.real = Real32.Math.pi / 180.0
|
val projectilePi: Real32.real = Real32.Math.pi / 180.0
|
||||||
|
|||||||
@@ -359,6 +359,15 @@ struct
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
structure AttackEnemies =
|
||||||
|
MakeQuadTreeFold
|
||||||
|
(struct
|
||||||
|
type env = unit
|
||||||
|
type state = defeated_enemies list
|
||||||
|
|
||||||
|
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
||||||
|
end)
|
||||||
|
|
||||||
fun runPhysicsAndInput (game: game_type, input, enemyTree) =
|
fun runPhysicsAndInput (game: game_type, input, enemyTree) =
|
||||||
let
|
let
|
||||||
val player = #player game
|
val player = #player game
|
||||||
@@ -406,24 +415,49 @@ struct
|
|||||||
(player, walls, wallTree, platforms, platformTree)
|
(player, walls, wallTree, platforms, platformTree)
|
||||||
val player = PlayerPatch.withPatches (player, patches)
|
val player = PlayerPatch.withPatches (player, patches)
|
||||||
|
|
||||||
in
|
val patches =
|
||||||
(* player reaction to collisions with enemies.
|
(* player reaction to collisions with enemies.
|
||||||
* We only detect collisions if player is not in invincibility period
|
* We only detect collisions if player is not in invincibility period
|
||||||
* after being previously attacked. *)
|
* after being previously attacked. *)
|
||||||
case #attacked player of
|
case #attacked player of
|
||||||
ATTACKED _ => player
|
ATTACKED _ => []
|
||||||
| _ =>
|
| _ =>
|
||||||
let
|
let
|
||||||
val {x, y, ...} = player
|
val {x, y, ...} = player
|
||||||
val size = Constants.playerSize
|
val size = Constants.playerSize
|
||||||
val env = (#enemies game, player)
|
val env = (#enemies game, player)
|
||||||
val state = []
|
val state = []
|
||||||
val patches = FoldEnemies.foldRegion
|
in
|
||||||
(x, y, size, size, env, state, enemyTree)
|
FoldEnemies.foldRegion (x, y, size, size, env, state, enemyTree)
|
||||||
|
end
|
||||||
|
|
||||||
|
val patches =
|
||||||
|
(* if player is attacking, check if enemies collide with attack
|
||||||
|
* todo: MAIN_ATTACKING variant should hold an integer,
|
||||||
|
* and be compared with attackLengthLimit
|
||||||
|
* and the attack should shrink at some point as well *)
|
||||||
|
case #mainAttack player of
|
||||||
|
MAIN_ATTACKING =>
|
||||||
|
let
|
||||||
|
val size = Constants.playerSize
|
||||||
|
val {x, y, facing, enemies, ...} = player
|
||||||
|
val x =
|
||||||
|
(case facing of
|
||||||
|
FACING_RIGHT => x + size
|
||||||
|
| FACING_LEFT => x - size)
|
||||||
|
|
||||||
|
val state = []
|
||||||
|
val newDefeated = AttackEnemies.foldRegion
|
||||||
|
(x, y, size, size, (), state, enemyTree)
|
||||||
|
val allDefeated =
|
||||||
|
Vector.concat [Vector.fromList newDefeated, enemies]
|
||||||
|
in
|
||||||
|
W_ENEMIES allDefeated :: patches
|
||||||
|
end
|
||||||
|
| _ => patches
|
||||||
in
|
in
|
||||||
PlayerPatch.withPatches (player, patches)
|
PlayerPatch.withPatches (player, patches)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
(* todo: add attacked enemies to player's 'enemies' field *)
|
(* todo: add attacked enemies to player's 'enemies' field *)
|
||||||
fun concatAttackedEnemies (player: player, enemyCollisions) =
|
fun concatAttackedEnemies (player: player, enemyCollisions) =
|
||||||
|
|||||||
Reference in New Issue
Block a user