diff --git a/fcore/enemy-behaviour.sml b/fcore/enemy-behaviour.sml index db89b8a..6fd3a28 100644 --- a/fcore/enemy-behaviour.sml +++ b/fcore/enemy-behaviour.sml @@ -194,6 +194,19 @@ struct andalso (ey > platY andalso ey + Constants.jumpLimit >= platY) end + fun canDrop (nextPlatform, platformTree, enemy) = + let + val {x = platX, y = platY, width = platW, ...} = nextPlatform + val platFinishX = platX + platW + + val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy + + val standingOnPlat = standingOnArea (enemy, platformTree) + in + isBetween (platX, eX, platFinishX) andalso standingOnPlat + andalso ey < platY + end + (* get patches to help enemy move to nextPlatformID *) fun getPathToNextPlatform (nextPlatformID, platforms, platformTree, enemy, eID, pID, acc) = @@ -203,13 +216,15 @@ struct val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy val canJump = canJump (nextPlatform, platformTree, enemy) - + val canDrop = canDrop (nextPlatform, platformTree, enemy) in if canJump then case eyAxis of ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc | FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc | _ => acc + else if canDrop then + EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc else acc end diff --git a/fcore/physics.sml b/fcore/physics.sml index 2a78f5b..3a854d6 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -153,7 +153,7 @@ struct (x, y, size, size, 0, 0, ww, wh, 0, platformTree) val acc = getPlatformPatches (yAxis, platforms, platCollisions, []) - val acc = + val acc = case yAxis of DROP_BELOW_PLATFORM => (* if we dropped below platform before @@ -162,11 +162,11 @@ struct * 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 + if + QuadTree.hasCollisionAt + (x, y, size, size, 0, 0, ww, wh, ~1, platformTree) + then acc + else Fn.W_Y_AXIS FALLING :: acc | _ => acc val wallCollisions = QuadTree.getCollisionSides