refactor file order in preparation for adding GapMap for enemy

This commit is contained in:
2025-02-13 11:24:44 +00:00
parent 4c8b404c09
commit f1521acec1
15 changed files with 173 additions and 158 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "vendored/brolib-sml"]
path = vendored/brolib-sml
url = https://github.com/hummy123/brolib-sml

View File

@@ -1,6 +1,9 @@
structure EnemyBehaviour = structure EnemyBehaviour =
struct struct
open GameType open GameType
open EnemyType
open EntityType
(* if player is attacking, does enemy collide with attack? *) (* if player is attacking, does enemy collide with attack? *)
fun isCollidingWithPlayerAttack (player: player, enemy: enemy) = fun isCollidingWithPlayerAttack (player: player, enemy: enemy) =
let let
@@ -569,44 +572,40 @@ struct
, enemyList , enemyList
, fallingList , fallingList
) = ) =
let case #variant enemy of
open EnemyVariants PATROL_SLIME =>
in updatePatrolState
case #variant enemy of ( player
PATROL_SLIME => , enemy
updatePatrolState , walls
( player , wallTree
, enemy , platforms
, walls , platformTree
, wallTree , projectileTree
, platforms , enemyList
, platformTree , fallingList
, projectileTree )
, enemyList | FOLLOW_SLIME =>
, fallingList updateFollowState
) ( player
| FOLLOW_SLIME => , enemy
updateFollowState , walls
( player , wallTree
, enemy , platforms
, walls , platformTree
, wallTree , projectileTree
, platforms , graph
, platformTree , enemyList
, projectileTree , fallingList
, graph )
, enemyList | STRAIGHT_BAT =>
, fallingList updateStraightBat
) ( player
| STRAIGHT_BAT => , enemy
updateStraightBat , walls
( player , wallTree
, enemy , projectileTree
, walls , enemyList
, wallTree , fallingList
, projectileTree )
, enemyList
, fallingList
)
end
end end

View File

