create enemy patch structure

This commit is contained in:
2025-01-12 23:28:03 +00:00
parent ca6b0b2160
commit 27fbe1c12e
2 changed files with 33 additions and 0 deletions

32
fcore/enemy-patch.sml Normal file
View File

@@ -0,0 +1,32 @@
structure EnemyPatch =
struct
datatype enemy_patch =
W_HEALTH of int
| W_X of int
| W_Y of int
| W_X_AXIS of GameType.x_axis
| W_Y_AXIS of GameType.y_axis
fun mkEnemy (id, health, x, y, xAxis, yAxis) =
{id = id, health = health, x = x, y = y, xAxis = xAxis, yAxis = yAxis}
fun withPatch (enemy, patch) =
let
val {id, health, x, y, xAxis, yAxis} = enemy
in
case patch of
W_HEALTH health => mkEnemy (id, health, x, y, xAxis, yAxis)
| W_X x => mkEnemy (id, health, x, y, xAxis, yAxis)
| W_X_AXIS xAxis => mkEnemy (id, health, x, y, xAxis, yAxis)
| W_Y y => mkEnemy (id, health, x, y, xAxis, yAxis)
| W_Y_AXIS yAxis => mkEnemy (id, health, x, y, xAxis, yAxis)
end
fun withPatches (enemy, lst) =
case lst of
hd :: tl =>
let val enemy = withPatch (enemy, hd)
in withPatches (enemy, tl)
end
| [] => enemy
end

View File

@@ -18,6 +18,7 @@ fcore/enemy.sml
fcore/game-type.sml fcore/game-type.sml
fcore/player-patch.sml fcore/player-patch.sml
fcore/enemy-patch.sml
fcore/physics.sml fcore/physics.sml
fcore/player.sml fcore/player.sml