From 2c6b1556d1136e662e7414273381a014554fb665 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 18 Jan 2025 22:18:05 +0000 Subject: [PATCH] implemented four functions: is it possible to reach platform from above, is it possible to reach from below, or from left or right --- fcore/enemy-behaviour.sml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index f4d01d9..60d6ec2 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -1,4 +1,4 @@ -1tructure EnemyBehaviour = +structure EnemyBehaviour = struct open GameType @@ -145,7 +145,7 @@ struct fun isBetween (p1, check, p2) = check >= p1 andalso check <= p2 - fun isReachableFromBottom (prevPlat: platform, currentPlat: platform) = + fun isReachableFromBelow (prevPlat: platform, currentPlat: platform) = let val {x = prevX, y = prevY, width = prevWidth, ...} = prevPlat val {x = curX, y = curY, width = curWidth, ...} = currentPlat @@ -159,6 +159,18 @@ struct andalso prevY + Constants.jumpLimit >= curY) end + fun isReachableFromAbove (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 <= curY) + end + fun isReachableFromLeft (prevPlat, currentPlat) = (* prev = right/from, current = left/to *) let