From ce7520ce81b3e44af174c2bc0f72bab89d6a8ea6 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 12 Jan 2025 23:33:20 +0000 Subject: [PATCH] derive EnemyPhysics module from functor --- fcore/constants.sml | 1 + fcore/enemy-patch.sml | 16 +++++++++++++++- fcore/physics.sml | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/fcore/constants.sml b/fcore/constants.sml index 4811ddb..7cdf052 100644 --- a/fcore/constants.sml +++ b/fcore/constants.sml @@ -28,4 +28,5 @@ struct (* constants for enemy *) val enemySize = 35 val enemySizeReal: Real32.real = 35.0 + val moveEnemyBy = 5 end diff --git a/fcore/enemy-patch.sml b/fcore/enemy-patch.sml index f66d853..5d59e84 100644 --- a/fcore/enemy-patch.sml +++ b/fcore/enemy-patch.sml @@ -1,4 +1,18 @@ -structure EnemyPatch = +signature ENEMY_PATCH = +sig + 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 + + val withPatch: GameType.enemy * enemy_patch -> GameType.enemy + + val withPatches: GameType.enemy * enemy_patch list -> GameType.enemy +end + +structure EnemyPatch: ENEMY_PATCH = struct datatype enemy_patch = W_HEALTH of int diff --git a/fcore/physics.sml b/fcore/physics.sml index 42d133a..aae71a4 100644 --- a/fcore/physics.sml +++ b/fcore/physics.sml @@ -94,3 +94,26 @@ structure PlayerPhysics = val W_Y = PlayerPatch.W_Y val W_Y_AXIS = PlayerPatch.W_Y_AXIS end) + +structure EnemyPhysics = + MakePhysics + (struct + type t = GameType.enemy + type patch = EnemyPatch.enemy_patch + + (* constants for physics *) + val moveBy = Constants.moveEnemyBy + val floatLimit = Constants.floatLimit + val jumpLimit = Constants.jumpLimit + + (* destructuring functions *) + fun getX ({x, ...}: t) = x + fun getY ({y, ...}: t) = y + + fun getXAxis ({xAxis, ...}: t) = xAxis + fun getYAxis ({yAxis, ...}: t) = yAxis + + val W_X = EnemyPatch.W_X + val W_Y = EnemyPatch.W_Y + val W_Y_AXIS = EnemyPatch.W_Y_AXIS + end)