aboutsummaryrefslogtreecommitdiff
path: root/src/Game.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-15 22:53:22 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-15 22:53:22 +0000
commit11120a24b6927073d55d2e56b4b911817dedaae2 (patch)
tree0c591330afba9f37a4ff0110a022b213aedb31e0 /src/Game.hs
parent6f2644afcb52e4cfb60169de2cb3efdff62b17b2 (diff)
downloadspace-plat-hs-11120a24b6927073d55d2e56b4b911817dedaae2.tar.gz
space-plat-hs-11120a24b6927073d55d2e56b4b911817dedaae2.zip
Game state, HUD, ... WIP
Exploring ideas.
Diffstat (limited to 'src/Game.hs')
-rw-r--r--src/Game.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/Game.hs b/src/Game.hs
index c267453..a7454b8 100644
--- a/src/Game.hs
+++ b/src/Game.hs
@@ -7,8 +7,10 @@ import Data.Text (pack)
import Foreign.C.Types (CInt)
import qualified Game.Controller as C
import qualified Game.Entities as E
+import qualified Game.Hud as H
import qualified Game.Map as M
import qualified Game.Sprites as S
+import qualified Game.State as GS
import Game.Utils (isPressed)
import SDL (($=), ($~))
import qualified SDL
@@ -19,7 +21,7 @@ name :: String
name = "Haskell gamedev [Space Platformer]"
gameWidth, gameHeight :: CInt
-(gameWidth, gameHeight) = (320, 180)
+(gameWidth, gameHeight) = (320, 192)
gameScale :: CInt
gameScale = 3
@@ -39,7 +41,9 @@ data Env = Env
controls :: IORef C.Controls,
map :: M.Map,
sprites :: S.SpriteSheet,
- entities :: IORef E.Entities
+ entities :: IORef E.Entities,
+ hud :: H.Hud,
+ state :: IORef GS.State
}
defaultRenderRect :: SDL.Rectangle CInt
@@ -69,7 +73,14 @@ main = do
controls <- newIORef =<< C.init
map' <- M.load "data/map.json" tsTexture
sprites <- S.load "data/sprites.json" ssTexture
- entities <- newIORef =<< E.mkEntities sprites map' controls
+ state <-
+ newIORef
+ GS.State
+ { batteries = 0,
+ totalBatteries = M.totalBatteries map'
+ }
+ hud <- H.mkHud sprites state
+ entities <- newIORef =<< E.mkEntities sprites map' controls state
runReaderT
gameLoop
Env
@@ -81,7 +92,9 @@ main = do
controls = controls,
map = map',
sprites = sprites,
- entities = entities
+ entities = entities,
+ hud = hud,
+ state = state
}
SDL.destroyWindow window
SDL.quit
@@ -120,6 +133,7 @@ gameLoop = do
controls = env.controls
map' = env.map
entities = env.entities
+ hud = env.hud
events <- map SDL.eventPayload <$> SDL.pollEvents
@@ -141,9 +155,11 @@ gameLoop = do
-- render map and entities
void $ liftIO $ do
M.render renderer map'
+ H.render renderer hud
E.render renderer updated
SDL.rendererRenderTarget renderer $= Nothing
+ SDL.clear renderer
rect <- SDL.get renderRect
SDL.copy renderer canvas Nothing (Just rect)