From 07d31119a7c5e0258ce15817ddb74c369cbe10a5 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 8 Feb 2025 11:05:58 +0000 Subject: [PATCH] code functionality to filter out falling enemy from list if falling enemy is colliding with player --- fcore/enemy/falling-enemies.sml | 32 ++++++++++++++++++++++++++++---- fcore/game-update.sml | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) 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