initial implementation of bat's update function (todo: make bat oscillate up and down while it also moves in x axis, and also code bat's collisions with player, adding to falling list if necessary, or being filtered by player's attack)
This commit is contained in:
@@ -30,6 +30,7 @@ struct
|
||||
val enemySize = 35
|
||||
val enemySizeReal: Real32.real = 35.0
|
||||
val moveEnemyBy = 3
|
||||
val batRestLimit = 155
|
||||
|
||||
val moveProjectileBy = 11
|
||||
end
|
||||
|
||||
@@ -499,6 +499,55 @@ struct
|
||||
end
|
||||
end
|
||||
|
||||
fun updateStraightBat
|
||||
(player, enemy, walls, wallTree, projectileTree, enemyList, fallingList) =
|
||||
let
|
||||
val {x, y, batRest, ...} = enemy
|
||||
val size = Constants.enemySize
|
||||
in
|
||||
if QuadTree.hasCollisionAt (x, y, size, size, ~1, wallTree) then
|
||||
(* has collision with wall *)
|
||||
let
|
||||
val enemy =
|
||||
if batRest >= Constants.batRestLimit then
|
||||
(* make enemy move in opposite direction *)
|
||||
case #xAxis enemy of
|
||||
MOVE_RIGHT =>
|
||||
EnemyPatch.withPatches
|
||||
( enemy
|
||||
, [ EnemyPatch.W_X_AXIS MOVE_LEFT
|
||||
, EnemyPatch.W_X (x - (Constants.moveEnemyBy * 9))
|
||||
]
|
||||
)
|
||||
| MOVE_LEFT =>
|
||||
EnemyPatch.withPatches
|
||||
( enemy
|
||||
, [ EnemyPatch.W_X_AXIS MOVE_RIGHT
|
||||
, EnemyPatch.W_X (x + (Constants.moveEnemyBy * 9))
|
||||
]
|
||||
)
|
||||
| _ => enemy
|
||||
else
|
||||
(* keep resting until we hit rest limit *)
|
||||
EnemyPatch.withPatch (enemy, EnemyPatch.W_BAT_REST (batRest + 1))
|
||||
in
|
||||
(enemy :: enemyList, fallingList)
|
||||
end
|
||||
else
|
||||
(* no collision, so continue moving in direction *)
|
||||
let
|
||||
val patches =
|
||||
case #xAxis enemy of
|
||||
MOVE_RIGHT => [EnemyPatch.W_X (x + Constants.moveEnemyBy)]
|
||||
| MOVE_LEFT => [EnemyPatch.W_X (x - Constants.moveEnemyBy)]
|
||||
| STAY_STILL => []
|
||||
val patches = EnemyPatch.W_BAT_REST 0 :: patches
|
||||
val enemy = EnemyPatch.withPatches (enemy, patches)
|
||||
in
|
||||
(enemy :: enemyList, fallingList)
|
||||
end
|
||||
end
|
||||
|
||||
fun updateEnemyState
|
||||
( enemy
|
||||
, projectiles
|
||||
@@ -541,5 +590,15 @@ struct
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
| STRAIGHT_BAT =>
|
||||
updateStraightBat
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, projectileTree
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,6 +8,7 @@ sig
|
||||
| W_Y_AXIS of GameType.y_axis
|
||||
| W_PLAT_ID of int
|
||||
| W_NEXT_PLAT_ID of int
|
||||
| W_BAT_REST of int
|
||||
|
||||
val withPatch: GameType.enemy * enemy_patch -> GameType.enemy
|
||||
|
||||
@@ -24,6 +25,7 @@ struct
|
||||
| W_Y_AXIS of GameType.y_axis
|
||||
| W_PLAT_ID of int
|
||||
| W_NEXT_PLAT_ID of int
|
||||
| W_BAT_REST of int
|
||||
|
||||
fun mkEnemy
|
||||
(id, health, x, y, xAxis, yAxis, variant, platID, nextPlatID, batRest) =
|
||||
@@ -136,6 +138,19 @@ struct
|
||||
, nextPlatID
|
||||
, batRest
|
||||
)
|
||||
| W_BAT_REST batRest =>
|
||||
mkEnemy
|
||||
( id
|
||||
, health
|
||||
, x
|
||||
, y
|
||||
, xAxis
|
||||
, yAxis
|
||||
, variant
|
||||
, platID
|
||||
, nextPlatID
|
||||
, batRest
|
||||
)
|
||||
end
|
||||
|
||||
fun withPatches (enemy, lst) =
|
||||
|
||||
@@ -217,9 +217,9 @@ struct
|
||||
, x = 751
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = STAY_STILL
|
||||
, xAxis = MOVE_RIGHT
|
||||
, yAxis = FALLING
|
||||
, variant = EnemyVariants.FOLLOW_SLIME
|
||||
, variant = EnemyVariants.STRAIGHT_BAT
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
|
||||
Reference in New Issue
Block a user