add functionality for enemy to walk to appropriate position if next platform is below current one, but only partially overlapping with current platform so enemy will not reach it if they drop down from current position
This commit is contained in:
@@ -88,10 +88,10 @@ struct
|
|||||||
if
|
if
|
||||||
hasWallAhead
|
hasWallAhead
|
||||||
then EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
then EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
else (* invert direction if moving further left
|
else if canWalkAhead (searchStartX, y, wallTree, platformTree) then
|
||||||
* will result in falling down *) if
|
(* invert direction if moving further left
|
||||||
canWalkAhead (searchStartX, y, wallTree, platformTree)
|
* will result in falling down *)
|
||||||
then acc
|
acc
|
||||||
else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
end
|
end
|
||||||
| MOVE_RIGHT =>
|
| MOVE_RIGHT =>
|
||||||
@@ -122,10 +122,10 @@ struct
|
|||||||
if
|
if
|
||||||
hasWallAhead
|
hasWallAhead
|
||||||
then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
else (* invert direction if moving further right
|
else if canWalkAhead (searchStartX, y, wallTree, platformTree) then
|
||||||
* will result in falling down *) if
|
(* invert direction if moving further right
|
||||||
canWalkAhead (searchStartX, y, wallTree, platformTree)
|
* will result in falling down *)
|
||||||
then acc
|
acc
|
||||||
else EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
else EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
end
|
end
|
||||||
| STAY_STILL => acc
|
| STAY_STILL => acc
|
||||||
@@ -190,7 +190,7 @@ struct
|
|||||||
val nPlatFinishX = nPlatX + nPlatW
|
val nPlatFinishX = nPlatX + nPlatW
|
||||||
in
|
in
|
||||||
(isBetween (nPlatX, pPlatX, nPlatFinishX)
|
(isBetween (nPlatX, pPlatX, nPlatFinishX)
|
||||||
orelse isBetween (nPlatX, pPlatFinishX, nPlatFinishX))
|
orelse isBetween (nPlatX, pPlatFinishX, nPlatFinishX))
|
||||||
andalso pPlatY > nPlatY
|
andalso pPlatY > nPlatY
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -206,33 +206,65 @@ struct
|
|||||||
val standingOnPlat = standingOnArea (enemy, platformTree)
|
val standingOnPlat = standingOnArea (enemy, platformTree)
|
||||||
in
|
in
|
||||||
if ey >= platY andalso standingOnPlat then
|
if ey >= platY andalso standingOnPlat then
|
||||||
if isBetween (platX, ecx, platFinishX) then
|
if
|
||||||
|
isBetween (platX, ecx, platFinishX)
|
||||||
|
then
|
||||||
(* can jump from same position enemy is at *)
|
(* can jump from same position enemy is at *)
|
||||||
case eyAxis of
|
case eyAxis of
|
||||||
ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
||||||
| FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
| FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
||||||
| _ => acc
|
| _ => acc
|
||||||
else
|
else
|
||||||
(* have to travel either left or right before jumping *)
|
(* have to travel either left or right before jumping *)
|
||||||
if ecx < platX then
|
if ecx < platX then
|
||||||
EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
else
|
else
|
||||||
EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
else
|
else
|
||||||
acc
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun canDrop (nextPlatform, platformTree, enemy) =
|
fun canDrop (prevPlatform, nextPlatform) =
|
||||||
let
|
let
|
||||||
val {x = platX, y = platY, width = platW, ...} = nextPlatform
|
val {x = pPlatX, y = pPlatY, width = pPlatW, ...} = prevPlatform
|
||||||
val platFinishX = platX + platW
|
val pPlatFinishX = pPlatX + pPlatW
|
||||||
|
|
||||||
val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy
|
val {x = nPlatX, y = nPlatY, width = nPlatW, ...} = nextPlatform
|
||||||
|
val nPlatFinishX = nPlatX + nPlatW
|
||||||
|
in
|
||||||
|
(isBetween (nPlatX, pPlatX, nPlatFinishX)
|
||||||
|
orelse isBetween (nPlatX, pPlatFinishX, nPlatFinishX))
|
||||||
|
andalso pPlatY < nPlatY
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getDropPatches (nextPlatform, platformTree, enemy, acc) =
|
||||||
|
let
|
||||||
|
val {x = platX, y = platY, width = platWidth, ...} = nextPlatform
|
||||||
|
val platFinishX = platX + platWidth
|
||||||
|
|
||||||
|
val {x = eX, y = ey, yAxis = eyAxis, xAxis = exAxis, ...} = enemy
|
||||||
|
val ecx = eX + (Constants.enemySize div 2)
|
||||||
|
val ey = ey + Constants.enemySize
|
||||||
|
|
||||||
val standingOnPlat = standingOnArea (enemy, platformTree)
|
val standingOnPlat = standingOnArea (enemy, platformTree)
|
||||||
in
|
in
|
||||||
isBetween (platX, eX, platFinishX) andalso standingOnPlat
|
if ey <= platY andalso standingOnPlat then
|
||||||
andalso ey < platY
|
if
|
||||||
|
isBetween (platX, ecx, platFinishX)
|
||||||
|
then
|
||||||
|
(* can jump from same position enemy is at *)
|
||||||
|
case eyAxis of
|
||||||
|
ON_GROUND => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
||||||
|
| FALLING => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
||||||
|
| _ => acc
|
||||||
|
else
|
||||||
|
(* have to travel either left or right before jumping *)
|
||||||
|
if ecx < platX then
|
||||||
|
EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
|
else
|
||||||
|
EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
|
else
|
||||||
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
(* get patches to help enemy move to nextPlatformID *)
|
(* get patches to help enemy move to nextPlatformID *)
|
||||||
@@ -245,11 +277,14 @@ struct
|
|||||||
val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy
|
val {x = eX, y = ey, yAxis = eyAxis, ...} = enemy
|
||||||
|
|
||||||
val canJump = canJump (currentPlatform, nextPlatform)
|
val canJump = canJump (currentPlatform, nextPlatform)
|
||||||
val canDrop = canDrop (nextPlatform, platformTree, enemy)
|
val canDrop = canDrop (currentPlatform, nextPlatform)
|
||||||
in
|
in
|
||||||
if canJump then getJumpPatches (nextPlatform, platformTree, enemy, acc)
|
if canJump then
|
||||||
else if canDrop then EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
getJumpPatches (nextPlatform, platformTree, enemy, acc)
|
||||||
else acc
|
else if canDrop then
|
||||||
|
getDropPatches (nextPlatform, platformTree, enemy, acc)
|
||||||
|
else
|
||||||
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun canJumpOnPlatform (player, platforms, enemy: enemy, platformTree, acc) =
|
fun canJumpOnPlatform (player, platforms, enemy: enemy, platformTree, acc) =
|
||||||
|
|||||||
Reference in New Issue
Block a user