when play button is focused on title screen and either attack or jump button is pressed, start level

This commit is contained in:
2025-02-20 05:46:00 +00:00
parent f293e084f7
commit 6d39c17a11
6 changed files with 64 additions and 38 deletions

View File

@@ -0,0 +1,11 @@
structure FrameInputType =
struct
type t =
{ leftHeld: bool
, rightHeld: bool
, upHeld: bool
, downHeld: bool
, attackHeld: bool
, jumpHeld: bool
}
end

View File

@@ -5,18 +5,9 @@ struct
fun update (game: GameType.game_type, input) = fun update (game: GameType.game_type, input) =
let let
val {mode, userKeys} = game 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 in
{mode = mode, userKeys = userKeys} case mode of
LEVEL level => LevelUpdate.update (level, input, userKeys)
| TITLE title => TitleUpdate.update (title, input, userKeys)
end end
end end

View File

@@ -1,6 +1,6 @@
structure LevelUpdate = structure LevelUpdate =
struct struct
fun update (level, input) = fun update (level, input, userKeys) =
let let
val val
{ player { player
@@ -30,7 +30,8 @@ struct
(enemies, walls, wallTree, platforms, platformTree, player, graph) (enemies, walls, wallTree, platforms, platformTree, player, graph)
val fallingEnemies = FallingEnemies.update fallingEnemies val fallingEnemies = FallingEnemies.update fallingEnemies
in
val mode =
{ player = player { player = player
, walls = walls , walls = walls
, wallTree = wallTree , wallTree = wallTree
@@ -40,5 +41,7 @@ struct
, graph = graph , graph = graph
, fallingEnemies = fallingEnemies , fallingEnemies = fallingEnemies
} }
in
{mode = GameType.LEVEL mode, userKeys = userKeys}
end end
end end

View File

@@ -2,5 +2,16 @@ structure TitleUpdate =
struct struct
open TitleType 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 end

View File

@@ -3,7 +3,19 @@ struct
open TitleType open TitleType
fun helpGetTextVec 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 if pos = String.size str then
Vector.concat acc Vector.concat acc
else else
@@ -31,15 +43,12 @@ struct
) )
end end
fun getTextWidth text = fun getTextWidth text = String.size text * Constants.fontSpace
String.size text * Constants.fontSpace
(* x coordinate that will let us place this text on centre of screen *) (* x coordinate that will let us place this text on centre of screen *)
fun getTextCentreX text = fun getTextCentreX text =
let let val textWidth = getTextWidth text
val textWidth = getTextWidth text in (Constants.worldWidth - textWidth) div 2
in
(Constants.worldWidth - textWidth) div 2
end end
fun getTextVec (x, y, width, height, str, r, g, b) = 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.fromInt Constants.fontSpace * wratio
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
in 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
else else
let let
@@ -87,16 +97,15 @@ struct
val fontSpace = Real32.fromInt Constants.fontSpace * hratio val fontSpace = Real32.fromInt Constants.fontSpace * hratio
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
in 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
end end
fun getDrawVec (title: TitleType.title_type, width, height) = fun getDrawVec (title: TitleType.title_type, width, height) =
case #focus title of case #focus title of
START_BUTTON => START_BUTTON =>
let let val playX = getTextCentreX "Play game"
val playX = getTextCentreX "Play game" in getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0)
in
getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0)
end end
end end

View File

@@ -37,8 +37,11 @@ fcore/level/enemy/falling-enemy-pair.sml
fcore/level/enemy/falling-enemy-map.sml fcore/level/enemy/falling-enemy-map.sml
fcore/core-key.sml fcore/core-key.sml
fcore/frame-input-type.sml
fcore/level/player/player-type.sml fcore/level/player/player-type.sml
fcore/level/level-type.sml fcore/level/level-type.sml
fcore/title/title-type.sml
fcore/game-type.sml
fcore/level/player/player-patch.sml fcore/level/player/player-patch.sml
fcore/level/enemy/enemy-patch.sml fcore/level/enemy/enemy-patch.sml
@@ -53,11 +56,9 @@ fcore/level/player/player-attack.sml
fcore/level/projectile.sml fcore/level/projectile.sml
fcore/level/level-update.sml fcore/level/level-update.sml
fcore/title/title-type.sml
fcore/title/title-update.sml fcore/title/title-update.sml
fcore/title/title-vec.sml fcore/title/title-vec.sml
fcore/game-type.sml
fcore/game-update.sml fcore/game-update.sml
(* shell *) (* shell *)