begin parameterising level so that it fits into larger type (with different modes like TITLE, LEVEL, SETTINGS, etc.)
This commit is contained in:
@@ -1,148 +1,16 @@
|
||||
signature GAME_TYPE =
|
||||
sig
|
||||
type game_type =
|
||||
{ player: PlayerType.player
|
||||
, walls: Wall.t vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: Platform.t vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: EnemyMap.t
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: FallingEnemyMap.t
|
||||
, userKeys: CoreKey.user_key
|
||||
}
|
||||
|
||||
val initial: CoreKey.user_key -> game_type
|
||||
datatype mode =
|
||||
LEVEL of LevelType.level_type
|
||||
end
|
||||
|
||||
structure GameType :> GAME_TYPE =
|
||||
struct
|
||||
type game_type =
|
||||
{ player: PlayerType.player
|
||||
, walls: Wall.t vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: Platform.t vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: EnemyMap.t
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: FallingEnemyMap.t
|
||||
, userKeys: CoreKey.user_key
|
||||
}
|
||||
datatype mode =
|
||||
LEVEL of LevelType.level_type
|
||||
|
||||
fun enemyMapFromList (hd :: tl, map) =
|
||||
let val map = EnemyMap.add (#id hd, hd, map)
|
||||
in enemyMapFromList (tl, map)
|
||||
end
|
||||
| enemyMapFromList ([], map) = map
|
||||
|
||||
fun initial userKeys =
|
||||
let
|
||||
val player =
|
||||
{ yAxis = EntityType.JUMPING 0
|
||||
, xAxis = EntityType.STAY_STILL
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, recoil = PlayerType.NO_RECOIL
|
||||
, attacked = PlayerType.NOT_ATTACKED
|
||||
, mainAttack = PlayerType.MAIN_NOT_ATTACKING
|
||||
, mainAttackPressed = false
|
||||
, health = 3
|
||||
, x = 500
|
||||
, y = 800
|
||||
, jumpPressed = false
|
||||
, enemies = Vector.fromList []
|
||||
, charge = Constants.maxCharge
|
||||
, projectiles = Vector.fromList []
|
||||
, platID = ~1
|
||||
}
|
||||
|
||||
val wall1 = {id = 1, x = 0, y = 0, width = 100, height = 1080}
|
||||
val wall2 = {id = 2, x = 1820, y = 0, width = 100, height = 1080}
|
||||
val wall3 = {id = 3, x = 0, y = 980, width = 1920, height = 108}
|
||||
val walls = Vector.fromList [wall1, wall2, wall3]
|
||||
val wallTree = Wall.generateTree walls
|
||||
|
||||
val plat1 = {id = 1, x = 255, y = 855, width = 199}
|
||||
val plat2 = {id = 2, x = 750, y = 855, width = 199}
|
||||
val plat3 = {id = 3, x = 399, y = 755, width = 399}
|
||||
val plat4 = {id = 4, x = 255, y = 655, width = 199}
|
||||
val plat5 = {id = 5, x = 750, y = 655, width = 199}
|
||||
val plat6 = {id = 6, x = 171, y = 555, width = 99}
|
||||
val plat7 = {id = 7, x = 934, y = 555, width = 99}
|
||||
val plat8 = {id = 8, x = 399, y = 555, width = 399}
|
||||
val plat9 = {id = 9, x = 255, y = 455, width = 199}
|
||||
val plat10 = {id = 10, x = 750, y = 455, width = 199}
|
||||
val plat11 = {id = 11, x = 399, y = 355, width = 399}
|
||||
val plat12 = {id = 12, x = 255, y = 255, width = 199}
|
||||
val plat13 = {id = 13, x = 750, y = 255, width = 199}
|
||||
val plat14 = {id = 14, x = 399, y = 155, width = 399}
|
||||
val plat15 = {id = 15, x = 171, y = 155, width = 99}
|
||||
val plat16 = {id = 16, x = 934, y = 155, width = 99}
|
||||
val platforms = Vector.fromList
|
||||
[ plat1
|
||||
, plat2
|
||||
, plat3
|
||||
, plat4
|
||||
, plat5
|
||||
, plat6
|
||||
, plat7
|
||||
, plat8
|
||||
, plat9
|
||||
, plat10
|
||||
, plat11
|
||||
, plat12
|
||||
, plat13
|
||||
, plat14
|
||||
, plat15
|
||||
, plat16
|
||||
]
|
||||
val platformTree = Platform.generateTree platforms
|
||||
|
||||
val enemy1 =
|
||||
{ id = 1
|
||||
, x = 751
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = EntityType.MOVE_RIGHT
|
||||
, yAxis = EntityType.FALLING
|
||||
, variant = EnemyType.FOLLOW_SLIME
|
||||
, batDirY = EnemyType.UP
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
, batMaxY = 485
|
||||
, batMinY = 625
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, shieldOn = false
|
||||
}
|
||||
val enemy2 =
|
||||
{ id = 2
|
||||
, x = 351
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = EntityType.MOVE_RIGHT
|
||||
, yAxis = EntityType.FALLING
|
||||
, variant = EnemyType.SHIELD_SLIME
|
||||
, batDirY = EnemyType.UP
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
, batMaxY = 485
|
||||
, batMinY = 625
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, shieldOn = false
|
||||
}
|
||||
val enemies = enemyMapFromList ([enemy1, enemy2], EnemyMap.empty)
|
||||
val graph = Graph.fromPlatforms (platforms, platformTree)
|
||||
in
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = FallingEnemyMap.empty
|
||||
, userKeys = userKeys
|
||||
}
|
||||
end
|
||||
type game_type = {
|
||||
userKeys: CoreKey.user_key,
|
||||
mode: mode
|
||||
}
|
||||
end
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
structure GameUpdate =
|
||||
struct
|
||||
fun update (game, input) =
|
||||
let
|
||||
val
|
||||
{ player
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, enemies
|
||||
, graph
|
||||
, fallingEnemies
|
||||
, userKeys
|
||||
} = game
|
||||
|
||||
val player = Player.runPhysicsAndInput (game, input)
|
||||
|
||||
val enemyTree = Enemy.generateTree enemies
|
||||
val player = Player.checkEnemyCollisions (player, enemies, enemyTree)
|
||||
|
||||
val (player, enemies, fallingEnemies) =
|
||||
PlayerAttack.attackEnemies (player, enemies, enemyTree, fallingEnemies)
|
||||
|
||||
val projectiles = #projectiles player
|
||||
val (fallingEnemies, enemies) =
|
||||
PlayerAttack.projectileHitEnemy
|
||||
(projectiles, enemies, enemyTree, fallingEnemies)
|
||||
|
||||
val enemies = Enemy.update
|
||||
(enemies, walls, wallTree, platforms, platformTree, player, graph)
|
||||
|
||||
val fallingEnemies = FallingEnemies.update fallingEnemies
|
||||
in
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = fallingEnemies
|
||||
, userKeys = userKeys
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -102,7 +102,7 @@ struct
|
||||
end
|
||||
end)
|
||||
|
||||
fun getDrawVec (game: GameType.game_type, width, height) =
|
||||
fun getDrawVec (game: LevelType.level_type, width, height) =
|
||||
let
|
||||
val fallingEnemies = #fallingEnemies game
|
||||
val wratio = width / Constants.worldWidthReal
|
||||
148
fcore/level/level-type.sml
Normal file
148
fcore/level/level-type.sml
Normal file
@@ -0,0 +1,148 @@
|
||||
signature LEVEL_TYPE =
|
||||
sig
|
||||
type level_type =
|
||||
{ player: PlayerType.player
|
||||
, walls: Wall.t vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: Platform.t vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: EnemyMap.t
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: FallingEnemyMap.t
|
||||
, userKeys: CoreKey.user_key
|
||||
}
|
||||
|
||||
val initial: CoreKey.user_key -> level_type
|
||||
end
|
||||
|
||||
structure LevelType :> LEVEL_TYPE =
|
||||
struct
|
||||
type level_type =
|
||||
{ player: PlayerType.player
|
||||
, walls: Wall.t vector
|
||||
, wallTree: QuadTree.t
|
||||
, platforms: Platform.t vector
|
||||
, platformTree: QuadTree.t
|
||||
, enemies: EnemyMap.t
|
||||
, graph: PlatSet.elem vector vector
|
||||
, fallingEnemies: FallingEnemyMap.t
|
||||
, userKeys: CoreKey.user_key
|
||||
}
|
||||
|
||||
fun enemyMapFromList (hd :: tl, map) =
|
||||
let val map = EnemyMap.add (#id hd, hd, map)
|
||||
in enemyMapFromList (tl, map)
|
||||
end
|
||||
| enemyMapFromList ([], map) = map
|
||||
|
||||
fun initial userKeys =
|
||||
let
|
||||
val player =
|
||||
{ yAxis = EntityType.JUMPING 0
|
||||
, xAxis = EntityType.STAY_STILL
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, recoil = PlayerType.NO_RECOIL
|
||||
, attacked = PlayerType.NOT_ATTACKED
|
||||
, mainAttack = PlayerType.MAIN_NOT_ATTACKING
|
||||
, mainAttackPressed = false
|
||||
, health = 3
|
||||
, x = 500
|
||||
, y = 800
|
||||
, jumpPressed = false
|
||||
, enemies = Vector.fromList []
|
||||
, charge = Constants.maxCharge
|
||||
, projectiles = Vector.fromList []
|
||||
, platID = ~1
|
||||
}
|
||||
|
||||
val wall1 = {id = 1, x = 0, y = 0, width = 100, height = 1080}
|
||||
val wall2 = {id = 2, x = 1820, y = 0, width = 100, height = 1080}
|
||||
val wall3 = {id = 3, x = 0, y = 980, width = 1920, height = 108}
|
||||
val walls = Vector.fromList [wall1, wall2, wall3]
|
||||
val wallTree = Wall.generateTree walls
|
||||
|
||||
val plat1 = {id = 1, x = 255, y = 855, width = 199}
|
||||
val plat2 = {id = 2, x = 750, y = 855, width = 199}
|
||||
val plat3 = {id = 3, x = 399, y = 755, width = 399}
|
||||
val plat4 = {id = 4, x = 255, y = 655, width = 199}
|
||||
val plat5 = {id = 5, x = 750, y = 655, width = 199}
|
||||
val plat6 = {id = 6, x = 171, y = 555, width = 99}
|
||||
val plat7 = {id = 7, x = 934, y = 555, width = 99}
|
||||
val plat8 = {id = 8, x = 399, y = 555, width = 399}
|
||||
val plat9 = {id = 9, x = 255, y = 455, width = 199}
|
||||
val plat10 = {id = 10, x = 750, y = 455, width = 199}
|
||||
val plat11 = {id = 11, x = 399, y = 355, width = 399}
|
||||
val plat12 = {id = 12, x = 255, y = 255, width = 199}
|
||||
val plat13 = {id = 13, x = 750, y = 255, width = 199}
|
||||
val plat14 = {id = 14, x = 399, y = 155, width = 399}
|
||||
val plat15 = {id = 15, x = 171, y = 155, width = 99}
|
||||
val plat16 = {id = 16, x = 934, y = 155, width = 99}
|
||||
val platforms = Vector.fromList
|
||||
[ plat1
|
||||
, plat2
|
||||
, plat3
|
||||
, plat4
|
||||
, plat5
|
||||
, plat6
|
||||
, plat7
|
||||
, plat8
|
||||
, plat9
|
||||
, plat10
|
||||
, plat11
|
||||
, plat12
|
||||
, plat13
|
||||
, plat14
|
||||
, plat15
|
||||
, plat16
|
||||
]
|
||||
val platformTree = Platform.generateTree platforms
|
||||
|
||||
val enemy1 =
|
||||
{ id = 1
|
||||
, x = 751
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = EntityType.MOVE_RIGHT
|
||||
, yAxis = EntityType.FALLING
|
||||
, variant = EnemyType.FOLLOW_SLIME
|
||||
, batDirY = EnemyType.UP
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
, batMaxY = 485
|
||||
, batMinY = 625
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, shieldOn = false
|
||||
}
|
||||
val enemy2 =
|
||||
{ id = 2
|
||||
, x = 351
|
||||
, y = 555
|
||||
, health = 1
|
||||
, xAxis = EntityType.MOVE_RIGHT
|
||||
, yAxis = EntityType.FALLING
|
||||
, variant = EnemyType.SHIELD_SLIME
|
||||
, batDirY = EnemyType.UP
|
||||
, platID = ~1
|
||||
, nextPlatID = ~1
|
||||
, batRest = 0
|
||||
, batMaxY = 485
|
||||
, batMinY = 625
|
||||
, facing = EntityType.FACING_RIGHT
|
||||
, shieldOn = false
|
||||
}
|
||||
val enemies = enemyMapFromList ([enemy1, enemy2], EnemyMap.empty)
|
||||
val graph = Graph.fromPlatforms (platforms, platformTree)
|
||||
in
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = FallingEnemyMap.empty
|
||||
, userKeys = userKeys
|
||||
}
|
||||
end
|
||||
end
|
||||
46
fcore/level/level-update.sml
Normal file
46
fcore/level/level-update.sml
Normal file
@@ -0,0 +1,46 @@
|
||||
structure LevelUpdate =
|
||||
struct
|
||||
fun update (game, input) =
|
||||
let
|
||||
val
|
||||
{ player
|
||||
, walls
|
||||
, wallTree
|
||||
, platforms
|
||||
, platformTree
|
||||
, enemies
|
||||
, graph
|
||||
, fallingEnemies
|
||||
, userKeys
|
||||
} = game
|
||||
|
||||
val player = Player.runPhysicsAndInput (game, input)
|
||||
|
||||
val enemyTree = Enemy.generateTree enemies
|
||||
val player = Player.checkEnemyCollisions (player, enemies, enemyTree)
|
||||
|
||||
val (player, enemies, fallingEnemies) =
|
||||
PlayerAttack.attackEnemies (player, enemies, enemyTree, fallingEnemies)
|
||||
|
||||
val projectiles = #projectiles player
|
||||
val (fallingEnemies, enemies) =
|
||||
PlayerAttack.projectileHitEnemy
|
||||
(projectiles, enemies, enemyTree, fallingEnemies)
|
||||
|
||||
val enemies = Enemy.update
|
||||
(enemies, walls, wallTree, platforms, platformTree, player, graph)
|
||||
|
||||
val fallingEnemies = FallingEnemies.update fallingEnemies
|
||||
in
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = fallingEnemies
|
||||
, userKeys = userKeys
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -376,7 +376,7 @@ struct
|
||||
fun fold (_, (), defeatedList) = {angle = 1} :: defeatedList
|
||||
end)
|
||||
|
||||
fun runPhysicsAndInput (game: GameType.game_type, input) =
|
||||
fun runPhysicsAndInput (game: LevelType.level_type, input) =
|
||||
let
|
||||
val player = #player game
|
||||
|
||||
57
oms.mlb
57
oms.mlb
@@ -2,11 +2,11 @@ $(SML_LIB)/basis/basis.mlb
|
||||
|
||||
(* fcore *)
|
||||
fcore/constants.sml
|
||||
fcore/collision.sml
|
||||
fcore/level/collision.sml
|
||||
|
||||
fcore/quad-tree-type.sml
|
||||
fcore/quad-tree-fold.sml
|
||||
fcore/quad-tree.sml
|
||||
fcore/level/quad-tree-type.sml
|
||||
fcore/level/quad-tree-fold.sml
|
||||
fcore/level/quad-tree.sml
|
||||
|
||||
vendored/brolib-sml/src/gap_map.sml
|
||||
|
||||
@@ -17,39 +17,40 @@ ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
fcore/block.sml
|
||||
fcore/player/player-sprite.sml
|
||||
fcore/level/player/player-sprite.sml
|
||||
fcore/field.sml
|
||||
fcore/chain-edge.sml
|
||||
fcore/level/chain-edge.sml
|
||||
end
|
||||
|
||||
fcore/wall.sml
|
||||
fcore/platform.sml
|
||||
fcore/level/wall.sml
|
||||
fcore/level/platform.sml
|
||||
|
||||
fcore/graph.sml
|
||||
fcore/path-finding.sml
|
||||
fcore/level/graph.sml
|
||||
fcore/level/path-finding.sml
|
||||
|
||||
fcore/entity-type.sml
|
||||
fcore/enemy/enemy-type.sml
|
||||
fcore/enemy/enemy-pair.sml
|
||||
fcore/enemy/enemy-map.sml
|
||||
fcore/enemy/falling-enemy-pair.sml
|
||||
fcore/enemy/falling-enemy-map.sml
|
||||
fcore/level/entity-type.sml
|
||||
fcore/level/enemy/enemy-type.sml
|
||||
fcore/level/enemy/enemy-pair.sml
|
||||
fcore/level/enemy/enemy-map.sml
|
||||
fcore/level/enemy/falling-enemy-pair.sml
|
||||
fcore/level/enemy/falling-enemy-map.sml
|
||||
|
||||
fcore/core-key.sml
|
||||
fcore/player/player-type.sml
|
||||
fcore/game-type.sml
|
||||
fcore/level/player/player-type.sml
|
||||
fcore/level/level-type.sml
|
||||
|
||||
fcore/player/player-patch.sml
|
||||
fcore/enemy/enemy-patch.sml
|
||||
fcore/physics.sml
|
||||
fcore/level/player/player-patch.sml
|
||||
fcore/level/enemy/enemy-patch.sml
|
||||
fcore/level/physics.sml
|
||||
|
||||
fcore/trace-jump.sml
|
||||
fcore/enemy/enemy-behaviour.sml
|
||||
fcore/enemy/enemy.sml
|
||||
fcore/enemy/falling-enemies.sml
|
||||
fcore/player/player.sml
|
||||
fcore/player/player-attack.sml
|
||||
fcore/projectile.sml
|
||||
fcore/level/trace-jump.sml
|
||||
fcore/level/enemy/enemy-behaviour.sml
|
||||
fcore/level/enemy/enemy.sml
|
||||
fcore/level/enemy/falling-enemies.sml
|
||||
fcore/level/player/player.sml
|
||||
fcore/level/player/player-attack.sml
|
||||
fcore/level/projectile.sml
|
||||
fcore/level/level-update.sml
|
||||
|
||||
fcore/game-update.sml
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ struct
|
||||
val width = InputState.getWidth ()
|
||||
val height = InputState.getHeight ()
|
||||
|
||||
val game = GameUpdate.update (game, input)
|
||||
val game = LevelUpdate.update (game, input)
|
||||
|
||||
val playerVec = Player.getDrawVec (#player game, width, height)
|
||||
val enemyVec = Enemy.getDrawVec (#enemies game, width, height)
|
||||
@@ -281,6 +281,6 @@ struct
|
||||
|
||||
val () = InputState.setControls controls
|
||||
in
|
||||
helpLoop (shellState, GameType.initial controls)
|
||||
helpLoop (shellState, LevelType.initial controls)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user