partial refactoring so we use EnemyMap.t for collection of enemies
This commit is contained in:
@@ -11,3 +11,73 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
structure EnemyMap = MakeGapMap(EnemyPair)
|
structure EnemyMap = MakeGapMap(EnemyPair)
|
||||||
|
|
||||||
|
structure EnemyTreeFolder =
|
||||||
|
struct
|
||||||
|
structure Pair = EnemyPair
|
||||||
|
|
||||||
|
type env = unit
|
||||||
|
type state = QuadTree.t
|
||||||
|
|
||||||
|
fun fold (enemyID, enemy: EnemyType.enemy, (), quadTree) =
|
||||||
|
let
|
||||||
|
val {id, x, y, ...} = enemy
|
||||||
|
val size = Constants.enemySize
|
||||||
|
in
|
||||||
|
QuadTree.insert (x, y, size, size, id, quadTree)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
structure MakeEnemyTree = MakeGapMapFolder(EnemyTreeFolder)
|
||||||
|
|
||||||
|
structure EnemyDrawVec =
|
||||||
|
MakeGapMapFolder
|
||||||
|
(struct
|
||||||
|
structure Pair = EnemyPair
|
||||||
|
|
||||||
|
type env = Real32.real * Real32.real
|
||||||
|
type state = Real32.real vector list
|
||||||
|
|
||||||
|
fun helpGetDrawVec (enemy: EnemyType.enemy, width, height) =
|
||||||
|
let
|
||||||
|
val {x, y, ...} = enemy
|
||||||
|
val wratio = width / Constants.worldWidthReal
|
||||||
|
val hratio = height / Constants.worldHeightReal
|
||||||
|
in
|
||||||
|
if wratio < hratio then
|
||||||
|
let
|
||||||
|
val scale = Constants.worldHeightReal * wratio
|
||||||
|
val yOffset =
|
||||||
|
if height > scale then (height - scale) / 2.0
|
||||||
|
else if height < scale then (scale - height) / 2.0
|
||||||
|
else 0.0
|
||||||
|
|
||||||
|
val x = Real32.fromInt x * wratio
|
||||||
|
val y = Real32.fromInt y * wratio + yOffset
|
||||||
|
|
||||||
|
val realSize = Constants.enemySizeReal * wratio
|
||||||
|
in
|
||||||
|
Block.lerp
|
||||||
|
(x, y, realSize, realSize, width, height, 0.5, 0.5, 1.0)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val scale = Constants.worldWidthReal * hratio
|
||||||
|
val xOffset =
|
||||||
|
if width > scale then (width - scale) / 2.0
|
||||||
|
else if width < scale then (scale - width) / 2.0
|
||||||
|
else 0.0
|
||||||
|
|
||||||
|
val x = Real32.fromInt x * hratio + xOffset
|
||||||
|
val y = Real32.fromInt y * hratio
|
||||||
|
|
||||||
|
val realSize = Constants.enemySizeReal * hratio
|
||||||
|
in
|
||||||
|
Block.lerp
|
||||||
|
(x, y, realSize, realSize, width, height, 0.5, 0.5, 1.0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fun fold (_, enemy: EnemyType.enemy, (width, height), acc) =
|
||||||
|
helpGetDrawVec (enemy, width, height) :: acc
|
||||||
|
end)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ sig
|
|||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: platform vector
|
, platforms: platform vector
|
||||||
, platformTree: QuadTree.t
|
, platformTree: QuadTree.t
|
||||||
, enemies: EnemyType.enemy vector
|
, enemies: EnemyMap.t
|
||||||
, graph: PlatSet.elem vector vector
|
, graph: PlatSet.elem vector vector
|
||||||
, fallingEnemies: EnemyType.falling_enemy vector
|
, fallingEnemies: EnemyType.falling_enemy vector
|
||||||
}
|
}
|
||||||
@@ -93,11 +93,17 @@ struct
|
|||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: platform vector
|
, platforms: platform vector
|
||||||
, platformTree: QuadTree.t
|
, platformTree: QuadTree.t
|
||||||
, enemies: EnemyType.enemy vector
|
, enemies: EnemyMap.t
|
||||||
, graph: PlatSet.elem vector vector
|
, graph: PlatSet.elem vector vector
|
||||||
, fallingEnemies: EnemyType.falling_enemy vector
|
, fallingEnemies: EnemyType.falling_enemy vector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun enemyMapFromList (hd :: tl, map) =
|
||||||
|
let val map = EnemyMap.add (#id hd, hd, map)
|
||||||
|
in enemyMapFromList (tl, map)
|
||||||
|
end
|
||||||
|
| enemyMapFromList ([], map) = map
|
||||||
|
|
||||||
val initial: game_type =
|
val initial: game_type =
|
||||||
let
|
let
|
||||||
val player =
|
val player =
|
||||||
@@ -175,7 +181,7 @@ struct
|
|||||||
, batMaxY = 485
|
, batMaxY = 485
|
||||||
, batMinY = 625
|
, batMinY = 625
|
||||||
}
|
}
|
||||||
val enemies = Vector.fromList [enemy1]
|
val enemies = enemyMapFromList ([enemy1], EnemyMap.empty)
|
||||||
val graph = Graph.fromPlatforms (platforms, platformTree)
|
val graph = Graph.fromPlatforms (platforms, platformTree)
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
|
|||||||
@@ -13,13 +13,18 @@ struct
|
|||||||
, fallingEnemies
|
, fallingEnemies
|
||||||
} = game
|
} = game
|
||||||
|
|
||||||
val enemyTree = Enemy.generateTree enemies
|
val enemyTree = MakeEnemyTree.foldUnordered
|
||||||
|
( enemies
|
||||||
|
, ()
|
||||||
|
, QuadTree.create (Constants.worldWidth, Constants.worldHeight)
|
||||||
|
)
|
||||||
val player = Player.runPhysicsAndInput (game, input, enemyTree)
|
val player = Player.runPhysicsAndInput (game, input, enemyTree)
|
||||||
|
|
||||||
val projectiles = #projectiles player
|
val projectiles = #projectiles player
|
||||||
val projectileTree = Projectile.generateTree projectiles
|
val projectileTree = Projectile.generateTree projectiles
|
||||||
|
|
||||||
(* update state of falling enemies and possibly filter *)
|
(* update state of falling enemies and possibly filter *)
|
||||||
|
(* todo: use enemy map
|
||||||
val fallingEnemies = FallingEnemies.updateList
|
val fallingEnemies = FallingEnemies.updateList
|
||||||
(Vector.length fallingEnemies - 1, fallingEnemies, player, [])
|
(Vector.length fallingEnemies - 1, fallingEnemies, player, [])
|
||||||
|
|
||||||
@@ -39,6 +44,7 @@ struct
|
|||||||
)
|
)
|
||||||
|
|
||||||
val fallingEnemies = Vector.fromList fallingEnemies
|
val fallingEnemies = Vector.fromList fallingEnemies
|
||||||
|
*)
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
, walls = walls
|
, walls = walls
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ struct
|
|||||||
structure FoldEnemies =
|
structure FoldEnemies =
|
||||||
MakeQuadTreeFold
|
MakeQuadTreeFold
|
||||||
(struct
|
(struct
|
||||||
type env = EnemyType.enemy vector * player
|
type env = EnemyMap.t * player
|
||||||
type state = PlayerPatch.player_patch list
|
type state = PlayerPatch.player_patch list
|
||||||
|
|
||||||
fun getEnemyRecoilPatches (player, playerOnRight, acc) =
|
fun getEnemyRecoilPatches (player, playerOnRight, acc) =
|
||||||
@@ -349,14 +349,19 @@ struct
|
|||||||
val pFinishX = x + Constants.playerSize
|
val pFinishX = x + Constants.playerSize
|
||||||
val pHalfW = Constants.playerSize div 2
|
val pHalfW = Constants.playerSize div 2
|
||||||
val pCentreX = x + pHalfW
|
val pCentreX = x + pHalfW
|
||||||
|
in
|
||||||
val {x = ex, y = ey, ...} = Enemy.find (enemyID, enemies)
|
case EnemyMap.get (enemyID, enemies) of
|
||||||
|
SOME {x = ex, y = ey, ...} =>
|
||||||
|
let
|
||||||
val eFinishX = ex + Constants.enemySize
|
val eFinishX = ex + Constants.enemySize
|
||||||
val eHalfW = Constants.enemySize div 2
|
val eHalfW = Constants.enemySize div 2
|
||||||
val eCentreX = ex + eHalfW
|
val eCentreX = ex + eHalfW
|
||||||
in
|
in
|
||||||
eCentreX < pCentreX
|
eCentreX < pCentreX
|
||||||
end
|
end
|
||||||
|
| NONE => false
|
||||||
|
end
|
||||||
|
|
||||||
val patches =
|
val patches =
|
||||||
getEnemyRecoilPatches (player, playerOnRight, patches)
|
getEnemyRecoilPatches (player, playerOnRight, patches)
|
||||||
in
|
in
|
||||||
@@ -437,10 +442,7 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
val patches =
|
val patches =
|
||||||
(* if player is attacking, check if enemies collide with attack
|
(* if player is attacking, check if enemies collide with attack *)
|
||||||
* todo: MAIN_ATTACKING variant should hold an integer,
|
|
||||||
* and be compared with attackLengthLimit
|
|
||||||
* and the attack should shrink at some point as well *)
|
|
||||||
case #mainAttack player of
|
case #mainAttack player of
|
||||||
MAIN_ATTACKING {length, ...} =>
|
MAIN_ATTACKING {length, ...} =>
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
signature QUAD_TREE =
|
signature QUAD_TREE =
|
||||||
sig
|
sig
|
||||||
type t
|
type t = {tree: QuadTreeType.t, width: int, height: int}
|
||||||
|
|
||||||
val insert: int * int * int * int * int * t -> t
|
val insert: int * int * int * int * int * t -> t
|
||||||
|
|
||||||
|
|||||||
3
oms.mlb
3
oms.mlb
@@ -1,7 +1,6 @@
|
|||||||
$(SML_LIB)/basis/basis.mlb
|
$(SML_LIB)/basis/basis.mlb
|
||||||
|
|
||||||
(* fcore *)
|
(* fcore *)
|
||||||
vendored/brolib-sml/src/gap_map.sml
|
|
||||||
fcore/constants.sml
|
fcore/constants.sml
|
||||||
fcore/collision.sml
|
fcore/collision.sml
|
||||||
|
|
||||||
@@ -9,6 +8,8 @@ fcore/quad-tree-type.sml
|
|||||||
fcore/quad-tree-fold.sml
|
fcore/quad-tree-fold.sml
|
||||||
fcore/quad-tree.sml
|
fcore/quad-tree.sml
|
||||||
|
|
||||||
|
vendored/brolib-sml/src/gap_map.sml
|
||||||
|
|
||||||
fcore/bin-search.sml
|
fcore/bin-search.sml
|
||||||
fcore/bin-vec.sml
|
fcore/bin-vec.sml
|
||||||
|
|
||||||
|
|||||||
@@ -236,7 +236,11 @@ struct
|
|||||||
val game = GameUpdate.update (game, input)
|
val game = GameUpdate.update (game, input)
|
||||||
|
|
||||||
val playerVec = Player.getDrawVec (#player game, width, height)
|
val playerVec = Player.getDrawVec (#player game, width, height)
|
||||||
val enemyVec = Enemy.getDrawVec (#enemies game, width, height)
|
|
||||||
|
val enemyVec =
|
||||||
|
EnemyDrawVec.foldUnordered (#enemies game, (width, height), [])
|
||||||
|
val enemyVec = Vector.concat enemyVec
|
||||||
|
|
||||||
val playerVec = Vector.concat [playerVec, enemyVec]
|
val playerVec = Vector.concat [playerVec, enemyVec]
|
||||||
|
|
||||||
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
||||||
|
|||||||
Submodule vendored/brolib-sml updated: f3cc41e9a2...5f834ddaa4
Reference in New Issue
Block a user