diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-02-09 23:25:05 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-02-09 23:25:05 +0000 |
commit | 6e48bd38850f6326fe435ff87af3ca14e6707379 (patch) | |
tree | 6db157869c0df517e7b0629d0445bbf418f43a3b /src/Game.hs | |
parent | 84057b11507a1434a9f189bca2fdb71df294c572 (diff) | |
download | space-plat-hs-6e48bd38850f6326fe435ff87af3ca14e6707379.tar.gz space-plat-hs-6e48bd38850f6326fe435ff87af3ca14e6707379.zip |
Spawn objects
For now only the Player.
Diffstat (limited to 'src/Game.hs')
-rw-r--r-- | src/Game.hs | 11 |
1 files changed, 9 insertions, 2 deletions
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 |