@@ -4,18 +4,18 @@ sig
W_HEALTH of int W_HEALTH of int
| W_X of int | W_X of int
| W_Y of int | W_Y of int
| W_X_AXIS of GameType.x_axis | W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of GameType.y_axis | W_Y_AXIS of EntityType.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 | W_BAT_REST of int
| W_BAT_MAX_Y of int | W_BAT_MAX_Y of int
| W_BAT_MIN_Y of int | W_BAT_MIN_Y of int
| W_BAT_DIR_Y of GameType.bat_dir_y | W_BAT_DIR_Y of EnemyType.bat_dir_y
val withPatch: GameType.enemy * enemy_patch -> GameType.enemy val withPatch: EnemyType.enemy * enemy_patch -> EnemyType.enemy
val withPatches: GameType.enemy * enemy_patch list -> GameType.enemy val withPatches: EnemyType.enemy * enemy_patch list -> EnemyType.enemy
end end
structure EnemyPatch: ENEMY_PATCH = structure EnemyPatch: ENEMY_PATCH =
@@ -24,14 +24,14 @@ struct
W_HEALTH of int W_HEALTH of int
| W_X of int | W_X of int
| W_Y of int | W_Y of int
| W_X_AXIS of GameType.x_axis | W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of GameType.y_axis | W_Y_AXIS of EntityType.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 | W_BAT_REST of int
| W_BAT_MAX_Y of int | W_BAT_MAX_Y of int
| W_BAT_MIN_Y of int | W_BAT_MIN_Y of int
| W_BAT_DIR_Y of GameType.bat_dir_y | W_BAT_DIR_Y of EnemyType.bat_dir_y
fun mkEnemy fun mkEnemy
( id ( id

View File

@@ -0,0 +1,49 @@
signature ENEMY_TYPE =
sig
datatype variant = PATROL_SLIME | FOLLOW_SLIME | STRAIGHT_BAT
datatype bat_dir_y = UP | DOWN
type enemy =
{ id: int
, health: int
, x: int
, y: int
, xAxis: EntityType.x_axis
, yAxis: EntityType.y_axis
, variant: variant
, platID: int
, nextPlatID: int
, batRest: int
, batDirY: bat_dir_y
, batMaxY: int
, batMinY: int
}
type falling_enemy = {x: int, y: int, variant: variant}
end
structure EnemyType: ENEMY_TYPE =
struct
datatype variant = PATROL_SLIME | FOLLOW_SLIME | STRAIGHT_BAT
datatype bat_dir_y = UP | DOWN
type enemy =
{ id: int
, health: int
, x: int
, y: int
, xAxis: EntityType.x_axis
, yAxis: EntityType.y_axis
, variant: variant
, platID: int
, nextPlatID: int
, batRest: int
, batDirY: bat_dir_y
, batMaxY: int
, batMinY: int
}
type falling_enemy = {x: int, y: int, variant: variant}
end

View File

@@ -1,7 +0,0 @@
signature ENEMY_VARIANTS =
sig
datatype t = PATROL_SLIME | FOLLOW_SLIME | STRAIGHT_BAT
end
structure EnemyVariants: ENEMY_VARIANTS =
struct datatype t = PATROL_SLIME | FOLLOW_SLIME | STRAIGHT_BAT end

View File

@@ -1,6 +1,6 @@
structure Enemy = structure Enemy =
struct struct
open GameType open EnemyType
(* returns a vector of enemies, with new state (like position, etc.). (* returns a vector of enemies, with new state (like position, etc.).
* Also filters any enemies from list if defeated. * Also filters any enemies from list if defeated.

View File

@@ -1,6 +1,8 @@
structure FallingEnemies = structure FallingEnemies =
struct struct
open EnemyType
open GameType open GameType
open EntityType
fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) = fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) =
if pos = Vector.length fallingVec then if pos = Vector.length fallingVec then
@@ -23,7 +25,7 @@ struct
, QuadTree.create (Constants.worldWidth, Constants.worldHeight) , QuadTree.create (Constants.worldWidth, Constants.worldHeight)
) )
fun isCollidingWithPlayerAttack (player: player, fx, fy) = fun isCollidingWithPlayerAttack (player: GameType.player, fx, fy) =
let let
val {x = px, y = py, mainAttack, facing, ...} = player val {x = px, y = py, mainAttack, facing, ...} = player
in in
@@ -44,7 +46,7 @@ struct
| _ => false | _ => false
end end
fun updateList (pos, vec, player: player, acc) = fun updateList (pos, vec, player: GameType.player, acc) =
if pos < 0 then if pos < 0 then
acc acc
else else
@@ -55,7 +57,7 @@ struct
val ww = Constants.worldWidth val ww = Constants.worldWidth
val wh = Constants.worldHeight val wh = Constants.worldHeight
in in
if isCollidingWithPlayerAttack (player : player, x, y) then if isCollidingWithPlayerAttack (player, x, y) then
(* filter out if player is attacking falling enemy *) (* filter out if player is attacking falling enemy *)
updateList (pos - 1, vec, player, acc) updateList (pos - 1, vec, player, acc)
else if Collision.isCollidingPlus (x, y, size, size, 0, 0, ww, wh) then else if Collision.isCollidingPlus (x, y, size, size, 0, 0, ww, wh) then

27
fcore/entity-type.sml Normal file
View File

@@ -0,0 +1,27 @@
signature ENTITY_TYPE =
sig
datatype y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int
datatype x_axis = MOVE_LEFT | STAY_STILL | MOVE_RIGHT
datatype facing = FACING_LEFT | FACING_RIGHT
end
structure EntityType :> ENTITY_TYPE =
struct
datatype y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int
datatype x_axis = MOVE_LEFT | STAY_STILL | MOVE_RIGHT
datatype facing = FACING_LEFT | FACING_RIGHT
end

View File

