From e644160e380fd0b8be78a21b7e7034ec6ebdd5e4 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 23 Jan 2025 01:06:16 +0000 Subject: [PATCH] enemy dropping below platform (without any bugs) is fully implemented now --- fcore/enemy-behaviour.sml | 3 +- fcore/physics.sml | 77 +++++++++++++++++++++++++++------------ fcore/platform.sml | 4 +- fcore/quad-tree.sml | 8 ++-- 4 files changed, 61 insertions(+), 31 deletions(-) diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index 6fd3a28..f9e40f7 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -187,11 +187,12 @@ struct val platFinishX = platX + platW val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy + val ey = ey + Constants.enemySize val standingOnPlat = standingOnArea (enemy, platformTree) in isBetween (platX, eX, platFinishX) andalso standingOnPlat - andalso (ey > platY andalso ey + Constants.jumpLimit >= platY) + andalso (ey > platY andalso ey >= platY) end fun canDrop (nextPlatform, platformTree, enemy) = diff --git a/fcore/physics.sml b/fcore/physics.sml index 3a854d6..90dbd57 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -73,31 +73,30 @@ struct end end - fun getPlatformPatches (yAxis, platforms: platform vector, lst, acc) = + fun standingOnArea (x, y, tree) = let - open QuadTree - in - case lst of - platID :: tl => - (case yAxis of - DROP_BELOW_PLATFORM => - (* pass through, allowing player to drop below the platform *) - getPlatformPatches (yAxis, platforms, tl, acc) - | JUMPING _ => - (* pass through, allowing player to jump above the platform *) - getPlatformPatches (yAxis, platforms, tl, acc) - | _ => - let - (* default case: - * player will land on platform and stay on the ground there. *) - val {y = platY, ...} = Vector.sub (platforms, platID - 1) + val y = y + Fn.entitySize - 1 - val newY = platY - Fn.entitySize - val acc = Fn.W_Y_AXIS ON_GROUND :: Fn.W_Y newY :: acc - in - getPlatformPatches (yAxis, platforms, tl, acc) - end) - | [] => acc + val width = Fn.entitySize + val height = Platform.platHeight + + val ww = Constants.worldWidth + val wh = Constants.worldHeight + in + QuadTree.hasCollisionAt (x, y, width, height, 0, 0, ww, wh, ~1, tree) + end + + fun standingOnAreaID (x, y, tree) = + let + val y = y + Fn.entitySize - 1 + + val width = Fn.entitySize + val height = Platform.platHeight + + val ww = Constants.worldWidth + val wh = Constants.worldHeight + in + QuadTree.getItemID (x, y, width, height, 0, 0, ww, wh, tree) end fun getWallPatches (walls: wall vector, lst, acc) = @@ -151,7 +150,37 @@ struct val platCollisions = QuadTree.getCollisionsBelow (x, y, size, size, 0, 0, ww, wh, 0, platformTree) - val acc = getPlatformPatches (yAxis, platforms, platCollisions, []) + + val platID = standingOnAreaID (x, y, platformTree) + + val acc = [] + + val acc = + if platID <> ~1 then + (case yAxis of + DROP_BELOW_PLATFORM => + (* pass through, allowing player to drop below the platform *) + acc + | JUMPING _ => + (* pass through, allowing player to jump above the platform *) + acc + | FLOATING _ => + (* pass through, allowing player to jump above the platform *) + acc + | _ => + let + (* default case: + * player will land on platform and stay on the ground there. *) + val {y = platY, ...}: GameType.platform = + Vector.sub (platforms, platID - 1) + + val newY = platY - Fn.entitySize + val acc = Fn.W_Y_AXIS ON_GROUND :: Fn.W_Y newY :: acc + in + acc + end) + else + acc val acc = case yAxis of diff --git a/fcore/platform.sml b/fcore/platform.sml index 7e1c1a7..10063fb 100644 --- a/fcore/platform.sml +++ b/fcore/platform.sml @@ -2,8 +2,8 @@ structure Platform = struct (* collision height of a platform. * Visual height may (and probably will) be different. *) - val platHeight = 3 - val rPlatHeight = 3.0 + val platHeight = 5 + val rPlatHeight = 5.0 fun helpGenerateTree (pos, platVec, acc) = if pos = Vector.length platVec then diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 6465d07..820d05b 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -1305,7 +1305,7 @@ struct , quadY , halfWidth , halfHeight - , tree + , topLeft ) end | TOP_RIGHT => @@ -1323,7 +1323,7 @@ struct , quadY , halfWidth , halfHeight - , tree + , topRight ) end | BOTTOM_LEFT => @@ -1341,7 +1341,7 @@ struct , middleY , halfWidth , halfHeight - , tree + , bottomLeft ) end | BOTTOM_RIGHT => @@ -1360,7 +1360,7 @@ struct , middleY , halfWidth , halfHeight - , tree + , bottomRight ) end | PARENT_QUADRANT => ~1)