From efbf0c7da957a551fe2435b096c295645f7915de Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 23 Jan 2025 00:01:15 +0000 Subject: [PATCH] progress towards letting enemy drop below platform if path to player is there --- fcore/enemy-behaviour.sml | 17 ++++++++++++++++- fcore/physics.sml | 12 ++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index db89b8a..6fd3a28 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -194,6 +194,19 @@ struct andalso (ey > platY andalso ey + Constants.jumpLimit >= platY) end + fun canDrop (nextPlatform, platformTree, enemy) = + let + val {x = platX, y = platY, width = platW, ...} = nextPlatform + val platFinishX = platX + platW + + val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy + + val standingOnPlat = standingOnArea (enemy, platformTree) + in + isBetween (platX, eX, platFinishX) andalso standingOnPlat + andalso ey < platY + end + (* get patches to help enemy move to nextPlatformID *) fun getPathToNextPlatform (nextPlatformID, platforms, platformTree, enemy, eID, pID, acc) = @@ -203,13 +216,15 @@ struct val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy val canJump = canJump (nextPlatform, platformTree, enemy) - + val canDrop = canDrop (nextPlatform, platformTree, enemy) in if canJump then case eyAxis of ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc | FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc | _ => acc + else if canDrop then + EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc else acc end diff --git a/fcore/physics.sml b/fcore/physics.sml index 2a78f5b..3a854d6 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -153,7 +153,7 @@ struct (x, y, size, size, 0, 0, ww, wh, 0, platformTree) val acc = getPlatformPatches (yAxis, platforms, platCollisions, []) - val acc = + val acc = case yAxis of DROP_BELOW_PLATFORM => (* if we dropped below platform before @@ -162,11 +162,11 @@ struct * then set new yAxis to FALLING * so we do not drop below any platforms again * *) - if QuadTree.hasCollisionAt (x, y, size, size, 0, 0, ww, wh, ~1, - platformTree) - then - Fn.W_Y_AXIS FALLING :: acc - else acc + if + QuadTree.hasCollisionAt + (x, y, size, size, 0, 0, ww, wh, ~1, platformTree) + then acc + else Fn.W_Y_AXIS FALLING :: acc | _ => acc val wallCollisions = QuadTree.getCollisionSides