diff --git a/fcore/enemy/falling-enemies.sml b/fcore/enemy/falling-enemies.sml index 417ad1f..4f1d777 100644 --- a/fcore/enemy/falling-enemies.sml +++ b/fcore/enemy/falling-enemies.sml @@ -28,6 +28,40 @@ struct , 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 - *) structure FallingDrawVec = MakeGapMapFolder diff --git a/fcore/game-update.sml b/fcore/game-update.sml index 3863b9d..714e94f 100644 --- a/fcore/game-update.sml +++ b/fcore/game-update.sml @@ -29,13 +29,7 @@ struct val enemies = Enemy.update (enemies, walls, wallTree, platforms, platformTree, player, graph) - (* update state of falling enemies and possibly filter *) - (* todo: use enemy map - val fallingEnemies = FallingEnemies.updateList - (Vector.length fallingEnemies - 1, fallingEnemies, player, []) - - val fallingEnemies = Vector.fromList fallingEnemies - *) + val fallingEnemies = FallingEnemies.update fallingEnemies in { player = player , walls = walls