additional refactoring, moving player type into its own directory

This commit is contained in:
2025-02-14 10:13:03 +00:00
parent d1e23b5455
commit 46a1836ae2
12 changed files with 88 additions and 114 deletions

View File

@@ -1,11 +1,10 @@
structure EnemyBehaviour =
struct
open GameType
open EnemyType
open EntityType
(* if player is attacking, does enemy collide with attack? *)
fun isCollidingWithPlayerAttack (player: player, enemy: enemy) =
fun isCollidingWithPlayerAttack (player: PlayerType.player, enemy: enemy) =
let
val {x = px, y = py, facing, mainAttack, ...} = player
val pSize = Constants.playerSize
@@ -14,7 +13,7 @@ struct
val eSize = Constants.enemySize
in
case mainAttack of
MAIN_ATTACKING {length, ...} =>
PlayerType.MAIN_ATTACKING {length, ...} =>
(case facing of
FACING_RIGHT =>
let
@@ -359,7 +358,14 @@ struct
end
fun getFollowPatches
(player: player, enemy, wallTree, platformTree, platforms, graph, acc) =
( player: PlayerType.player
, enemy
, wallTree
, platformTree
, platforms
, graph
, acc
) =
let
val pID = #platID player
val eID = #platID enemy

View File

@@ -1 +1 @@
structure EnemyMap = Enemy.EnemyMap
structure EnemyMap = MakeGapMap(EnemyPair)

View File

@@ -0,0 +1,11 @@
structure EnemyPair =
struct
type key = int
type value = EnemyType.enemy
fun l (a: int, b: int) = a < b
fun eq (a: int, b: int) = a = b
fun g (a: int, b: int) = a > b
val maxNodeSize = 8
end

View File

@@ -1,21 +1,6 @@
structure Enemy =
struct
structure EnemyPair =
struct
type key = int
type value = EnemyType.enemy
fun l (a: int, b: int) = a < b
fun eq (a: int, b: int) = a = b
fun g (a: int, b: int) = a > b
val maxNodeSize = 8
end
structure EnemyMap = MakeGapMap(EnemyPair)
(* - Updating state of enemies per-frame - *)
(* - Updating state of enemies per loop - *)
(*
structure UpdateEnemies = MakeGapMapMapper (struct
structure Pair = EnemyPair

View File

@@ -1,7 +1,6 @@
structure FallingEnemies =
struct
open EnemyType
open GameType
open EntityType
fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) =
@@ -25,12 +24,12 @@ struct
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
)
fun isCollidingWithPlayerAttack (player: GameType.player, fx, fy) =
fun isCollidingWithPlayerAttack (player: PlayerType.player, fx, fy) =
let
val {x = px, y = py, mainAttack, facing, ...} = player
in
case mainAttack of
MAIN_ATTACKING {length, ...} =>
PlayerType.MAIN_ATTACKING {length, ...} =>
let
val px =
(case facing of
@@ -46,7 +45,7 @@ struct
| _ => false
end
fun updateList (pos, vec, player: GameType.player, acc) =
fun updateList (pos, vec, player: PlayerType.player, acc) =
if pos < 0 then
acc
else
@@ -93,7 +92,7 @@ struct
(pos + 1, fallingVec, width, height, ratio, xOffset, yOffset, acc)
end
fun getDrawVec (game: game_type, width, height) =
fun getDrawVec (game: GameType.game_type, width, height) =
if Vector.length (#fallingEnemies game) = 0 then
Vector.fromList []
else

View File

@@ -1,38 +1,7 @@
signature GAME_TYPE =
sig
datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int
datatype player_attacked = NOT_ATTACKED | ATTACKED of int
datatype main_attack =
MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool}
| MAIN_THROWING
type defeated_enemies = {angle: int}
type player_projectile = {x: int, y: int, facing: EntityType.facing}
type player =
{ yAxis: EntityType.y_axis
, xAxis: EntityType.x_axis
, recoil: player_recoil
, attacked: player_attacked
, mainAttack: main_attack
, mainAttackPressed: bool
, facing: EntityType.facing
, health: int
, x: int
, y: int
, jumpPressed: bool
, enemies: defeated_enemies vector
, charge: int
, projectiles: player_projectile vector
, platID: int
}
type game_type =
{ player: player
{ player: PlayerType.player
, walls: Wall.t vector
, wallTree: QuadTree.t
, platforms: Platform.t vector
@@ -47,39 +16,8 @@ end
structure GameType :> GAME_TYPE =
struct
datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int
datatype player_attacked = NOT_ATTACKED | ATTACKED of int
datatype main_attack =
MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool}
| MAIN_THROWING
type defeated_enemies = {angle: int}
type player_projectile = {x: int, y: int, facing: EntityType.facing}
type player =
{ yAxis: EntityType.y_axis
, xAxis: EntityType.x_axis
, recoil: player_recoil
, attacked: player_attacked
, mainAttack: main_attack
, mainAttackPressed: bool
, facing: EntityType.facing
, health: int
, x: int
, y: int
, jumpPressed: bool
, enemies: defeated_enemies vector
, charge: int
, projectiles: player_projectile vector
, platID: int
}
type game_type =
{ player: player
{ player: PlayerType.player
, walls: Wall.t vector
, wallTree: QuadTree.t
, platforms: Platform.t vector
@@ -101,9 +39,9 @@ struct
{ yAxis = EntityType.JUMPING 0
, xAxis = EntityType.STAY_STILL
, facing = EntityType.FACING_RIGHT
, recoil = NO_RECOIL
, attacked = NOT_ATTACKED
, mainAttack = MAIN_NOT_ATTACKING
, recoil = PlayerType.NO_RECOIL
, attacked = PlayerType.NOT_ATTACKED
, mainAttack = PlayerType.MAIN_NOT_ATTACKING
, mainAttackPressed = false
, health = 3
, x = 500

View File

@@ -24,7 +24,6 @@ end
functor MakePhysics(Fn: PHYSICS_INPUT) =
struct
open GameType
open EntityType
fun getPhysicsPatches input =
@@ -220,7 +219,7 @@ end
structure PlayerPhysics =
MakePhysics
(struct
type t = GameType.player
type t = PlayerType.player
type patch = PlayerPatch.player_patch
val entitySize = Constants.playerSize

View File

@@ -4,21 +4,21 @@ sig
W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of EntityType.y_axis
| W_FACING of EntityType.facing
| W_RECOIL of GameType.player_recoil
| W_ATTACKED of GameType.player_attacked
| W_MAIN_ATTACK of GameType.main_attack
| W_RECOIL of PlayerType.player_recoil
| W_ATTACKED of PlayerType.player_attacked
| W_MAIN_ATTACK of PlayerType.main_attack
| W_HEALTH of int
| W_X of int
| W_Y of int
| W_JUMP_PRESSED of bool
| W_MAIN_ATTACK_PRESSED of bool
| W_ENEMIES of GameType.defeated_enemies vector
| W_ENEMIES of PlayerType.defeated_enemies vector
| W_CHARGE of int
| W_PROJECTILES of GameType.player_projectile vector
| W_PROJECTILES of PlayerType.player_projectile vector
| W_PLAT_ID of int
val withPatch: GameType.player * player_patch -> GameType.player
val withPatches: GameType.player * player_patch list -> GameType.player
val withPatch: PlayerType.player * player_patch -> PlayerType.player
val withPatches: PlayerType.player * player_patch list -> PlayerType.player
end
structure PlayerPatch: PLAYER_PATCH =
@@ -27,17 +27,17 @@ struct
W_X_AXIS of EntityType.x_axis
| W_Y_AXIS of EntityType.y_axis
| W_FACING of EntityType.facing
| W_RECOIL of GameType.player_recoil
| W_ATTACKED of GameType.player_attacked
| W_MAIN_ATTACK of GameType.main_attack
| W_RECOIL of PlayerType.player_recoil
| W_ATTACKED of PlayerType.player_attacked
| W_MAIN_ATTACK of PlayerType.main_attack
| W_HEALTH of int
| W_X of int
| W_Y of int
| W_JUMP_PRESSED of bool
| W_MAIN_ATTACK_PRESSED of bool
| W_ENEMIES of GameType.defeated_enemies vector
| W_ENEMIES of PlayerType.defeated_enemies vector
| W_CHARGE of int
| W_PROJECTILES of GameType.player_projectile vector
| W_PROJECTILES of PlayerType.player_projectile vector
| W_PLAT_ID of int
fun mkPlayer
@@ -367,7 +367,7 @@ struct
)
end
fun withPatches (player: GameType.player, lst) =
fun withPatches (player: PlayerType.player, lst) =
case lst of
hd :: tl =>
let val player = withPatch (player, hd)

View File

@@ -0,0 +1,33 @@
structure PlayerType =
struct
datatype player_recoil = NO_RECOIL | RECOIL_LEFT of int | RECOIL_RIGHT of int
datatype player_attacked = NOT_ATTACKED | ATTACKED of int
datatype main_attack =
MAIN_NOT_ATTACKING
| MAIN_ATTACKING of {length: int, growing: bool}
| MAIN_THROWING
type defeated_enemies = {angle: int}
type player_projectile = {x: int, y: int, facing: EntityType.facing}
type player =
{ yAxis: EntityType.y_axis
, xAxis: EntityType.x_axis
, recoil: player_recoil
, attacked: player_attacked
, mainAttack: main_attack
, mainAttackPressed: bool
, facing: EntityType.facing
, health: int
, x: int
, y: int
, jumpPressed: bool
, enemies: defeated_enemies vector
, charge: int
, projectiles: player_projectile vector
, platID: int
}
end

View File

@@ -1,8 +1,8 @@
structure Player =
struct
open GameType
open PlayerPatch
open EntityType
open PlayerType
(* helper functions checking input *)
fun getXAxis (lh, rh) =
@@ -378,7 +378,7 @@ struct
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
end)
fun runPhysicsAndInput (game: game_type, input, enemyTree) =
fun runPhysicsAndInput (game: GameType.game_type, input, enemyTree) =
let
val player = #player game

View File

@@ -44,7 +44,7 @@ struct
(pos + 1, projectiles, width, height, ratio, xOffset, yOffset, acc)
end
fun getProjectileVec (player: GameType.player, width, height) =
fun getProjectileVec (player: PlayerType.player, width, height) =
let
val {projectiles, ...} = player