From 11120a24b6927073d55d2e56b4b911817dedaae2 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 15 Feb 2023 22:53:22 +0000 Subject: Game state, HUD, ... WIP Exploring ideas. --- src/Game/Hud.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/Game/Hud.hs (limited to 'src/Game/Hud.hs') diff --git a/src/Game/Hud.hs b/src/Game/Hud.hs new file mode 100644 index 0000000..3b59558 --- /dev/null +++ b/src/Game/Hud.hs @@ -0,0 +1,22 @@ +module Game.Hud (Hud, mkHud, render) where + +import Data.IORef +import qualified Game.Sprites as S +import qualified Game.State as GS +import qualified SDL + +data Hud = Hud + { sprite :: S.Sprite, + stateRef :: IORef GS.State + } + +mkHud :: S.SpriteSheet -> IORef GS.State -> IO Hud +mkHud sprites stateRef = do + sprite <- S.get sprites "hud" + pure Hud {sprite = sprite, stateRef = stateRef} + +render :: SDL.Renderer -> Hud -> IO () +render renderer hud = do + state <- readIORef hud.stateRef + let xs = [0 .. state.totalBatteries - 1] + mapM_ (\x -> S.render renderer hud.sprite (4 + x * 8) 178 0 (if state.batteries <= x then 0 else 1)) xs -- cgit v1.2.3