@@ -4,21 +4,10 @@ sig
type platform = {id: int, x: int, y: int, width: int} type platform = {id: int, x: int, y: int, width: int}
datatype y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int
datatype x_axis = MOVE_LEFT | STAY_STILL | MOVE_RIGHT
datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int
datatype player_attacked = NOT_ATTACKED | ATTACKED of int datatype player_attacked = NOT_ATTACKED | ATTACKED of int
datatype facing = FACING_LEFT | FACING_RIGHT
datatype main_attack = datatype main_attack =
MAIN_NOT_ATTACKING MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool} | MAIN_ATTACKING of {length: int, growing: bool}
@@ -26,16 +15,16 @@ sig
type defeated_enemies = {angle: int} type defeated_enemies = {angle: int}
type player_projectile = {x: int, y: int, facing: facing} type player_projectile = {x: int, y: int, facing: EntityType.facing}
type player = type player =
{ yAxis: y_axis { yAxis: EntityType.y_axis
, xAxis: x_axis , xAxis: EntityType.x_axis
, recoil: player_recoil , recoil: player_recoil
, attacked: player_attacked , attacked: player_attacked
, mainAttack: main_attack , mainAttack: main_attack
, mainAttackPressed: bool , mainAttackPressed: bool
, facing: facing , facing: EntityType.facing
, health: int , health: int
, x: int , x: int
, y: int , y: int
@@ -46,35 +35,15 @@ sig
, platID: int , platID: int
} }
datatype bat_dir_y = UP | DOWN
type enemy =
{ id: int
, health: int
, x: int
, y: int
, xAxis: x_axis
, yAxis: y_axis
, variant: EnemyVariants.t
, platID: int
, nextPlatID: int
, batRest: int
, batDirY: bat_dir_y
, batMaxY: int
, batMinY: int
}
type falling_enemy = {x: int, y: int, variant: EnemyVariants.t}
type game_type = type game_type =
{ player: player { player: player
, walls: wall vector , walls: wall vector
, wallTree: QuadTree.t , wallTree: QuadTree.t
, platforms: platform vector , platforms: platform vector
, platformTree: QuadTree.t , platformTree: QuadTree.t
, enemies: enemy vector , enemies: EnemyType.enemy vector
, graph: PlatSet.elem vector vector , graph: PlatSet.elem vector vector
, fallingEnemies: falling_enemy vector , fallingEnemies: EnemyType.falling_enemy vector
} }
val initial: game_type val initial: game_type
@@ -87,21 +56,10 @@ struct
(* all platforms have a fixed visual height and a fixed collision height *) (* all platforms have a fixed visual height and a fixed collision height *)
type platform = {id: int, x: int, y: int, width: int} type platform = {id: int, x: int, y: int, width: int}
datatype y_axis =
ON_GROUND
| FALLING
| DROP_BELOW_PLATFORM
| JUMPING of int
| FLOATING of int
datatype x_axis = MOVE_LEFT | STAY_STILL | MOVE_RIGHT
datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int
datatype player_attacked = NOT_ATTACKED | ATTACKED of int datatype player_attacked = NOT_ATTACKED | ATTACKED of int
datatype facing = FACING_LEFT | FACING_RIGHT
datatype main_attack = datatype main_attack =
MAIN_NOT_ATTACKING MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool} | MAIN_ATTACKING of {length: int, growing: bool}
@@ -109,16 +67,16 @@ struct
type defeated_enemies = {angle: int} type defeated_enemies = {angle: int}
type player_projectile = {x: int, y: int, facing: facing} type player_projectile = {x: int, y: int, facing: EntityType.facing}
type player = type player =
{ yAxis: y_axis { yAxis: EntityType.y_axis
, xAxis: x_axis , xAxis: EntityType.x_axis
, recoil: player_recoil , recoil: player_recoil
, attacked: player_attacked , attacked: player_attacked
, mainAttack: main_attack , mainAttack: main_attack
, mainAttackPressed: bool , mainAttackPressed: bool
, facing: facing , facing: EntityType.facing
, health: int , health: int
, x: int , x: int
, y: int , y: int
@@ -129,47 +87,27 @@ struct
, platID: int , platID: int
} }
datatype bat_dir_y = UP | DOWN
type enemy =
{ id: int
, health: int
, x: int
, y: int
, xAxis: x_axis
, yAxis: y_axis
, variant: EnemyVariants.t
, platID: int
, nextPlatID: int
, batRest: int
, batDirY: bat_dir_y
, batMaxY: int
, batMinY: int
}
type falling_enemy = {x: int, y: int, variant: EnemyVariants.t}
type game_type = type game_type =
{ player: player { player: player
, walls: wall vector , walls: wall vector
, wallTree: QuadTree.t , wallTree: QuadTree.t
, platforms: platform vector , platforms: platform vector
, platformTree: QuadTree.t , platformTree: QuadTree.t
, enemies: enemy vector , enemies: EnemyType.enemy vector
, graph: PlatSet.elem vector vector , graph: PlatSet.elem vector vector
, fallingEnemies: falling_enemy vector , fallingEnemies: EnemyType.falling_enemy vector
} }
val initial: game_type = val initial: game_type =
let let
val player = val player =
{ yAxis = JUMPING 0 { yAxis = EntityType.JUMPING 0
, xAxis = STAY_STILL , xAxis = EntityType.STAY_STILL
, facing = EntityType.FACING_RIGHT
, recoil = NO_RECOIL , recoil = NO_RECOIL
, attacked = NOT_ATTACKED , attacked = NOT_ATTACKED
, mainAttack = MAIN_NOT_ATTACKING , mainAttack = MAIN_NOT_ATTACKING
, mainAttackPressed = false , mainAttackPressed = false
, facing = FACING_RIGHT
, health = 3 , health = 3
, x = 500 , x = 500
, y = 800 , y = 800
@@ -227,13 +165,13 @@ struct
, x = 751 , x = 751
, y = 555 , y = 555
, health = 1 , health = 1
, xAxis = MOVE_RIGHT , xAxis = EntityType.MOVE_RIGHT
, yAxis = FALLING , yAxis = EntityType.FALLING
, variant = EnemyVariants.STRAIGHT_BAT , variant = EnemyType.STRAIGHT_BAT
, batDirY = EnemyType.UP
, platID = ~1 , platID = ~1
, nextPlatID = ~1 , nextPlatID = ~1
, batRest = 0 , batRest = 0
, batDirY = UP
, batMaxY = 485 , batMaxY = 485
, batMinY = 625 , batMinY = 625
} }

