aboutsummaryrefslogtreecommitdiff
path: root/src/Game.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-06 12:17:33 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-06 12:17:33 +0000
commit049432fe1ffa4724f714a046adf21677a308f33f (patch)
treeacaefd9dc3a42d81bb014f6297c17d837249e10f /src/Game.hs
parent116c1db2b45bac6db66119825d316662f6eb913c (diff)
downloadspace-plat-hs-049432fe1ffa4724f714a046adf21677a308f33f.tar.gz
space-plat-hs-049432fe1ffa4724f714a046adf21677a308f33f.zip
Wrap entities operations on a type
Diffstat (limited to 'src/Game.hs')
-rw-r--r--src/Game.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Game.hs b/src/Game.hs
index 28e14e7..667053d 100644
--- a/src/Game.hs
+++ b/src/Game.hs
@@ -39,7 +39,7 @@ data Env = Env
_controls :: IORef C.Controls,
_map :: M.Map,
_sprites :: S.SpriteSheet,
- _entities :: IORef [E.Entity]
+ _entities :: IORef E.Entities
}
defaultRenderRect :: SDL.Rectangle CInt
@@ -69,9 +69,9 @@ main = do
controls <- newIORef =<< C.init
map' <- M.load "data/map.json" tsTexture
sprites <- S.load "data/sprites.json" ssTexture
- entities <- newIORef ([] :: [E.Entity])
+ entities <- newIORef $ E.mkEntities sprites
player <- E.mkPlayer sprites 32 104 controls (M.isBlocked map')
- entities $~ (player :)
+ entities $~ E.append player
runReaderT gameLoop (Env window renderer canvas fullscreen renderRect controls map' sprites entities)
SDL.destroyWindow window
SDL.quit
@@ -110,7 +110,6 @@ gameLoop = do
controls = _controls env
map' = _map env
entities = _entities env
- sprites = _sprites env
events <- map SDL.eventPayload <$> SDL.pollEvents
@@ -126,13 +125,13 @@ gameLoop = do
SDL.rendererRenderTarget renderer $= Just canvas
SDL.clear renderer
- updated <- liftIO $ E.update sprites =<< readIORef entities
+ updated <- liftIO $ E.update =<< readIORef entities
entities $= updated
-- render map and entities
void $ liftIO $ do
M.render renderer map'
- traverse (E.render renderer) updated
+ E.render renderer updated
SDL.rendererRenderTarget renderer $= Nothing
rect <- SDL.get renderRect