begin coding enemy
This commit is contained in:
71
fcore/enemy.sml
Normal file
71
fcore/enemy.sml
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
structure Enemy =
|
||||||
|
struct
|
||||||
|
val size = 35
|
||||||
|
val realSize = 35.0
|
||||||
|
|
||||||
|
fun helpGenerateTree (pos, enemyVec, acc) =
|
||||||
|
if pos = Vector.length enemyVec then
|
||||||
|
acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {id, x, y, health = _} = Vector.sub (enemyVec, pos)
|
||||||
|
val acc = QuadTree.insert
|
||||||
|
(x, y, size, size, 0, 0, 1920, 1080, id, acc)
|
||||||
|
in
|
||||||
|
helpGenerateTree (pos + 1, enemyVec, acc)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun generateTree enemyVec = helpGenerateTree (0, enemyVec, QuadTree.empty)
|
||||||
|
|
||||||
|
fun helpGetDrawVec ({x, y, id = _, health = _}, width, height) =
|
||||||
|
let
|
||||||
|
val wratio = width / 1920.0
|
||||||
|
val hratio = height / 1080.0
|
||||||
|
in
|
||||||
|
if wratio < hratio then
|
||||||
|
let
|
||||||
|
val scale = 1080.0 * 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 = realSize * wratio
|
||||||
|
in
|
||||||
|
Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 1.0)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val scale = 1920.0 * 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 = realSize * hratio
|
||||||
|
in
|
||||||
|
Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 1.0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getDrawVecLoop (pos, enemies, width, height, acc) =
|
||||||
|
if pos = Vector.length enemies then
|
||||||
|
Vector.concat acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val e = Vector.sub (enemies, pos)
|
||||||
|
val hd = helpGetDrawVec (e, width, height)
|
||||||
|
val acc = hd :: acc
|
||||||
|
in
|
||||||
|
getDrawVecLoop (pos + 1, enemies, width, height, acc)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getDrawVec (enemies, width, height) =
|
||||||
|
getDrawVecLoop (0, enemies, width, height, [])
|
||||||
|
end
|
||||||
@@ -22,12 +22,16 @@ sig
|
|||||||
, jumpPressed: bool
|
, jumpPressed: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type enemy = {id: int, health: int, x: int, y: int}
|
||||||
|
|
||||||
type game_type =
|
type game_type =
|
||||||
{ player: player
|
{ player: player
|
||||||
, walls: wall vector
|
, walls: wall vector
|
||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: platform vector
|
, platforms: platform vector
|
||||||
, platformTree: QuadTree.t
|
, platformTree: QuadTree.t
|
||||||
|
, enemies: enemy vector
|
||||||
|
, enemyTree: QuadTree.t
|
||||||
}
|
}
|
||||||
|
|
||||||
val initial: game_type
|
val initial: game_type
|
||||||
@@ -58,12 +62,16 @@ struct
|
|||||||
, jumpPressed: bool
|
, jumpPressed: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type enemy = {id: int, health: int, x: int, y: int}
|
||||||
|
|
||||||
type game_type =
|
type game_type =
|
||||||
{ player: player
|
{ player: player
|
||||||
, walls: wall vector
|
, walls: wall vector
|
||||||
, wallTree: QuadTree.t
|
, wallTree: QuadTree.t
|
||||||
, platforms: platform vector
|
, platforms: platform vector
|
||||||
, platformTree: QuadTree.t
|
, platformTree: QuadTree.t
|
||||||
|
, enemies: enemy vector
|
||||||
|
, enemyTree: QuadTree.t
|
||||||
}
|
}
|
||||||
|
|
||||||
val initial: game_type =
|
val initial: game_type =
|
||||||
@@ -86,12 +94,18 @@ struct
|
|||||||
val plat1 = {id = 1, x = 155, y = 911, width = 155}
|
val plat1 = {id = 1, x = 155, y = 911, width = 155}
|
||||||
val platforms = Vector.fromList [plat1]
|
val platforms = Vector.fromList [plat1]
|
||||||
val platformTree = Platform.generateTree platforms
|
val platformTree = Platform.generateTree platforms
|
||||||
|
|
||||||
|
val enemy1 = {id = 1, x = 300, y = 945, health = 5}
|
||||||
|
val enemies = Vector.fromList [enemy1]
|
||||||
|
val enemyTree = Enemy.generateTree enemies
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
, walls = walls
|
, walls = walls
|
||||||
, wallTree = wallTree
|
, wallTree = wallTree
|
||||||
, platforms = platforms
|
, platforms = platforms
|
||||||
, platformTree = platformTree
|
, platformTree = platformTree
|
||||||
|
, enemies = enemies
|
||||||
|
, enemyTree = enemyTree
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ structure GameUpdate =
|
|||||||
struct
|
struct
|
||||||
fun update (game, input) =
|
fun update (game, input) =
|
||||||
let
|
let
|
||||||
val {player, walls, wallTree, platforms, platformTree} = game
|
val {player, walls, wallTree, platforms, platformTree, enemies, enemyTree} =
|
||||||
|
game
|
||||||
val player = Player.move (game, input)
|
val player = Player.move (game, input)
|
||||||
in
|
in
|
||||||
{ player = player
|
{ player = player
|
||||||
@@ -10,6 +11,8 @@ struct
|
|||||||
, wallTree = wallTree
|
, wallTree = wallTree
|
||||||
, platforms = platforms
|
, platforms = platforms
|
||||||
, platformTree = platformTree
|
, platformTree = platformTree
|
||||||
|
, enemies = enemies
|
||||||
|
, enemyTree = enemyTree
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1
oms.mlb
1
oms.mlb
@@ -11,6 +11,7 @@ end
|
|||||||
|
|
||||||
fcore/wall.sml
|
fcore/wall.sml
|
||||||
fcore/platform.sml
|
fcore/platform.sml
|
||||||
|
fcore/enemy.sml
|
||||||
fcore/game-type.sml
|
fcore/game-type.sml
|
||||||
|
|
||||||
fcore/player.sml
|
fcore/player.sml
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ 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 playerVec = Vector.concat [playerVec, enemyVec]
|
||||||
|
|
||||||
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
||||||
val platVec = Platform.getDrawVec (#platforms game, width, height)
|
val platVec = Platform.getDrawVec (#platforms game, width, height)
|
||||||
val wallVec = Vector.concat [wallVec, platVec]
|
val wallVec = Vector.concat [wallVec, platVec]
|
||||||
|
|||||||
Reference in New Issue
Block a user