refactor file order in preparation for adding GapMap for enemy
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "vendored/brolib-sml"]
|
||||
path = vendored/brolib-sml
|
||||
url = https://github.com/hummy123/brolib-sml
|
||||
@@ -1,6 +1,9 @@
|
||||
structure EnemyBehaviour =
|
||||
struct
|
||||
open GameType
|
||||
open EnemyType
|
||||
open EntityType
|
||||
|
||||
(* if player is attacking, does enemy collide with attack? *)
|
||||
fun isCollidingWithPlayerAttack (player: player, enemy: enemy) =
|
||||
let
|
||||
@@ -569,44 +572,40 @@ struct
|
||||
, enemyList
|
||||
, fallingList
|
||||
) =
|
||||
let
|
||||
open EnemyVariants
|
||||
in
|
||||
case #variant enemy of
|
||||
PATROL_SLIME =>
|
||||
updatePatrolState
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, projectileTree
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
| FOLLOW_SLIME =>
|
||||
updateFollowState
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, projectileTree
|
||||
, graph
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
| STRAIGHT_BAT =>
|
||||
updateStraightBat
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, projectileTree
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
end
|
||||
case #variant enemy of
|
||||
PATROL_SLIME =>
|
||||
updatePatrolState
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, projectileTree
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
| FOLLOW_SLIME =>
|
||||
updateFollowState
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, projectileTree
|
||||
, graph
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
| STRAIGHT_BAT =>
|
||||
updateStraightBat
|
||||
( player
|
||||
, enemy
|
||||
, walls
|
||||
, wallTree
|
||||
, projectileTree
|
||||
, enemyList
|
||||
, fallingList
|
||||
)
|
||||
end
|
||||
|
||||
@@ -4,18 +4,18 @@ sig
|
||||
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
|
||||
| W_X_AXIS of EntityType.x_axis
|
||||
| W_Y_AXIS of EntityType.y_axis
|
||||
| W_PLAT_ID of int
|
||||
| W_NEXT_PLAT_ID of int
|
||||
| W_BAT_REST of int
|
||||
| W_BAT_MAX_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
|
||||
|
||||
structure EnemyPatch: ENEMY_PATCH =
|
||||
@@ -24,14 +24,14 @@ struct
|
||||
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
|
||||
| W_X_AXIS of EntityType.x_axis
|
||||
| W_Y_AXIS of EntityType.y_axis
|
||||
| W_PLAT_ID of int
|
||||
| W_NEXT_PLAT_ID of int
|
||||
| W_BAT_REST of int
|
||||
| W_BAT_MAX_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
|
||||
( id
|
||||
|
||||
49
fcore/enemy/enemy-type.sml
Normal file
49
fcore/enemy/enemy-type.sml
Normal 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
|
||||
@@ -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
|
||||
@@ -1,6 +1,6 @@
|
||||
structure Enemy =
|
||||
struct
|
||||
open GameType
|
||||
open EnemyType
|
||||
|
||||
(* returns a vector of enemies, with new state (like position, etc.).
|
||||
* Also filters any enemies from list if defeated.
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
structure FallingEnemies =
|
||||
struct
|
||||
open EnemyType
|
||||
open GameType
|
||||
open EntityType
|
||||
|
||||
fun helpGenerateTree (pos, fallingVec: falling_enemy vector, acc) =
|
||||
if pos = Vector.length fallingVec then
|
||||
@@ -23,7 +25,7 @@ struct
|
||||
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
|
||||
)
|
||||
|
||||
fun isCollidingWithPlayerAttack (player: player, fx, fy) =
|
||||
fun isCollidingWithPlayerAttack (player: GameType.player, fx, fy) =
|
||||
let
|
||||
val {x = px, y = py, mainAttack, facing, ...} = player
|
||||
in
|
||||
@@ -44,7 +46,7 @@ struct
|
||||
| _ => false
|
||||
end
|
||||
|
||||
fun updateList (pos, vec, player: player, acc) =
|
||||
fun updateList (pos, vec, player: GameType.player, acc) =
|
||||
if pos < 0 then
|
||||
acc
|
||||
else
|
||||
@@ -55,7 +57,7 @@ struct
|
||||
val ww = Constants.worldWidth
|
||||
val wh = Constants.worldHeight
|
||||
in
|
||||
if isCollidingWithPlayerAttack (player : player, x, y) then
|
||||
if isCollidingWithPlayerAttack (player, x, y) then
|
||||
(* filter out if player is attacking falling enemy *)
|
||||
updateList (pos - 1, vec, player, acc)
|
||||
else if Collision.isCollidingPlus (x, y, size, size, 0, 0, ww, wh) then
|
||||
|
||||
27
fcore/entity-type.sml
Normal file
27
fcore/entity-type.sml
Normal 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
|
||||
@@ -4,21 +4,10 @@ sig
|
||||
|
||||
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_attacked = NOT_ATTACKED | ATTACKED of int
|
||||
|
||||
datatype facing = FACING_LEFT | FACING_RIGHT
|
||||
|
||||
datatype main_attack =
|
||||
MAIN_NOT_ATTACKING
|
||||
| MAIN_ATTACKING of {length: int, growing: bool}
|
||||
@@ -26,16 +15,16 @@ sig
|
||||
|
||||
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 =
|
||||
{ yAxis: y_axis
|
||||
, xAxis: x_axis
|
||||
{ yAxis: EntityType.y_axis
|
||||
, xAxis: EntityType.x_axis
|
||||
, recoil: player_recoil
|
||||
, attacked: player_attacked
|
||||
, mainAttack: main_attack
|
||||
, mainAttackPressed: bool
|
||||
, facing: facing
|
||||
, facing: EntityType.facing
|
||||
, health: int
|
||||
, x: int
|
||||
, y: int
|
||||
@@ -46,35 +35,15 @@ sig
|
||||
, 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 =
|
||||
{ player: player
|
||||
, walls: wall vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: platform vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: enemy vector
|
||||
, enemies: EnemyType.enemy vector
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: falling_enemy vector
|
||||
, fallingEnemies: EnemyType.falling_enemy vector
|
||||
}
|
||||
|
||||
val initial: game_type
|
||||
@@ -87,21 +56,10 @@ struct
|
||||
(* all platforms have a fixed visual height and a fixed collision height *)
|
||||
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_attacked = NOT_ATTACKED | ATTACKED of int
|
||||
|
||||
datatype facing = FACING_LEFT | FACING_RIGHT
|
||||
|
||||
datatype main_attack =
|
||||
MAIN_NOT_ATTACKING
|
||||
| MAIN_ATTACKING of {length: int, growing: bool}
|
||||
@@ -109,16 +67,16 @@ struct
|
||||
|
||||
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 =
|
||||
{ yAxis: y_axis
|
||||
, xAxis: x_axis
|
||||
{ yAxis: EntityType.y_axis
|
||||
, xAxis: EntityType.x_axis
|
||||
, recoil: player_recoil
|
||||
, attacked: player_attacked
|
||||
, mainAttack: main_attack
|
||||
, mainAttackPressed: bool
|
||||
, facing: facing
|
||||
, facing: EntityType.facing
|
||||
, health: int
|
||||
, x: int
|
||||
, y: int
|
||||
@@ -129,47 +87,27 @@ struct
|
||||
, 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 =
|
||||
{ player: player
|
||||
, walls: wall vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: platform vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: enemy vector
|
||||
, enemies: EnemyType.enemy vector
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: falling_enemy vector
|
||||
, fallingEnemies: EnemyType.falling_enemy vector
|
||||
}
|
||||
|
||||
val initial: game_type =
|
||||
let
|
||||
val player =
|
||||
{ yAxis = JUMPING 0
|
||||
, xAxis = STAY_STILL
|
||||
{ yAxis = EntityType.JUMPING 0
|
||||
, xAxis = EntityType.STAY_STILL
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, recoil = NO_RECOIL
|
||||
, attacked = NOT_ATTACKED
|
||||
, mainAttack = MAIN_NOT_ATTACKING
|
||||
, mainAttackPressed = false
|
||||
, facing = FACING_RIGHT
|
||||
, health = 3
|
||||
, x = 500
|
||||
, y = 800
|
||||
@@ -227,13 +165,13 @@ struct
|
||||
, x = 751
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = MOVE_RIGHT
|
||||
, yAxis = FALLING
|
||||
, variant = EnemyVariants.STRAIGHT_BAT
|
||||
, xAxis = EntityType.MOVE_RIGHT
|
||||
, yAxis = EntityType.FALLING
|
||||
, variant = EnemyType.STRAIGHT_BAT
|
||||
, batDirY = EnemyType.UP
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
, batDirY = UP
|
||||
, batMaxY = 485
|
||||
, batMinY = 625
|
||||
}
|
||||
|
||||
@@ -13,18 +13,19 @@ sig
|
||||
(* destructuring functions *)
|
||||
val getX: t -> int
|
||||
val getY: t -> int
|
||||
val getXAxis: t -> GameType.x_axis
|
||||
val getYAxis: t -> GameType.y_axis
|
||||
val getXAxis: t -> EntityType.x_axis
|
||||
val getYAxis: t -> EntityType.y_axis
|
||||
|
||||
val W_X: 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
|
||||
end
|
||||
|
||||
functor MakePhysics(Fn: PHYSICS_INPUT) =
|
||||
struct
|
||||
open GameType
|
||||
open EntityType
|
||||
|
||||
fun getPhysicsPatches input =
|
||||
let
|
||||
@@ -245,7 +246,7 @@ structure PlayerPhysics =
|
||||
structure EnemyPhysics =
|
||||
MakePhysics
|
||||
(struct
|
||||
type t = GameType.enemy
|
||||
type t = EnemyType.enemy
|
||||
type patch = EnemyPatch.enemy_patch
|
||||
|
||||
val entitySize = Constants.enemySize
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
signature PLAYER_PATCH =
|
||||
sig
|
||||
datatype player_patch =
|
||||
W_X_AXIS of GameType.x_axis
|
||||
| W_Y_AXIS of GameType.y_axis
|
||||
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_FACING of GameType.facing
|
||||
| W_HEALTH of int
|
||||
| W_X of int
|
||||
| W_Y of int
|
||||
@@ -24,12 +24,12 @@ end
|
||||
structure PlayerPatch: PLAYER_PATCH =
|
||||
struct
|
||||
datatype player_patch =
|
||||
W_X_AXIS of GameType.x_axis
|
||||
| W_Y_AXIS of GameType.y_axis
|
||||
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_FACING of GameType.facing
|
||||
| W_HEALTH of int
|
||||
| W_X of int
|
||||
| W_Y of int
|
||||
|
||||
@@ -2,6 +2,7 @@ structure Player =
|
||||
struct
|
||||
open GameType
|
||||
open PlayerPatch
|
||||
open EntityType
|
||||
|
||||
(* helper functions checking input *)
|
||||
fun getXAxis (lh, rh) =
|
||||
@@ -315,7 +316,7 @@ struct
|
||||
structure FoldEnemies =
|
||||
MakeQuadTreeFold
|
||||
(struct
|
||||
type env = enemy vector * player
|
||||
type env = EnemyType.enemy vector * player
|
||||
type state = PlayerPatch.player_patch list
|
||||
|
||||
fun getEnemyRecoilPatches (player, playerOnRight, acc) =
|
||||
|
||||
@@ -29,7 +29,7 @@ struct
|
||||
orelse traceRightDescent (nextX, nextY, nextPlatID, platTree)
|
||||
end
|
||||
|
||||
fun traceRightDrop (enemy: GameType.enemy, nextPlatID, platTree) =
|
||||
fun traceRightDrop (enemy: EnemyType.enemy, nextPlatID, platTree) =
|
||||
let
|
||||
val {x, y, ...} = enemy
|
||||
val x = x - Constants.enemySize
|
||||
@@ -59,12 +59,12 @@ struct
|
||||
traceRightJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree)
|
||||
end
|
||||
|
||||
fun traceRightJump (enemy: GameType.enemy, nextPlatID, platTree) =
|
||||
fun traceRightJump (enemy: EnemyType.enemy, nextPlatID, platTree) =
|
||||
let
|
||||
val {x, y, ...} = enemy
|
||||
val x = x - Constants.enemySize
|
||||
|
||||
open GameType
|
||||
open EntityType
|
||||
in
|
||||
if EnemyPhysics.standingOnArea (x, y, platTree) then
|
||||
traceRightJumpAscent (x, y, 0, nextPlatID, platTree)
|
||||
@@ -94,7 +94,7 @@ struct
|
||||
orelse traceLeftDescent (nextX, nextY, nextPlatID, platTree)
|
||||
end
|
||||
|
||||
fun traceLeftDrop (enemy: GameType.enemy, nextPlatID, platTree) =
|
||||
fun traceLeftDrop (enemy: EnemyType.enemy, nextPlatID, platTree) =
|
||||
let
|
||||
val {x, y, ...} = enemy
|
||||
val x = x + Constants.enemySize
|
||||
@@ -121,12 +121,12 @@ struct
|
||||
traceLeftJumpAscent (nextX, nextY, nextJump, nextPlatID, platTree)
|
||||
end
|
||||
|
||||
fun traceLeftJump (enemy: GameType.enemy, nextPlatID, platTree) =
|
||||
fun traceLeftJump (enemy: EnemyType.enemy, nextPlatID, platTree) =
|
||||
let
|
||||
val {x, y, ...} = enemy
|
||||
val x = x + 75
|
||||
|
||||
open GameType
|
||||
open EntityType
|
||||
in
|
||||
if EnemyPhysics.standingOnArea (x, y, platTree) then
|
||||
traceLeftJumpAscent (x, y, 0, nextPlatID, platTree)
|
||||
|
||||
3
oms.mlb
3
oms.mlb
@@ -25,7 +25,8 @@ fcore/platform.sml
|
||||
fcore/graph.sml
|
||||
fcore/path-finding.sml
|
||||
|
||||
fcore/enemy/enemy-variants.sml
|
||||
fcore/entity-type.sml
|
||||
fcore/enemy/enemy-type.sml
|
||||
fcore/game-type.sml
|
||||
|
||||
fcore/player-patch.sml
|
||||
|
||||
1
vendored/brolib-sml
Submodule
1
vendored/brolib-sml
Submodule
Submodule vendored/brolib-sml added at d23396f5d1
Reference in New Issue
Block a user