when play button is focused on title screen and either attack or jump button is pressed, start level
This commit is contained in:
11
fcore/frame-input-type.sml
Normal file
11
fcore/frame-input-type.sml
Normal file
@@ -0,0 +1,11 @@
|
||||
structure FrameInputType =
|
||||
struct
|
||||
type t =
|
||||
{ leftHeld: bool
|
||||
, rightHeld: bool
|
||||
, upHeld: bool
|
||||
, downHeld: bool
|
||||
, attackHeld: bool
|
||||
, jumpHeld: bool
|
||||
}
|
||||
end
|
||||
@@ -5,18 +5,9 @@ struct
|
||||
fun update (game: GameType.game_type, input) =
|
||||
let
|
||||
val {mode, userKeys} = game
|
||||
|
||||
val mode =
|
||||
case mode of
|
||||
LEVEL level =>
|
||||
let val level = LevelUpdate.update (level, input)
|
||||
in LEVEL level
|
||||
end
|
||||
| TITLE title =>
|
||||
let val title = TitleUpdate.update (title, input)
|
||||
in TITLE title
|
||||
end
|
||||
in
|
||||
{mode = mode, userKeys = userKeys}
|
||||
case mode of
|
||||
LEVEL level => LevelUpdate.update (level, input, userKeys)
|
||||
| TITLE title => TitleUpdate.update (title, input, userKeys)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
structure LevelUpdate =
|
||||
struct
|
||||
fun update (level, input) =
|
||||
fun update (level, input, userKeys) =
|
||||
let
|
||||
val
|
||||
{ player
|
||||
@@ -30,15 +30,18 @@ struct
|
||||
(enemies, walls, wallTree, platforms, platformTree, player, graph)
|
||||
|
||||
val fallingEnemies = FallingEnemies.update fallingEnemies
|
||||
|
||||
val mode =
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = fallingEnemies
|
||||
}
|
||||
in
|
||||
{ player = player
|
||||
, walls = walls
|
||||
, wallTree = wallTree
|
||||
, platforms = platforms
|
||||
, platformTree = platformTree
|
||||
, enemies = enemies
|
||||
, graph = graph
|
||||
, fallingEnemies = fallingEnemies
|
||||
}
|
||||
{mode = GameType.LEVEL mode, userKeys = userKeys}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,5 +2,16 @@ structure TitleUpdate =
|
||||
struct
|
||||
open TitleType
|
||||
|
||||
fun update (titleState, input) = titleState
|
||||
fun update (titleState, input: FrameInputType.t, userKeys) =
|
||||
case #focus titleState of
|
||||
START_BUTTON =>
|
||||
let
|
||||
val mode =
|
||||
if #attackHeld input orelse #jumpHeld input then
|
||||
GameType.LEVEL LevelType.initial
|
||||
else
|
||||
GameType.TITLE titleState
|
||||
in
|
||||
{mode = mode, userKeys = userKeys}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,19 @@ struct
|
||||
open TitleType
|
||||
|
||||
fun helpGetTextVec
|
||||
(x, y, fontSize, fontSpace, windowWidth, windowHeight, pos, str, acc, r, g, b) =
|
||||
( x
|
||||
, y
|
||||
, fontSize
|
||||
, fontSpace
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, pos
|
||||
, str
|
||||
, acc
|
||||
, r
|
||||
, g
|
||||
, b
|
||||
) =
|
||||
if pos = String.size str then
|
||||
Vector.concat acc
|
||||
else
|
||||
@@ -31,15 +43,12 @@ struct
|
||||
)
|
||||
end
|
||||
|
||||
fun getTextWidth text =
|
||||
String.size text * Constants.fontSpace
|
||||
fun getTextWidth text = String.size text * Constants.fontSpace
|
||||
|
||||
(* x coordinate that will let us place this text on centre of screen *)
|
||||
fun getTextCentreX text =
|
||||
let
|
||||
val textWidth = getTextWidth text
|
||||
in
|
||||
(Constants.worldWidth - textWidth) div 2
|
||||
let val textWidth = getTextWidth text
|
||||
in (Constants.worldWidth - textWidth) div 2
|
||||
end
|
||||
|
||||
fun getTextVec (x, y, width, height, str, r, g, b) =
|
||||
@@ -66,7 +75,8 @@ struct
|
||||
val fontSpace = Real32.fromInt Constants.fontSpace * wratio
|
||||
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
|
||||
in
|
||||
helpGetTextVec (x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b)
|
||||
helpGetTextVec
|
||||
(x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b)
|
||||
end
|
||||
else
|
||||
let
|
||||
@@ -87,16 +97,15 @@ struct
|
||||
val fontSpace = Real32.fromInt Constants.fontSpace * hratio
|
||||
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
|
||||
in
|
||||
helpGetTextVec (x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b)
|
||||
helpGetTextVec
|
||||
(x, y, fontSize, fontSpace, width, height, 0, str, [], r, g, b)
|
||||
end
|
||||
end
|
||||
|
||||
fun getDrawVec (title: TitleType.title_type, width, height) =
|
||||
case #focus title of
|
||||
START_BUTTON =>
|
||||
let
|
||||
val playX = getTextCentreX "Play game"
|
||||
in
|
||||
getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0)
|
||||
let val playX = getTextCentreX "Play game"
|
||||
in getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user