From 6e48bd38850f6326fe435ff87af3ca14e6707379 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 9 Feb 2023 23:25:05 +0000 Subject: Spawn objects For now only the Player. --- src/Game.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Game.hs') diff --git a/src/Game.hs b/src/Game.hs index 463ef27..8cdd45f 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -45,6 +45,13 @@ data Env = Env defaultRenderRect :: SDL.Rectangle CInt defaultRenderRect = SDL.Rectangle (SDL.P $ V2 0 0) (V2 windowWidth windowHeight) +spawn :: M.Map -> S.SpriteSheet -> IORef C.Controls -> IO [E.Entity] +spawn m sprites controls = + traverse toEntity $ M.objects m + where + toEntity :: M.MapObject -> IO E.Entity + toEntity (M.PlayerEntity x y) = E.mkPlayer sprites x y controls (M.isBlocked m) + main :: IO () main = do SDL.initialize [SDL.InitVideo, SDL.InitGameController] @@ -70,8 +77,8 @@ main = do map' <- M.load "data/map.json" tsTexture sprites <- S.load "data/sprites.json" ssTexture entities <- newIORef $ E.mkEntities sprites - player <- E.mkPlayer sprites 32 104 controls (M.isBlocked map') - entities $~ E.append player + spawned <- spawn map' sprites controls + entities $~ flip E.add spawned runReaderT gameLoop Env -- cgit v1.2.3