use binary search to find enemy with ID in 'GameUpdate.checkEnemies' function, because we previously relied on the enemy's index

This commit is contained in:
2024-12-27 18:26:57 +00:00
parent ada63d54ce
commit 8804847d7a
3 changed files with 31 additions and 2 deletions

View File

@@ -33,7 +33,7 @@ struct
val pHalfW = Player.size div 2
val pCentreX = x + pHalfW
val {x = ex, y = ey, ...} = Vector.sub (enemies, id - 1)
val {x = ex, y = ey, ...} = Enemy.find (id, enemies)
val eFinishX = ex + Enemy.size
val eHalfW = Enemy.size div 2
val eCentreX = ex + eHalfW
@@ -47,6 +47,15 @@ struct
end
| [] => acc
fun checkEnemiesWhileAttacking (player, enemies, lst, acc) =
let
open QuadTree
in
case lst of
enemyID :: tl => (* placeholder *) acc
| [] => acc
end
(* removes enemies from `enemies` vector when that enemy is in collisions *)
fun filterEnemyCollisions (pos, collisions, enemies: enemy vector, acc) =
if pos < 0 then