aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Map.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-26 08:49:35 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-03-26 08:49:35 +0100
commit449dc21f1b48648c5e4abf1a6cace21176fa2226 (patch)
tree18b67359934694de20199e207dd0c9b33990e945 /src/Game/Map.hs
parent11d2ed7f15a86dd465bc3456e3478e9ff03bf5d2 (diff)
downloadspace-plat-hs-449dc21f1b48648c5e4abf1a6cace21176fa2226.tar.gz
space-plat-hs-449dc21f1b48648c5e4abf1a6cace21176fa2226.zip
Support entities facing left
Perhaps it would be better to support "custom properties" in tiled, but this is OK for now.
Diffstat (limited to 'src/Game/Map.hs')
-rw-r--r--src/Game/Map.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Game/Map.hs b/src/Game/Map.hs
index 3fb72f9..ea20b17 100644
--- a/src/Game/Map.hs
+++ b/src/Game/Map.hs
@@ -14,6 +14,7 @@ where
import Control.Monad
import Data.Maybe (fromMaybe, mapMaybe)
+import Game.Entities.Types (Dir (..))
import qualified Game.Utils as U
import SDL (($=))
import qualified SDL
@@ -39,8 +40,8 @@ data Layer
data Object
= PlayerEntity Int Int
| BatteryEntity Int Int
- | SlimeEntity Int Int
- | RobotEntity Int Int
+ | SlimeEntity Int Int Dir
+ | RobotEntity Int Int Dir
deriving (Show, Eq, Ord)
data JsonMapData = JsonMapData
@@ -81,9 +82,13 @@ instance JSON Object where
Just "Battery" ->
BatteryEntity <$> valFromObj "x" obj <*> valFromObj "y" obj
Just "Slime" ->
- SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj
+ SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
Just "Robot" ->
- RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj
+ RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirRight
+ Just "Slime-l" ->
+ SlimeEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
+ Just "Robot-l" ->
+ RobotEntity <$> valFromObj "x" obj <*> valFromObj "y" obj <*> pure DirLeft
Just (JSString (JSONString s)) -> Error $ "unsupported entity " ++ show s
e -> Error $ "unsupported entity in " ++ show e
readJSON _ = mzero