diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-03-01 07:27:50 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-03-01 07:27:50 +0000 |
commit | 973961a0ced31c30f0e7e5abc618aaca6c8452b8 (patch) | |
tree | ba6d11b5a3e14e39568e3b49ec3c4550b5a825b9 /src/Game.hs | |
parent | 9efd5381a31d69a1122f101cbee03ad3a91ed4b3 (diff) | |
download | space-plat-hs-973961a0ced31c30f0e7e5abc618aaca6c8452b8.tar.gz space-plat-hs-973961a0ced31c30f0e7e5abc618aaca6c8452b8.zip |
Scroll using SDL's viewport
Horizontal needs testing.
Diffstat (limited to 'src/Game.hs')
-rw-r--r-- | src/Game.hs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Game.hs b/src/Game.hs index 85445b8..8f921e9 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -180,16 +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 + -- update the map viewport + let (px, py) = E.playerPosition updated + -- render map and entities void $ do - SDL.rendererViewport renderer $= Just mapRect - M.render renderer map' - E.render renderer updated + viewport <- M.viewport renderer map' px py (fromIntegral gameWidth) (fromIntegral gameHeight - H.height) + M.render renderer map' viewport + E.renderVisible renderer updated viewport SDL.rendererViewport renderer $= Nothing H.render renderer hud |