From 9f1811975e996a3bf70c3e834a872e59c8ade984 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 14 Apr 2023 08:37:14 +0100 Subject: Load the map list from a JSON file --- src/Game.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/Game.hs') diff --git a/src/Game.hs b/src/Game.hs index be34a08..c2f6083 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -32,10 +32,6 @@ windowWidth, windowHeight :: CInt version :: String version = "0.1.0" --- XXX: placeholder for the map list, perhaps should be loaded from a JSON -maps :: [String] -maps = ["data/map1.json", "data/map2.json"] - data Env = Env { window :: SDL.Window, renderer :: SDL.Renderer, @@ -43,6 +39,7 @@ data Env = Env fullscreen :: Bool, renderRect :: SDL.Rectangle CInt, tsTexture :: SDL.Texture, + mapList :: [String], map :: M.Map, sprites :: S.SpriteSheet, font :: BF.BitmapFont, @@ -75,7 +72,8 @@ main = do tsTexture <- SDL.Image.loadTexture renderer "data/tiles.png" ssTexture <- SDL.Image.loadTexture renderer "data/sprites.png" bfTexture <- SDL.Image.loadTexture renderer "data/font.png" - map' <- M.load (head maps) tsTexture + mapList <- M.loadMapList "data/maps.json" + map' <- M.load (head mapList) tsTexture sprites <- S.load "data/sprites.json" ssTexture font <- BF.load "data/font.json" bfTexture controls <- newIORef C.init @@ -89,6 +87,7 @@ main = do fullscreen = False, renderRect = defaultRenderRect, tsTexture = tsTexture, + mapList = mapList, map = map', sprites = sprites, font = font, @@ -167,7 +166,7 @@ gameLoop e = do es <- E.addExit env.entities x (y - 8) -- adjusted to player's height pure env {entities = es, state = state {GS.exit = True}} | state.levelCompleted == GS.ExitDone = do - map' <- M.load (maps !! (env.state.currentLevel + 1)) env.tsTexture + map' <- M.load (env.mapList !! (env.state.currentLevel + 1)) env.tsTexture entities <- E.mkEntities env.sprites map' env.controls pure $ env -- cgit v1.2.3