when enemy jumps or drops without needing to move horizontally to reach platform, tell enemy to stay still so we don't risk falling off platform
This commit is contained in:
@@ -176,10 +176,16 @@ struct
|
|||||||
isBetween (platX, ecx, platFinishX)
|
isBetween (platX, ecx, platFinishX)
|
||||||
then
|
then
|
||||||
(* can jump from same position enemy is at *)
|
(* can jump from same position enemy is at *)
|
||||||
case eyAxis of
|
let
|
||||||
ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
(* since we want to jump vertically and not risk falling off by
|
||||||
| FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
* jumping + moving either left or right, make enemy stay still *)
|
||||||
| _ => acc
|
val acc = EnemyPatch.W_X_AXIS STAY_STILL :: acc
|
||||||
|
in
|
||||||
|
case eyAxis of
|
||||||
|
ON_GROUND => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
||||||
|
| FALLING => EnemyPatch.W_Y_AXIS (JUMPING 0) :: acc
|
||||||
|
| _ => acc
|
||||||
|
end
|
||||||
else (* have to travel either left or right before jumping *) if
|
else (* have to travel either left or right before jumping *) if
|
||||||
ecx < platX
|
ecx < platX
|
||||||
then
|
then
|
||||||
@@ -219,10 +225,14 @@ struct
|
|||||||
isBetween (platX, ecx, platFinishX)
|
isBetween (platX, ecx, platFinishX)
|
||||||
then
|
then
|
||||||
(* can jump from same position enemy is at *)
|
(* can jump from same position enemy is at *)
|
||||||
case eyAxis of
|
let
|
||||||
ON_GROUND => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
val acc = EnemyPatch.W_X_AXIS STAY_STILL :: acc
|
||||||
| FALLING => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
in
|
||||||
| _ => acc
|
case eyAxis of
|
||||||
|
ON_GROUND => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
||||||
|
| FALLING => EnemyPatch.W_Y_AXIS DROP_BELOW_PLATFORM :: acc
|
||||||
|
| _ => acc
|
||||||
|
end
|
||||||
else (* have to travel either left or right before jumping *) if
|
else (* have to travel either left or right before jumping *) if
|
||||||
ecx < platX
|
ecx < platX
|
||||||
then
|
then
|
||||||
@@ -420,24 +430,28 @@ struct
|
|||||||
(* if only one side in x direction overlaps with platform,
|
(* if only one side in x direction overlaps with platform,
|
||||||
* then move enemy left/right to make them fully overlap with platform *)
|
* then move enemy left/right to make them fully overlap with platform *)
|
||||||
fun getHorizontalLandingPatches (enemy, nextPlatform, acc) =
|
fun getHorizontalLandingPatches (enemy, nextPlatform, acc) =
|
||||||
let
|
case #xAxis enemy of
|
||||||
val {x = px, width = pw, ...} = nextPlatform
|
STAY_STILL =>
|
||||||
val pfx = px + pw
|
|
||||||
|
|
||||||
val {x = ex, ...} = enemy
|
|
||||||
val efx = ex + Constants.enemySize
|
|
||||||
in
|
|
||||||
if isBetween (px, ex, pfx) andalso isBetween (px, efx, pfx) then
|
|
||||||
acc
|
acc
|
||||||
else
|
| _ =>
|
||||||
let
|
let
|
||||||
val startDiff = abs (px - ex)
|
val {x = px, width = pw, ...} = nextPlatform
|
||||||
val endDiff = abs (pfx - efx)
|
val pfx = px + pw
|
||||||
in
|
|
||||||
if startDiff > endDiff then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
val {x = ex, ...} = enemy
|
||||||
else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
val efx = ex + Constants.enemySize
|
||||||
end
|
in
|
||||||
end
|
if isBetween (px, ex, pfx) andalso isBetween (px, efx, pfx) then
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val startDiff = abs (px - ex)
|
||||||
|
val endDiff = abs (pfx - efx)
|
||||||
|
in
|
||||||
|
if startDiff > endDiff then EnemyPatch.W_X_AXIS MOVE_LEFT :: acc
|
||||||
|
else EnemyPatch.W_X_AXIS MOVE_RIGHT :: acc
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
fun getFallingPatches (enemy, newPlatformID, platforms, acc) =
|
fun getFallingPatches (enemy, newPlatformID, platforms, acc) =
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -320,10 +320,6 @@ struct
|
|||||||
let
|
let
|
||||||
val player = #player game
|
val player = #player game
|
||||||
|
|
||||||
val _ = print
|
|
||||||
("(playerX, playerY) = (" ^ Int.toString (#x player) ^ ", "
|
|
||||||
^ Int.toString (#y player) ^ ")\n")
|
|
||||||
|
|
||||||
val patches = getProjectilePatches player
|
val patches = getProjectilePatches player
|
||||||
val player = PlayerPatch.withPatches (player, patches)
|
val player = PlayerPatch.withPatches (player, patches)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user