additional refactoring, moving player type into its own directory
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
structure EnemyBehaviour =
|
structure EnemyBehaviour =
|
||||||
struct
|
struct
|
||||||
open GameType
|
|
||||||
open EnemyType
|
open EnemyType
|
||||||
open EntityType
|
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: PlayerType.player, enemy: enemy) =
|
||||||
let
|
let
|
||||||
val {x = px, y = py, facing, mainAttack, ...} = player
|
val {x = px, y = py, facing, mainAttack, ...} = player
|
||||||
val pSize = Constants.playerSize
|
val pSize = Constants.playerSize
|
||||||
@@ -14,7 +13,7 @@ struct
|
|||||||
val eSize = Constants.enemySize
|
val eSize = Constants.enemySize
|
||||||
in
|
in
|
||||||
case mainAttack of
|
case mainAttack of
|
||||||
MAIN_ATTACKING {length, ...} =>
|
PlayerType.MAIN_ATTACKING {length, ...} =>
|
||||||
(case facing of
|
(case facing of
|
||||||
FACING_RIGHT =>
|
FACING_RIGHT =>
|
||||||
let
|
let
|
||||||
@@ -359,7 +358,14 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun getFollowPatches
|
fun getFollowPatches
|
||||||
(player: player, enemy, wallTree, platformTree, platforms, graph, acc) =
|
( player: PlayerType.player
|
||||||
|
, enemy
|
||||||
|
, wallTree
|
||||||
|
, platformTree
|
||||||
|
, platforms
|
||||||
|
, graph
|
||||||
|
, acc
|
||||||
|
) =
|
||||||
let
|
let
|
||||||
val pID = #platID player
|
val pID = #platID player
|
||||||
val eID = #platID enemy
|
val eID = #platID enemy
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
structure EnemyMap = Enemy.EnemyMap
|
structure EnemyMap = MakeGapMap(EnemyPair)
|
||||||
|
|||||||
11
fcore/enemy/enemy-pair.sml
Normal file
11
fcore/enemy/enemy-pair.sml
Normal 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
|
||||||
@@ -1,21 +1,6 @@
|
|||||||
structure Enemy =
|
structure Enemy =
|
||||||
struct
|
struct
|
||||||
|
(* - Updating state of enemies per loop - *)
|
||||||
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 - *)
|
|
||||||
(*
|
(*
|
||||||
structure UpdateEnemies = MakeGapMapMapper (struct
|
structure UpdateEnemies = MakeGapMapMapper (struct
|
||||||
structure Pair = EnemyPair
|
structure Pair = EnemyPair
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
structure FallingEnemies =
|
structure FallingEnemies =
|
||||||
struct
|
struct
|
||||||
open EnemyType
|
open EnemyType
|
||||||
open GameType
|
|
||||||
open EntityType
|
open EntityType
|
||||||
|
|
||||||
fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) =
|
fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) =
|
||||||
@@ -25,12 +24,12 @@ struct
|
|||||||
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
|
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun isCollidingWithPlayerAttack (player: GameType.player, fx, fy) =
|
fun isCollidingWithPlayerAttack (player: PlayerType.player, fx, fy) =
|
||||||
let
|
let
|
||||||
val {x = px, y = py, mainAttack, facing, ...} = player
|
val {x = px, y = py, mainAttack, facing, ...} = player
|
||||||
in
|
in
|
||||||
case mainAttack of
|
case mainAttack of
|
||||||
MAIN_ATTACKING {length, ...} =>
|
PlayerType.MAIN_ATTACKING {length, ...} =>
|
||||||
let
|
let
|
||||||
val px =
|
val px =
|
||||||
(case facing of
|
(case facing of
|
||||||
@@ -46,7 +45,7 @@ struct
|
|||||||
| _ => false
|
| _ => false
|
||||||
end
|
end
|
||||||
|
|
||||||
fun updateList (pos, vec, player: GameType.player, acc) =
|
fun updateList (pos, vec, player: PlayerType.player, acc) =
|
||||||
if pos < 0 then
|
if pos < 0 then
|
||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
@@ -93,7 +92,7 @@ struct
|
|||||||
(pos + 1, fallingVec, width, height, ratio, xOffset, yOffset, acc)
|
(pos + 1, fallingVec, width, height, ratio, xOffset, yOffset, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getDrawVec (game: game_type, width, height) =
|
fun getDrawVec (game: GameType.game_type, width, height) =
|
||||||
if Vector.length (#fallingEnemies game) = 0 then
|
if Vector.length (#fallingEnemies game) = 0 then
|
||||||
Vector.fromList []
|
Vector.fromList []
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,38 +1,7 @@
|
|||||||
signature GAME_TYPE =
|
signature GAME_TYPE =
|
||||||
sig
|
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 =
|
type game_type =
|
||||||
{ player: player
|
{ player: PlayerType.player
|
||||||
, walls: Wall.t vector
|
, walls: Wall.t vector
|
||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: Platform.t vector
|
, platforms: Platform.t vector
|
||||||
@@ -47,39 +16,8 @@ end
|
|||||||
|
|
||||||
structure GameType :> GAME_TYPE =
|
structure GameType :> GAME_TYPE =
|
||||||
struct
|
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 =
|
type game_type =
|
||||||
{ player: player
|
{ player: PlayerType.player
|
||||||
, walls: Wall.t vector
|
, walls: Wall.t vector
|
||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: Platform.t vector
|
, platforms: Platform.t vector
|
||||||
@@ -101,9 +39,9 @@ struct
|
|||||||
{ yAxis = EntityType.JUMPING 0
|
{ yAxis = EntityType.JUMPING 0
|
||||||
, xAxis = EntityType.STAY_STILL
|
, xAxis = EntityType.STAY_STILL
|
||||||
, facing = EntityType.FACING_RIGHT
|
, facing = EntityType.FACING_RIGHT
|
||||||
, recoil = NO_RECOIL
|
, recoil = PlayerType.NO_RECOIL
|
||||||
, attacked = NOT_ATTACKED
|
, attacked = PlayerType.NOT_ATTACKED
|
||||||
, mainAttack = MAIN_NOT_ATTACKING
|
, mainAttack = PlayerType.MAIN_NOT_ATTACKING
|
||||||
, mainAttackPressed = false
|
, mainAttackPressed = false
|
||||||
, health = 3
|
, health = 3
|
||||||
, x = 500
|
, x = 500
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ end
|
|||||||
|
|
||||||
functor MakePhysics(Fn: PHYSICS_INPUT) =
|
functor MakePhysics(Fn: PHYSICS_INPUT) =
|
||||||
struct
|
struct
|
||||||
open GameType
|
|
||||||
open EntityType
|
open EntityType
|
||||||
|
|
||||||
fun getPhysicsPatches input =
|
fun getPhysicsPatches input =
|
||||||
@@ -220,7 +219,7 @@ end
|
|||||||
structure PlayerPhysics =
|
structure PlayerPhysics =
|
||||||
MakePhysics
|
MakePhysics
|
||||||
(struct
|
(struct
|
||||||
type t = GameType.player
|
type t = PlayerType.player
|
||||||
type patch = PlayerPatch.player_patch
|
type patch = PlayerPatch.player_patch
|
||||||
|
|
||||||
val entitySize = Constants.playerSize
|
val entitySize = Constants.playerSize
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ sig
|
|||||||
W_X_AXIS of EntityType.x_axis
|
W_X_AXIS of EntityType.x_axis
|
||||||
| W_Y_AXIS of EntityType.y_axis
|
| W_Y_AXIS of EntityType.y_axis
|
||||||
| W_FACING of EntityType.facing
|
| W_FACING of EntityType.facing
|
||||||
| W_RECOIL of GameType.player_recoil
|
| W_RECOIL of PlayerType.player_recoil
|
||||||
| W_ATTACKED of GameType.player_attacked
|
| W_ATTACKED of PlayerType.player_attacked
|
||||||
| W_MAIN_ATTACK of GameType.main_attack
|
| W_MAIN_ATTACK of PlayerType.main_attack
|
||||||
| 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_JUMP_PRESSED of bool
|
| W_JUMP_PRESSED of bool
|
||||||
| W_MAIN_ATTACK_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_CHARGE of int
|
||||||
| W_PROJECTILES of GameType.player_projectile vector
|
| W_PROJECTILES of PlayerType.player_projectile vector
|
||||||
| W_PLAT_ID of int
|
| W_PLAT_ID of int
|
||||||
|
|
||||||
val withPatch: GameType.player * player_patch -> GameType.player
|
val withPatch: PlayerType.player * player_patch -> PlayerType.player
|
||||||
val withPatches: GameType.player * player_patch list -> GameType.player
|
val withPatches: PlayerType.player * player_patch list -> PlayerType.player
|
||||||
end
|
end
|
||||||
|
|
||||||
structure PlayerPatch: PLAYER_PATCH =
|
structure PlayerPatch: PLAYER_PATCH =
|
||||||
@@ -27,17 +27,17 @@ struct
|
|||||||
W_X_AXIS of EntityType.x_axis
|
W_X_AXIS of EntityType.x_axis
|
||||||
| W_Y_AXIS of EntityType.y_axis
|
| W_Y_AXIS of EntityType.y_axis
|
||||||
| W_FACING of EntityType.facing
|
| W_FACING of EntityType.facing
|
||||||
| W_RECOIL of GameType.player_recoil
|
| W_RECOIL of PlayerType.player_recoil
|
||||||
| W_ATTACKED of GameType.player_attacked
|
| W_ATTACKED of PlayerType.player_attacked
|
||||||
| W_MAIN_ATTACK of GameType.main_attack
|
| W_MAIN_ATTACK of PlayerType.main_attack
|
||||||
| 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_JUMP_PRESSED of bool
|
| W_JUMP_PRESSED of bool
|
||||||
| W_MAIN_ATTACK_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_CHARGE of int
|
||||||
| W_PROJECTILES of GameType.player_projectile vector
|
| W_PROJECTILES of PlayerType.player_projectile vector
|
||||||
| W_PLAT_ID of int
|
| W_PLAT_ID of int
|
||||||
|
|
||||||
fun mkPlayer
|
fun mkPlayer
|
||||||
@@ -367,7 +367,7 @@ struct
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun withPatches (player: GameType.player, lst) =
|
fun withPatches (player: PlayerType.player, lst) =
|
||||||
case lst of
|
case lst of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
let val player = withPatch (player, hd)
|
let val player = withPatch (player, hd)
|
||||||
33
fcore/player/player-type.sml
Normal file
33
fcore/player/player-type.sml
Normal 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
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
structure Player =
|
structure Player =
|
||||||
struct
|
struct
|
||||||
open GameType
|
|
||||||
open PlayerPatch
|
open PlayerPatch
|
||||||
open EntityType
|
open EntityType
|
||||||
|
open PlayerType
|
||||||
|
|
||||||
(* helper functions checking input *)
|
(* helper functions checking input *)
|
||||||
fun getXAxis (lh, rh) =
|
fun getXAxis (lh, rh) =
|
||||||
@@ -378,7 +378,7 @@ struct
|
|||||||
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
||||||
end)
|
end)
|
||||||
|
|
||||||
fun runPhysicsAndInput (game: game_type, input, enemyTree) =
|
fun runPhysicsAndInput (game: GameType.game_type, input, enemyTree) =
|
||||||
let
|
let
|
||||||
val player = #player game
|
val player = #player game
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ struct
|
|||||||
(pos + 1, projectiles, width, height, ratio, xOffset, yOffset, acc)
|
(pos + 1, projectiles, width, height, ratio, xOffset, yOffset, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getProjectileVec (player: GameType.player, width, height) =
|
fun getProjectileVec (player: PlayerType.player, width, height) =
|
||||||
let
|
let
|
||||||
val {projectiles, ...} = player
|
val {projectiles, ...} = player
|
||||||
|
|
||||||
|
|||||||
9
oms.mlb
9
oms.mlb
@@ -29,18 +29,21 @@ fcore/path-finding.sml
|
|||||||
|
|
||||||
fcore/entity-type.sml
|
fcore/entity-type.sml
|
||||||
fcore/enemy/enemy-type.sml
|
fcore/enemy/enemy-type.sml
|
||||||
fcore/enemy/enemy.sml
|
fcore/enemy/enemy-pair.sml
|
||||||
fcore/enemy/enemy-map.sml
|
fcore/enemy/enemy-map.sml
|
||||||
|
|
||||||
|
fcore/player/player-type.sml
|
||||||
|
fcore/enemy/enemy.sml
|
||||||
fcore/game-type.sml
|
fcore/game-type.sml
|
||||||
|
|
||||||
fcore/player-patch.sml
|
fcore/player/player-patch.sml
|
||||||
fcore/enemy/enemy-patch.sml
|
fcore/enemy/enemy-patch.sml
|
||||||
fcore/physics.sml
|
fcore/physics.sml
|
||||||
|
|
||||||
fcore/trace-jump.sml
|
fcore/trace-jump.sml
|
||||||
fcore/enemy/enemy-behaviour.sml
|
fcore/enemy/enemy-behaviour.sml
|
||||||
fcore/enemy/falling-enemies.sml
|
fcore/enemy/falling-enemies.sml
|
||||||
fcore/player.sml
|
fcore/player/player.sml
|
||||||
fcore/projectile.sml
|
fcore/projectile.sml
|
||||||
|
|
||||||
fcore/game-update.sml
|
fcore/game-update.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user