fix bug in physics.sml where player/enemy would drop below continuously past multiple platforms even if they intended to drop below platforms only once (fixed by setting yAxis to 'FALLING' if there are no collisions at all and player is in DROP_BELOW_PLATFORMS state)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
structure EnemyBehaviour =
|
1tructure EnemyBehaviour =
|
||||||
struct
|
struct
|
||||||
open GameType
|
open GameType
|
||||||
|
|
||||||
@@ -143,6 +143,22 @@ struct
|
|||||||
fun hasVisted (find, visited) =
|
fun hasVisted (find, visited) =
|
||||||
helpHasVisited (0, Char.chr 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) =
|
fun isReachableFromLeft (prevPlat, currentPlat) =
|
||||||
(* prev = right/from, current = left/to *)
|
(* prev = right/from, current = left/to *)
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -153,6 +153,22 @@ struct
|
|||||||
(x, y, size, size, 0, 0, ww, wh, 0, platformTree)
|
(x, y, size, size, 0, 0, ww, wh, 0, platformTree)
|
||||||
val acc = getPlatformPatches (yAxis, platforms, platCollisions, [])
|
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
|
val wallCollisions = QuadTree.getCollisionSides
|
||||||
(x, y, size, size, 0, 0, ww, wh, 0, wallTree)
|
(x, y, size, size, 0, 0, ww, wh, 0, wallTree)
|
||||||
in
|
in
|
||||||
|
|||||||
Reference in New Issue
Block a user