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 enemySize = 35
|
||||||
val enemySizeReal: Real32.real = 35.0
|
val enemySizeReal: Real32.real = 35.0
|
||||||
val moveEnemyBy = 3
|
val moveEnemyBy = 3
|
||||||
|
val batRestLimit = 155
|
||||||
|
|
||||||
val moveProjectileBy = 11
|
val moveProjectileBy = 11
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -499,6 +499,55 @@ struct
|
|||||||
end
|
end
|
||||||
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
|
fun updateEnemyState
|
||||||
( enemy
|
( enemy
|
||||||
, projectiles
|
, projectiles
|
||||||
@@ -541,5 +590,15 @@ struct
|
|||||||
, enemyList
|
, enemyList
|
||||||
, fallingList
|
, fallingList
|
||||||
)
|
)
|
||||||
|
| STRAIGHT_BAT =>
|
||||||
|
updateStraightBat
|
||||||
|
( player
|
||||||
|
, enemy
|
||||||
|
, walls
|
||||||
|
, wallTree
|
||||||
|
, projectileTree
|
||||||
|
, enemyList
|
||||||
|
, fallingList
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ sig
|
|||||||
| W_Y_AXIS of GameType.y_axis
|
| W_Y_AXIS of GameType.y_axis
|
||||||
| W_PLAT_ID of int
|
| W_PLAT_ID of int
|
||||||
| W_NEXT_PLAT_ID of int
|
| W_NEXT_PLAT_ID of int
|
||||||
|
| W_BAT_REST of int
|
||||||
|
|
||||||
val withPatch: GameType.enemy * enemy_patch -> GameType.enemy
|
val withPatch: GameType.enemy * enemy_patch -> GameType.enemy
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ struct
|
|||||||
| W_Y_AXIS of GameType.y_axis
|
| W_Y_AXIS of GameType.y_axis
|
||||||
| W_PLAT_ID of int
|
| W_PLAT_ID of int
|
||||||
| W_NEXT_PLAT_ID of int
|
| W_NEXT_PLAT_ID of int
|
||||||
|
| W_BAT_REST of int
|
||||||
|
|
||||||
fun mkEnemy
|
fun mkEnemy
|
||||||
(id, health, x, y, xAxis, yAxis, variant, platID, nextPlatID, batRest) =
|
(id, health, x, y, xAxis, yAxis, variant, platID, nextPlatID, batRest) =
|
||||||
@@ -136,6 +138,19 @@ struct
|
|||||||
, nextPlatID
|
, nextPlatID
|
||||||
, batRest
|
, batRest
|
||||||
)
|
)
|
||||||
|
| W_BAT_REST batRest =>
|
||||||
|
mkEnemy
|
||||||
|
( id
|
||||||
|
, health
|
||||||
|
, x
|
||||||
|
, y
|
||||||
|
, xAxis
|
||||||
|
, yAxis
|
||||||
|
, variant
|
||||||
|
, platID
|
||||||
|
, nextPlatID
|
||||||
|
, batRest
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun withPatches (enemy, lst) =
|
fun withPatches (enemy, lst) =
|
||||||
|
|||||||
@@ -217,9 +217,9 @@ struct
|
|||||||
, x = 751
|
, x = 751
|
||||||
, y = 555
|
, y = 555
|
||||||
, health = 1
|
, health = 1
|
||||||
, xAxis = STAY_STILL
|
, xAxis = MOVE_RIGHT
|
||||||
, yAxis = FALLING
|
, yAxis = FALLING
|
||||||
, variant = EnemyVariants.FOLLOW_SLIME
|
, variant = EnemyVariants.STRAIGHT_BAT
|
||||||
, platID = ~1
|
, platID = ~1
|
||||||
, nextPlatID = ~1
|
, nextPlatID = ~1
|
||||||
, batRest = 0
|
, batRest = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user