update positions of falling enemies per frame (and filter them out too)

This commit is contained in:
2025-02-15 02:17:01 +00:00
parent 219b37053b
commit 0b9bdeceff
2 changed files with 35 additions and 7 deletions

View File

@@ -28,6 +28,40 @@ struct
, QuadTree.create (Constants.worldWidth, Constants.worldHeight) , QuadTree.create (Constants.worldWidth, Constants.worldHeight)
) )
(* - Updating position of fallingEnemies
* - and filtering out enemies which are no longer in world bounds - *)
structure UpdateFalling =
MakeGapMapFolder
(struct
structure Pair = FallingEnemyPair
type env = unit
type state = FallingEnemyMap.t
fun fold (fallingID, fallingEnemy, (), fallingMap) =
let
val {x, y, variant} = fallingEnemy
val size = Constants.enemySize
val ww = Constants.worldWidth
val wh = Constants.worldHeight
in
if Collision.isCollidingPlus (x, y, size, size, 0, 0, ww, wh) then
let
val newFalling =
{x = x, y = y - Constants.moveEnemyBy, variant = variant}
in
FallingEnemyMap.add (fallingID, newFalling, fallingMap)
end
else
(* filter out since not in world bounds *)
fallingMap
end
end)
fun update fallingEnemies =
UpdateFalling.foldUnordered (fallingEnemies, (), FallingEnemyMap.empty)
(* - Drawing falling enemies - *) (* - Drawing falling enemies - *)
structure FallingDrawVec = structure FallingDrawVec =
MakeGapMapFolder MakeGapMapFolder

View File

@@ -29,13 +29,7 @@ struct
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 *) val fallingEnemies = FallingEnemies.update fallingEnemies
(* todo: use enemy map
val fallingEnemies = FallingEnemies.updateList
(Vector.length fallingEnemies - 1, fallingEnemies, player, [])
val fallingEnemies = Vector.fromList fallingEnemies
*)
in in
{ player = player { player = player
, walls = walls , walls = walls