View File

@@ -13,18 +13,19 @@ sig
(* destructuring functions *) (* destructuring functions *)
val getX: t -> int val getX: t -> int
val getY: t -> int val getY: t -> int
val getXAxis: t -> GameType.x_axis val getXAxis: t -> EntityType.x_axis
val getYAxis: t -> GameType.y_axis val getYAxis: t -> EntityType.y_axis
val W_X: int -> patch val W_X: int -> patch
val W_Y: int -> patch val W_Y: int -> patch
val W_Y_AXIS: GameType.y_axis -> patch val W_Y_AXIS: EntityType.y_axis -> patch
val W_PLAT_ID: int -> patch val W_PLAT_ID: int -> patch
end end
functor MakePhysics(Fn: PHYSICS_INPUT) = functor MakePhysics(Fn: PHYSICS_INPUT) =
struct struct
open GameType open GameType
open EntityType
fun getPhysicsPatches input = fun getPhysicsPatches input =
let let
@@ -245,7 +246,7 @@ structure PlayerPhysics =
structure EnemyPhysics = structure EnemyPhysics =
MakePhysics MakePhysics
(struct (struct
type t = GameType.enemy type t = EnemyType.enemy
type patch = EnemyPatch.enemy_patch type patch = EnemyPatch.enemy_patch
val entitySize = Constants.enemySize val entitySize = Constants.enemySize

View File

@@ -1,12 +1,12 @@
signature PLAYER_PATCH = signature PLAYER_PATCH =
sig sig
datatype player_patch = datatype player_patch =
W_X_AXIS of GameType.x_axis W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of GameType.y_axis | W_Y_AXIS of EntityType.y_axis
| W_FACING of EntityType.facing
| W_RECOIL of GameType.player_recoil | W_RECOIL of GameType.player_recoil
| W_ATTACKED of GameType.player_attacked | W_ATTACKED of GameType.player_attacked
| W_MAIN_ATTACK of GameType.main_attack | W_MAIN_ATTACK of GameType.main_attack
| W_FACING of GameType.facing
| W_HEALTH of int | W_HEALTH of int
| W_X of int | W_X of int
| W_Y of int | W_Y of int
@@ -24,12 +24,12 @@ end
structure PlayerPatch: PLAYER_PATCH = structure PlayerPatch: PLAYER_PATCH =
struct struct
datatype player_patch = datatype player_patch =
W_X_AXIS of GameType.x_axis W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of GameType.y_axis | W_Y_AXIS of EntityType.y_axis
| W_FACING of EntityType.facing
| W_RECOIL of GameType.player_recoil | W_RECOIL of GameType.player_recoil
| W_ATTACKED of GameType.player_attacked | W_ATTACKED of GameType.player_attacked
| W_MAIN_ATTACK of GameType.main_attack | W_MAIN_ATTACK of GameType.main_attack
| W_FACING of GameType.facing
| W_HEALTH of int | W_HEALTH of int
| W_X of int | W_X of int
| W_Y of int | W_Y of int

View File

@@ -2,6 +2,7 @@ structure Player =
struct struct
open GameType open GameType
open PlayerPatch open PlayerPatch
open EntityType
(* helper functions checking input *) (* helper functions checking input *)
fun getXAxis (lh, rh) = fun getXAxis (lh, rh) =
@@ -315,7 +316,7 @@ struct
structure FoldEnemies = structure FoldEnemies =
MakeQuadTreeFold MakeQuadTreeFold
(struct (struct
type env = enemy vector * player type env = EnemyType.enemy vector * player
type state = PlayerPatch.player_patch list type state = PlayerPatch.player_patch list
fun getEnemyRecoilPatches (player, playerOnRight, acc) = fun getEnemyRecoilPatches (player, playerOnRight, acc) =

View File

@@ -29,7 +29,7 @@ struct
orelse traceRightDescent (nextX, nextY, nextPlatID, platTree) orelse traceRightDescent (nextX, nextY, nextPlatID, platTree)
end end
fun traceRightDrop (enemy: GameType.enemy, nextPlatID, platTree) = fun traceRightDrop (enemy: EnemyType.enemy, nextPlatID, platTree) =
let let
val {x, y, ...} = enemy val {x, y, ...} = enemy
val x = x - Constants.enemySize val x = x - Constants.enemySize
@@ -59,12 +59,12 @@ struct
traceRightJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree) traceRightJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree)
end end
fun traceRightJump (enemy: GameType.enemy, nextPlatID, platTree) = fun traceRightJump (enemy: EnemyType.enemy, nextPlatID, platTree) =
let let
val {x, y, ...} = enemy val {x, y, ...} = enemy
val x = x - Constants.enemySize val x = x - Constants.enemySize
open GameType open EntityType
in in
if EnemyPhysics.standingOnArea (x, y, platTree) then if EnemyPhysics.standingOnArea (x, y, platTree) then
traceRightJumpAscent (x, y, 0, nextPlatID, platTree) traceRightJumpAscent (x, y, 0, nextPlatID, platTree)
@@ -94,7 +94,7 @@ struct
orelse traceLeftDescent (nextX, nextY, nextPlatID, platTree) orelse traceLeftDescent (nextX, nextY, nextPlatID, platTree)
end end
fun traceLeftDrop (enemy: GameType.enemy, nextPlatID, platTree) = fun traceLeftDrop (enemy: EnemyType.enemy, nextPlatID, platTree) =
let let
val {x, y, ...} = enemy val {x, y, ...} = enemy
val x = x + Constants.enemySize val x = x + Constants.enemySize
@@ -121,12 +121,12 @@ struct
traceLeftJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree) traceLeftJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree)
end end
fun traceLeftJump (enemy: GameType.enemy, nextPlatID, platTree) = fun traceLeftJump (enemy: EnemyType.enemy, nextPlatID, platTree) =
let let
val {x, y, ...} = enemy val {x, y, ...} = enemy
val x = x + 75 val x = x + 75
open GameType open EntityType
in in
if EnemyPhysics.standingOnArea (x, y, platTree) then if EnemyPhysics.standingOnArea (x, y, platTree) then
traceLeftJumpAscent (x, y, 0, nextPlatID, platTree) traceLeftJumpAscent (x, y, 0, nextPlatID, platTree)

View File

@@ -25,7 +25,8 @@ fcore/platform.sml
fcore/graph.sml fcore/graph.sml
fcore/path-finding.sml fcore/path-finding.sml
fcore/enemy/enemy-variants.sml fcore/entity-type.sml
fcore/enemy/enemy-type.sml
fcore/game-type.sml fcore/game-type.sml
fcore/player-patch.sml fcore/player-patch.sml

1
vendored/brolib-sml Submodule

Submodule vendored/brolib-sml added at d23396f5d1