diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-02-26 00:26:54 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-02-26 00:26:54 +0000 |
commit | 9b04633e09a80d33456f545baf1fa910f0986db7 (patch) | |
tree | 28554c66d557cb16b1281f07abb9c083aca12589 | |
parent | b3e0ace3ca198cacd8d77c6ca0f2c457826dee63 (diff) | |
download | space-plat-hs-9b04633e09a80d33456f545baf1fa910f0986db7.tar.gz space-plat-hs-9b04633e09a80d33456f545baf1fa910f0986db7.zip |
Draw the HUB on the top of the screen
-rw-r--r-- | src/Game.hs | 5 | ||||
-rw-r--r-- | src/Game/Hud.hs | 4 | ||||
-rw-r--r-- | src/Game/Map.hs | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/Game.hs b/src/Game.hs index a1f0e2a..85445b8 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -180,15 +180,18 @@ gameLoop = do map' = env.map entities = env.entities hud = env.hud + mapRect = U.rect 0 (fromIntegral gameHeight - M.height map') (fromIntegral gameWidth) (M.height map') updated <- E.updateAll =<< readIORef entities entities $= updated -- render map and entities void $ do + SDL.rendererViewport renderer $= Just mapRect M.render renderer map' - H.render renderer hud E.render renderer updated + SDL.rendererViewport renderer $= Nothing + H.render renderer hud gameOverLoop :: Env -> IO () gameOverLoop env = do diff --git a/src/Game/Hud.hs b/src/Game/Hud.hs index dd72bb3..1e51993 100644 --- a/src/Game/Hud.hs +++ b/src/Game/Hud.hs @@ -19,6 +19,6 @@ render :: SDL.Renderer -> Hud -> IO () render renderer hud = do state <- readIORef hud.stateRef let xs = [0 .. state.totalBatteries - 1] - in mapM_ (\x -> S.render renderer hud.sprite (4 + x * 8) 178 0 (if state.batteries <= x then 0 else 1)) xs + in mapM_ (\x -> S.render renderer hud.sprite (4 + x * 8) 4 0 (if state.batteries <= x then 0 else 1)) xs let xs = [0 .. state.totalLives - 1] - in mapM_ (\x -> S.render renderer hud.sprite (320 - 4 - state.totalLives * 8 + x * 8) 178 0 (if state.lives <= x then 2 else 3)) xs + in mapM_ (\x -> S.render renderer hud.sprite (320 - 4 - state.totalLives * 8 + x * 8) 4 0 (if state.lives <= x then 2 else 3)) xs diff --git a/src/Game/Map.hs b/src/Game/Map.hs index 47dc31c..e1dd673 100644 --- a/src/Game/Map.hs +++ b/src/Game/Map.hs @@ -2,6 +2,7 @@ module Game.Map ( Map (..), Object (..), objects, + height, totalBatteries, load, render, @@ -154,6 +155,9 @@ isPlayer :: Object -> Bool isPlayer (PlayerEntity _ _) = True isPlayer _ = False +height :: Map -> Int +height (Map md _) = md.height * md.tileset.height + -- | Return the number of batteries in a map. totalBatteries :: Map -> Int totalBatteries m = length $ filter isBattery (objects m) |