add function to generate quad tree from falling enemies

This commit is contained in:
2025-02-15 01:52:19 +00:00
parent e758a5a13c
commit b8934e3add
2 changed files with 28 additions and 2 deletions

View File

@@ -3,6 +3,32 @@ struct
open EnemyType
open EntityType
(* - Generating tree of falling enemies - *)
structure FallingTree =
MakeGapMapFolder
(struct
structure Pair = FallingEnemyPair
type env = unit
type state = QuadTree.t
fun fold (fallingID, falling: EnemyType.falling_enemy, (), quadTree) =
let
val {x, y, ...} = falling
val size = Constants.enemySize
in
QuadTree.insert (x, y, size, size, fallingID, quadTree)
end
end)
fun generateTree falling =
FallingTree.foldUnordered
( falling
, ()
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
)
(* - Drawing falling enemies - *)
structure FallingDrawVec =
MakeGapMapFolder
(struct

View File

@@ -1,7 +1,7 @@
structure PlayerAttack =
struct
(* - Handle collisions where player hits enemy directly - *)
structure AttackEnemies =
structure PlayerAttackEnemy =
MakeQuadTreeFold
(struct
type env = unit
@@ -45,7 +45,7 @@ struct
FACING_RIGHT => x + Constants.playerSize
| FACING_LEFT => x - length)
val (defeatedList, enemyMap) = AttackEnemies.foldRegion
val (defeatedList, enemyMap) = PlayerAttackEnemy.foldRegion
(x, y, length, height, (), ([], enemyMap), enemyTree)
val defeatedList = Vector.fromList defeatedList