aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-03 12:57:17 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-03-03 12:57:17 +0000
commitef0a75834870eced4371edd6d50916d4e1bd432f (patch)
tree259062a436aff6f722a807c9885b2a092f6bcadc /src
parente5cbf917ad8b12b48932bc4fa13a044bc8159a74 (diff)
downloadspace-plat-hs-ef0a75834870eced4371edd6d50916d4e1bd432f.tar.gz
space-plat-hs-ef0a75834870eced4371edd6d50916d4e1bd432f.zip
Simple game over menu
Diffstat (limited to 'src')
-rw-r--r--src/Game.hs50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/Game.hs b/src/Game.hs
index 851b7fc..1d93065 100644
--- a/src/Game.hs
+++ b/src/Game.hs
@@ -8,6 +8,7 @@ import Foreign.C.Types (CInt)
import qualified Game.BitmapFont as BF
import qualified Game.Controller as C
import qualified Game.Entities as E
+import Game.Entities.Const (hitDelay)
import qualified Game.Hud as H
import qualified Game.Map as M
import qualified Game.Sprites as S
@@ -54,6 +55,17 @@ data Env = Env
defaultRenderRect :: SDL.Rectangle CInt
defaultRenderRect = SDL.Rectangle (SDL.P $ V2 0 0) (V2 windowWidth windowHeight)
+initialState :: M.Map -> GS.State
+initialState m =
+ GS.State
+ { batteries = 0,
+ totalBatteries = M.totalBatteries m,
+ lives = maxLives,
+ totalLives = maxLives,
+ hitDelay = hitDelay,
+ gameOverDelay = 0
+ }
+
main :: IO ()
main = do
SDL.initialize [SDL.InitVideo, SDL.InitGameController]
@@ -80,15 +92,6 @@ main = do
controls <- newIORef =<< C.init
entities <- E.mkEntities sprites map' controls
hud <- H.mkHud sprites
- let initialState =
- GS.State
- { batteries = 0,
- totalBatteries = M.totalBatteries map',
- lives = maxLives,
- totalLives = maxLives,
- hitDelay = 0,
- gameOverDelay = 0
- }
gameLoop
Env
{ window = window,
@@ -101,7 +104,7 @@ main = do
font = font,
entities = entities,
hud = hud,
- state = initialState,
+ state = initialState map',
controls = controls
}
SDL.destroyWindow window
@@ -198,8 +201,25 @@ gameOverLoop e = do
sprites = e.sprites
state = e.state
hud = e.hud
-
- H.render renderer hud state
- title <- S.get sprites "game-over"
- S.render renderer title 112 80 0 0
- pure e
+ font = e.font
+ map' = e.map
+ controls = e.controls
+
+ ctl <- readIORef controls
+
+ if ctl.a
+ then do
+ -- retry last level
+ entities <- E.mkEntities sprites map' controls
+ pure e {state = initialState map', entities = entities}
+ else do
+ H.render renderer hud state
+ title <- S.get sprites "game-over"
+ S.render renderer title 112 80 0 0
+
+ BF.renderText renderer font 109 116 "Press to retry"
+ button <- S.get sprites "ui"
+ S.render renderer button 143 113 0 1
+
+ BF.renderText renderer font 112 132 "(or ESC to quit)"
+ pure e