From 973961a0ced31c30f0e7e5abc618aaca6c8452b8 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 1 Mar 2023 07:27:50 +0000 Subject: Scroll using SDL's viewport Horizontal needs testing. --- src/Game.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Game.hs') 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 -- cgit v1.2.3