From b8934e3add16039089b0120d7a79267bfa53a293 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 15 Feb 2025 01:52:19 +0000 Subject: [PATCH] add function to generate quad tree from falling enemies --- fcore/enemy/falling-enemies.sml | 26 ++++++++++++++++++++++++++ fcore/player/player-attack.sml | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fcore/enemy/falling-enemies.sml b/fcore/enemy/falling-enemies.sml index 5b424af..417ad1f 100644 --- a/fcore/enemy/falling-enemies.sml +++ b/fcore/enemy/falling-enemies.sml @@ -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 diff --git a/fcore/player/player-attack.sml b/fcore/player/player-attack.sml index d9091e5..9517e00 100644 --- a/fcore/player/player-attack.sml +++ b/fcore/player/player-attack.sml @@ -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