implemented four functions: is it possible to reach platform from above, is it possible to reach from below, or from left or right
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
1tructure EnemyBehaviour =
|
structure EnemyBehaviour =
|
||||||
struct
|
struct
|
||||||
open GameType
|
open GameType
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ struct
|
|||||||
|
|
||||||
fun isBetween (p1, check, p2) = check >= p1 andalso check <= p2
|
fun isBetween (p1, check, p2) = check >= p1 andalso check <= p2
|
||||||
|
|
||||||
fun isReachableFromBottom (prevPlat: platform, currentPlat: platform) =
|
fun isReachableFromBelow (prevPlat: platform, currentPlat: platform) =
|
||||||
let
|
let
|
||||||
val {x = prevX, y = prevY, width = prevWidth, ...} = prevPlat
|
val {x = prevX, y = prevY, width = prevWidth, ...} = prevPlat
|
||||||
val {x = curX, y = curY, width = curWidth, ...} = currentPlat
|
val {x = curX, y = curY, width = curWidth, ...} = currentPlat
|
||||||
@@ -159,6 +159,18 @@ struct
|
|||||||
andalso prevY + Constants.jumpLimit >= curY)
|
andalso prevY + Constants.jumpLimit >= curY)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun isReachableFromAbove (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 <= curY)
|
||||||
|
end
|
||||||
|
|
||||||
fun isReachableFromLeft (prevPlat, currentPlat) =
|
fun isReachableFromLeft (prevPlat, currentPlat) =
|
||||||
(* prev = right/from, current = left/to *)
|
(* prev = right/from, current = left/to *)
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user