distinguish between standing on wall vs standing on platform (platform can be jumped on but wall cannot)
This commit is contained in:
@@ -19,7 +19,12 @@ struct
|
|||||||
(x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, platformTree)
|
(x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, platformTree)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun isOnGround (enemy, wallTree, platformTree) =
|
(* same function takes either wallTree or platformTree and returns true
|
||||||
|
* if standing on tree.
|
||||||
|
* Function is monomorphic in the sense that wallTree and platformTree
|
||||||
|
* are both same type (no generics/parametric polymorphism).
|
||||||
|
* *)
|
||||||
|
fun standingOnArea (enemy, tree) =
|
||||||
let
|
let
|
||||||
val {x = ex, y = ey, ...} = enemy
|
val {x = ex, y = ey, ...} = enemy
|
||||||
|
|
||||||
@@ -31,11 +36,7 @@ struct
|
|||||||
val ww = Constants.worldWidth
|
val ww = Constants.worldWidth
|
||||||
val wh = Constants.worldHeight
|
val wh = Constants.worldHeight
|
||||||
in
|
in
|
||||||
QuadTree.hasCollisionAt
|
QuadTree.hasCollisionAt (ex, ey, width, height, 0, 0, ww, wh, ~1, tree)
|
||||||
(ex, ey, width, height, 0, 0, ww, wh, ~1, wallTree)
|
|
||||||
orelse
|
|
||||||
QuadTree.hasCollisionAt
|
|
||||||
(ex, ey, width, height, 0, 0, ww, wh, ~1, platformTree)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getPatrollPatches (enemy: enemy, wallTree, platformTree, acc) =
|
fun getPatrollPatches (enemy: enemy, wallTree, platformTree, acc) =
|
||||||
@@ -138,9 +139,10 @@ struct
|
|||||||
|
|
||||||
val xAxis = if px < ex then MOVE_LEFT else MOVE_RIGHT
|
val xAxis = if px < ex then MOVE_LEFT else MOVE_RIGHT
|
||||||
|
|
||||||
val isOnGround = isOnGround (enemy, wallTree, platformTree)
|
val isOnWall = standingOnArea (enemy, wallTree)
|
||||||
|
val isOnPlatform = standingOnArea (enemy, platformTree)
|
||||||
val yAxis =
|
val yAxis =
|
||||||
if ey > py andalso isOnGround then
|
if ey > py andalso (isOnWall orelse isOnPlatform) then
|
||||||
case eyAxis of
|
case eyAxis of
|
||||||
ON_GROUND => JUMPING 0
|
ON_GROUND => JUMPING 0
|
||||||
| FALLING => JUMPING 0
|
| FALLING => JUMPING 0
|
||||||
|
|||||||
Reference in New Issue
Block a user