done with patroll function, successfully making enemy switch directions while patrolling
This commit is contained in:
@@ -12,6 +12,24 @@ struct
|
|||||||
|
|
||||||
fun exists (id, collisions) = helpExists (0, id, collisions)
|
fun exists (id, collisions) = helpExists (0, id, collisions)
|
||||||
|
|
||||||
|
fun canWalkAhead (x, y, wallTree, platformTree) =
|
||||||
|
let
|
||||||
|
val ww = Constants.worldWidth
|
||||||
|
val wh = Constants.worldHeight
|
||||||
|
|
||||||
|
val searchWidth = Constants.enemySize
|
||||||
|
|
||||||
|
val y = y + Constants.enemySize - 5
|
||||||
|
val searchHeight = 10
|
||||||
|
in
|
||||||
|
QuadTree.hasCollisionAt
|
||||||
|
(x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, wallTree)
|
||||||
|
orelse
|
||||||
|
QuadTree.hasCollisionAt
|
||||||
|
(x, y, searchWidth, searchHeight, 0, 0, ww, wh, ~1, platformTree)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
fun getPatrollPatches (enemy: enemy, wallTree, platformTree, acc) =
|
fun getPatrollPatches (enemy: enemy, wallTree, platformTree, acc) =
|
||||||
let
|
let
|
||||||
(* This function is meant to check
|
(* This function is meant to check
|
||||||
@@ -58,12 +76,14 @@ struct
|
|||||||
, wallTree
|
, wallTree
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
if hasWallAhead then
|
if
|
||||||
EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
hasWallAhead
|
||||||
else
|
then EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
(* todo: invert direction if moving further left
|
else (* invert direction if moving further left
|
||||||
* will result in falling down *)
|
* will result in falling down *) if
|
||||||
acc
|
canWalkAhead (searchStartX, y, wallTree, platformTree)
|
||||||
|
then acc
|
||||||
|
else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
end
|
end
|
||||||
| MOVE_RIGHT =>
|
| MOVE_RIGHT =>
|
||||||
let
|
let
|
||||||
@@ -90,12 +110,14 @@ struct
|
|||||||
, wallTree
|
, wallTree
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
if hasWallAhead then
|
if
|
||||||
EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
hasWallAhead
|
||||||
else
|
then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
(* todo: invert direction if moving further left
|
else (* invert direction if moving further right
|
||||||
* will result in falling down *)
|
* will result in falling down *) if
|
||||||
acc
|
canWalkAhead (searchStartX, y, wallTree, platformTree)
|
||||||
|
then acc
|
||||||
|
else EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
end
|
end
|
||||||
| STAY_STILL => acc
|
| STAY_STILL => acc
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -147,15 +147,15 @@ struct
|
|||||||
val walls = Vector.fromList [wall1, wall2, wall3]
|
val walls = Vector.fromList [wall1, wall2, wall3]
|
||||||
val wallTree = Wall.generateTree walls
|
val wallTree = Wall.generateTree walls
|
||||||
|
|
||||||
val plat1 = {id = 1, x = 155, y = 911, width = 155}
|
val plat1 = {id = 1, x = 155, y = 911, width = 199}
|
||||||
val platforms = Vector.fromList [plat1]
|
val platforms = Vector.fromList [plat1]
|
||||||
val platformTree = Platform.generateTree platforms
|
val platformTree = Platform.generateTree platforms
|
||||||
|
|
||||||
val enemy1 =
|
val enemy1 =
|
||||||
{ id = 1
|
{ id = 1
|
||||||
, x = 300
|
, x = 300
|
||||||
, y = 745
|
, y = 855
|
||||||
, health = 5
|
, health = 1
|
||||||
, xAxis = MOVE_LEFT
|
, xAxis = MOVE_LEFT
|
||||||
, yAxis = FALLING
|
, yAxis = FALLING
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ struct
|
|||||||
{ id = 2
|
{ id = 2
|
||||||
, x = 555
|
, x = 555
|
||||||
, y = 945
|
, y = 945
|
||||||
, health = 5
|
, health = 1
|
||||||
, xAxis = MOVE_LEFT
|
, xAxis = MOVE_LEFT
|
||||||
, yAxis = FALLING
|
, yAxis = FALLING
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ struct
|
|||||||
{ id = 3
|
{ id = 3
|
||||||
, x = 979
|
, x = 979
|
||||||
, y = 945
|
, y = 945
|
||||||
, health = 5
|
, health = 1
|
||||||
, xAxis = MOVE_RIGHT
|
, xAxis = MOVE_RIGHT
|
||||||
, yAxis = FALLING
|
, yAxis = FALLING
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user