From 20e34ca0d5cd15586c75756fbcd1b4a37d65308b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 17 Jan 2025 12:29:07 +0000 Subject: [PATCH] add function that returns true if we can jump on platform --- fcore/enemy-behaviour.sml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index cd7f21d..a038e8d 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -131,6 +131,29 @@ struct | STAY_STILL => acc end + fun canJumpOnPlatform (enemy: enemy, platformTree) = + let + val {x, y, ...} = enemy + + val distance = Constants.moveEnemyBy * Constants.jumpLimit + + val distance = distance div 2 + val yDistance = distance + + val y = y - yDistance + Constants.enemySize + + val ww = Constants.worldWidth + val wh = Constants.worldHeight + + val mx = x - distance + in + QuadTree.hasCollisionAt + (x, y, distance, yDistance, 0, 0, ww, wh, ~1, platformTree) + orelse + QuadTree.hasCollisionAt + (mx, y, distance, yDistance, 0, 0, ww, wh, ~1, platformTree) + end + (* pathfinding *) fun getFollowPatches (player: player, enemy, wallTree, platformTree, acc) = let @@ -141,8 +164,12 @@ struct val isOnWall = standingOnArea (enemy, wallTree) val isOnPlatform = standingOnArea (enemy, platformTree) + val hasPlatformAbove = canJumpOnPlatform (enemy, platformTree) + val () = print ("canJump: " ^ Bool.toString hasPlatformAbove ^ "\n") + val shouldJump = (isOnWall orelse isOnPlatform) andalso hasPlatformAbove + val yAxis = - if ey > py andalso (isOnWall orelse isOnPlatform) then + if ey > py andalso shouldJump then case eyAxis of ON_GROUND => JUMPING 0 | FALLING => JUMPING 0