a little refactoring (Player.runPhysicsAndInput function now does just that, instead of also checking for collisions with enemy)
This commit is contained in:
@@ -13,19 +13,21 @@ struct
|
|||||||
, fallingEnemies
|
, fallingEnemies
|
||||||
} = game
|
} = game
|
||||||
|
|
||||||
|
val player = Player.runPhysicsAndInput (game, input)
|
||||||
|
|
||||||
val enemyTree = Enemy.generateTree enemies
|
val enemyTree = Enemy.generateTree enemies
|
||||||
val player = Player.runPhysicsAndInput (game, input, enemyTree)
|
val player = Player.checkEnemyCollisions (player, enemies, enemyTree)
|
||||||
|
|
||||||
val enemies = Enemy.update
|
val enemies = Enemy.update
|
||||||
(enemies, walls, wallTree, platforms, platformTree, player, graph)
|
(enemies, walls, wallTree, platforms, platformTree, player, graph)
|
||||||
|
|
||||||
(* update state of falling enemies and possibly filter *)
|
(* update state of falling enemies and possibly filter *)
|
||||||
(* todo: use enemy map
|
(* todo: use enemy map
|
||||||
val fallingEnemies = FallingEnemies.updateList
|
val fallingEnemies = FallingEnemies.updateList
|
||||||
(Vector.length fallingEnemies - 1, fallingEnemies, player, [])
|
(Vector.length fallingEnemies - 1, fallingEnemies, player, [])
|
||||||
|
|
||||||
val fallingEnemies = Vector.fromList fallingEnemies
|
val fallingEnemies = Vector.fromList fallingEnemies
|
||||||
*)
|
*)
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
, walls = walls
|
, walls = walls
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ struct
|
|||||||
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
||||||
end)
|
end)
|
||||||
|
|
||||||
fun runPhysicsAndInput (game: GameType.game_type, input, enemyTree) =
|
fun runPhysicsAndInput (game: GameType.game_type, input) =
|
||||||
let
|
let
|
||||||
val player = #player game
|
val player = #player game
|
||||||
|
|
||||||
@@ -423,24 +423,31 @@ struct
|
|||||||
val {walls, wallTree, platforms, platformTree, ...} = game
|
val {walls, wallTree, platforms, platformTree, ...} = game
|
||||||
val patches = PlayerPhysics.getEnvironmentPatches
|
val patches = PlayerPhysics.getEnvironmentPatches
|
||||||
(player, walls, wallTree, platforms, platformTree)
|
(player, walls, wallTree, platforms, platformTree)
|
||||||
val player = PlayerPatch.withPatches (player, patches)
|
in
|
||||||
|
PlayerPatch.withPatches (player, patches)
|
||||||
|
end
|
||||||
|
|
||||||
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. *)
|
fun checkEnemyCollisions (player: PlayerType.player, enemies, enemyTree) =
|
||||||
case #attacked player of
|
case #attacked player of
|
||||||
ATTACKED _ => []
|
ATTACKED _ => player
|
||||||
| _ =>
|
| _ =>
|
||||||
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, player)
|
||||||
val state = []
|
val state = []
|
||||||
in
|
val patches = FoldEnemies.foldRegion
|
||||||
FoldEnemies.foldRegion (x, y, size, size, env, state, enemyTree)
|
(x, y, size, size, env, state, enemyTree)
|
||||||
end
|
in
|
||||||
|
PlayerPatch.withPatches (player, patches)
|
||||||
|
end
|
||||||
|
|
||||||
|
(* todo: check which enemies are being attacked by player,
|
||||||
|
* updating player's 'defeatedEnemies' field (if enemy's health would reach 0)
|
||||||
|
* and updating enemy (if enemy's health wouldn't reach 0, decrement health)
|
||||||
val patches =
|
val patches =
|
||||||
(* if player is attacking, check if enemies collide with attack *)
|
(* if player is attacking, check if enemies collide with attack *)
|
||||||
case #mainAttack player of
|
case #mainAttack player of
|
||||||
@@ -473,6 +480,7 @@ struct
|
|||||||
in
|
in
|
||||||
PlayerPatch.withPatches (player, patches)
|
PlayerPatch.withPatches (player, patches)
|
||||||
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