From 45a103da2133b645fac9617cc97c11901d3e258f Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 10 Mar 2023 23:53:40 +0000 Subject: Change stage --- src/Game/Hud.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/Game/Hud.hs') diff --git a/src/Game/Hud.hs b/src/Game/Hud.hs index a5d3e22..c4d5234 100644 --- a/src/Game/Hud.hs +++ b/src/Game/Hud.hs @@ -1,5 +1,6 @@ module Game.Hud (Hud, mkHud, render, height) where +import qualified Game.BitmapFont as BM import qualified Game.Sprites as S import qualified Game.State as GS import qualified SDL @@ -7,16 +8,18 @@ import qualified SDL height :: Int height = 16 -newtype Hud = Hud S.Sprite +data Hud = Hud S.Sprite BM.BitmapFont -mkHud :: S.SpriteSheet -> IO Hud -mkHud sprites = do - Hud <$> S.get sprites "hud" +mkHud :: S.SpriteSheet -> BM.BitmapFont -> IO Hud +mkHud sprites font = do + sprite <- S.get sprites "hud" + pure $ Hud sprite font render :: SDL.Renderer -> Hud -> GS.State -> IO () -render renderer (Hud sprite) state = do +render renderer (Hud sprite font) state = do let xs = [0 .. state.totalBatteries - 1] in mapM_ (\x -> S.render renderer sprite (4 + x * 8) 4 0 (if state.batteries <= x then 0 else 1)) xs let xs = [0 .. state.totalLives - 1] in -- magic numbers mapM_ (\x -> S.render renderer sprite (320 - 4 - state.totalLives * 8 + x * 8) 4 0 (if state.lives <= x then 2 else 3)) xs + BM.renderText renderer font 140 4 $ "Stage " ++ show (state.currentLevel + 1) -- cgit v1.2.3