aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Hud.hs
blob: a93166c38a328e5339d266975d8ca38ad9e61a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Game.Hud (Hud, mkHud, render, height) where

import Game.BitmapFont qualified as BM
import Game.Sprites qualified as S
import Game.State qualified as GS
import SDL qualified

height :: Int
height = 16

data Hud = Hud S.Sprite BM.BitmapFont

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 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)