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 | |
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')
-rw-r--r-- | src/Game/Entities.hs | 6 | ||||
-rw-r--r-- | src/Game/Map.hs | 7 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs index 96cc4fa..7d29e41 100644 --- a/src/Game/Entities.hs +++ b/src/Game/Entities.hs @@ -1,4 +1,4 @@ -module Game.Entities (Entities, mkEntities, mkPlayer, mkEffect, append, updateAll, render) where +module Game.Entities (Entities, Entity, mkEntities, mkPlayer, mkEffect, add, updateAll, render) where import Data.Foldable (traverse_) import Data.IORef @@ -59,8 +59,8 @@ data Entity = Entity mkEntities :: S.SpriteSheet -> Entities mkEntities sprites = Entities sprites [] -append :: Entity -> Entities -> Entities -append e (Entities sprites entities) = Entities sprites (entities ++ [e]) +add :: Entities -> [Entity] -> Entities +add (Entities sprites entities) es = Entities sprites (entities ++ es) processSpawn :: S.SpriteSheet -> Spawn -> IO Entity processSpawn sprites (DustEffectSpawn x y) = mkEffect sprites x y "dust" diff --git a/src/Game/Map.hs b/src/Game/Map.hs index a1c7e84..b4d848e 100644 --- a/src/Game/Map.hs +++ b/src/Game/Map.hs @@ -1,5 +1,7 @@ module Game.Map ( Map, + MapObject (..), + objects, load, render, isBlocked, @@ -28,6 +30,7 @@ data Layer {name :: String, objects :: [MapObject]} deriving (Show) +-- | The object types in the map. data MapObject = PlayerEntity Int Int deriving (Show) data JsonMapData = JsonMapData @@ -130,6 +133,10 @@ isBlocked :: Map -> Int -> Int -> Bool isBlocked (Map (MapData mapWidth _ ts _ blocked _) _) x y = blocked !! ((x `div` ts.width) + (y `div` ts.height) * mapWidth) >= ts.firstGid +-- | Returns the objects in the map. +objects :: Map -> [MapObject] +objects (Map md _) = md.objects + -- | Renders a map. render :: SDL.Renderer -> Map -> IO () render renderer (Map mapData tex) = do |