From edf7d4c8dc9c294b0caf76dbd998a58648c26e34 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 18 Jan 2025 22:13:16 +0000 Subject: [PATCH] fix bug in physics.sml where player/enemy would drop below continuously past multiple platforms even if they intended to drop below platforms only once (fixed by setting yAxis to 'FALLING' if there are no collisions at all and player is in DROP_BELOW_PLATFORMS state) --- fcore/enemy-behaviour.sml | 18 +++++++++++++++++- fcore/physics.sml | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index 1d7649e..f4d01d9 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -1,4 +1,4 @@ -structure EnemyBehaviour = +1tructure EnemyBehaviour = struct open GameType @@ -143,6 +143,22 @@ struct fun hasVisted (find, visited) = helpHasVisited (0, Char.chr find, visited) + fun isBetween (p1, check, p2) = check >= p1 andalso check <= p2 + + fun isReachableFromBottom (prevPlat: platform, currentPlat: platform) = + let + val {x = prevX, y = prevY, width = prevWidth, ...} = prevPlat + val {x = curX, y = curY, width = curWidth, ...} = currentPlat + + val prevFinishX = prevX + prevWidth + val curFinishX = curX + curWidth + in + (isBetween (prevX, curX, prevFinishX) + orelse + isBetween (prevX, curFinishX, prevFinishX) + andalso prevY + Constants.jumpLimit >= curY) + end + fun isReachableFromLeft (prevPlat, currentPlat) = (* prev = right/from, current = left/to *) let diff --git a/fcore/physics.sml b/fcore/physics.sml index a17b532..2a78f5b 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -153,6 +153,22 @@ struct (x, y, size, size, 0, 0, ww, wh, 0, platformTree) val acc = getPlatformPatches (yAxis, platforms, platCollisions, []) + val acc = + case yAxis of + DROP_BELOW_PLATFORM => + (* if we dropped below platform before + * but we have fully passed the platform now + * such that there are no platform collisions + * 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 + | _ => acc + val wallCollisions = QuadTree.getCollisionSides (x, y, size, size, 0, 0, ww, wh, 0, wallTree) in