aboutsummaryrefslogtreecommitdiff
path: root/src/Game
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-09 23:43:14 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-09 23:43:14 +0000
commit04c2839de5b860ff0efe957e2be9a21dbdfa329a (patch)
treef179999988414fc8fff62b0e50d9d15d0e813f1b /src/Game
parent6e48bd38850f6326fe435ff87af3ca14e6707379 (diff)
downloadspace-plat-hs-04c2839de5b860ff0efe957e2be9a21dbdfa329a.tar.gz
space-plat-hs-04c2839de5b860ff0efe957e2be9a21dbdfa329a.zip
Make entities in the map module
This needs to be reviewed.
Diffstat (limited to 'src/Game')
-rw-r--r--src/Game/Map.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Game/Map.hs b/src/Game/Map.hs
index b4d848e..9596b14 100644
--- a/src/Game/Map.hs
+++ b/src/Game/Map.hs
@@ -1,15 +1,18 @@
module Game.Map
( Map,
- MapObject (..),
- objects,
load,
+ mkEntities,
render,
isBlocked,
)
where
import Control.Monad
+import Data.IORef
import Data.Maybe (mapMaybe)
+import qualified Game.Controller as C
+import qualified Game.Entities as E
+import qualified Game.Sprites as S
import qualified Game.Utils as U
import qualified SDL
import Text.JSON
@@ -133,9 +136,12 @@ 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
+mkEntities :: Map -> S.SpriteSheet -> IORef C.Controls -> IO [E.Entity]
+mkEntities m@(Map md _) sprites controls =
+ traverse toEntity $ md.objects
+ where
+ toEntity :: MapObject -> IO E.Entity
+ toEntity (PlayerEntity x y) = E.mkPlayer sprites x y controls (isBlocked m)
-- | Renders a map.
render :: SDL.Renderer -> Map -> IO ()