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