diff --git a/fcore/enemy/falling-enemies.sml b/fcore/enemy/falling-enemies.sml index 337d95a..ac466e1 100644 --- a/fcore/enemy/falling-enemies.sml +++ b/fcore/enemy/falling-enemies.sml @@ -23,7 +23,28 @@ struct , QuadTree.create (Constants.worldWidth, Constants.worldHeight) ) - fun updateList (pos, vec, acc) = + fun isCollidingWithPlayerAttack (player: player, fx, fy) = + let + val {x = px, y = py, mainAttack, facing, ...} = player + in + case mainAttack of + MAIN_ATTACKING {length, ...} => + let + val px = + (case facing of + FACING_RIGHT => px + Constants.playerSize + | FACING_LEFT => px - length) + + val pSize = Constants.playerSize + val fSize = Constants.enemySize + in + Collision.isCollidingPlus + (px, py, length, pSize, fx, fy, fSize, fSize) + end + | _ => false + end + + fun updateList (pos, vec, player: player, acc) = if pos < 0 then acc else @@ -34,7 +55,10 @@ struct val ww = Constants.worldWidth val wh = Constants.worldHeight in - if Collision.isColliding (x, y, size, size, 0, 0, ww, wh) then + if isCollidingWithPlayerAttack (player : player, x, y) then + (* filter out if player is attacking falling enemy *) + updateList (pos - 1, vec, player, acc) + else if Collision.isCollidingPlus (x, y, size, size, 0, 0, ww, wh) then (* move falling enemy up or down depending on jumped *) let val updated = @@ -51,12 +75,12 @@ struct , variant = variant } in - updateList (pos - 1, vec, updated :: acc) + updateList (pos - 1, vec, player, updated :: acc) end else (* if current is not colliding with world's bounds, then filter out * as it is off screen *) - updateList (pos - 1, vec, acc) + updateList (pos - 1, vec, player, acc) end fun helpGetDrawVec diff --git a/fcore/game-update.sml b/fcore/game-update.sml index e385f96..b001448 100644 --- a/fcore/game-update.sml +++ b/fcore/game-update.sml @@ -21,7 +21,7 @@ struct (* update state of falling enemies and possibly filter *) val fallingEnemies = FallingEnemies.updateList - (Vector.length fallingEnemies - 1, fallingEnemies, []) + (Vector.length fallingEnemies - 1, fallingEnemies, player, []) val (enemies, fallingEnemies) = Enemy.updateEnemyList ( Vector.length enemies - 1