From 18d75f825c59aa75a1499737e9b498536db1e966 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 1 May 2019 14:36:40 +0200 Subject: [PATCH] modules/world: separate map loading from level initialization --- examples/basic/test_scene2/init.lua | 2 ++ examples/gameplay/moveplayer/init.lua | 2 ++ examples/gameplay/plateform/init.lua | 1 + gamecore/modules/world/baseworld.lua | 34 +++++++++++++++++---------- gamecore/modules/world/world2D.lua | 2 +- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/examples/basic/test_scene2/init.lua b/examples/basic/test_scene2/init.lua index c63f938..baab487 100644 --- a/examples/basic/test_scene2/init.lua +++ b/examples/basic/test_scene2/init.lua @@ -40,6 +40,8 @@ function TestScene:new() self.world:newActor("explosion", 12, 12) self.world:newActor("explosion", 1, 78) self.world:newActor("explosion", 40, 200) + + self.world:loadMap() end function TestScene:update(dt) diff --git a/examples/gameplay/moveplayer/init.lua b/examples/gameplay/moveplayer/init.lua index 5444d5b..de53582 100644 --- a/examples/gameplay/moveplayer/init.lua +++ b/examples/gameplay/moveplayer/init.lua @@ -33,6 +33,8 @@ function MovePlayer:new() self.world:addPlayer(self.world.obj.Player(self.world, 16, 16, 1), 1, true) self.world:addPlayer(self.world.obj.Player(self.world, 424 - 16, 16, 2), 2, true) + + self.world:loadMap() end function MovePlayer:update(dt) diff --git a/examples/gameplay/plateform/init.lua b/examples/gameplay/plateform/init.lua index d03a06c..9fb2963 100644 --- a/examples/gameplay/plateform/init.lua +++ b/examples/gameplay/plateform/init.lua @@ -34,6 +34,7 @@ function Plateformer:new() self.assets:batchImport("examples.gameplay.plateform.assets") self.world = World(self, folder .. ".actors", "examples/gameplay/plateform/assets/platformer.lua") + self.world:loadMap() end function Plateformer:update(dt) diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 98cd17d..a90d00a 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -40,7 +40,7 @@ function BaseWorld:new(scene, actorlist, mapfile) self:initPlayers() self:setActorList(actorlist) - self:setMap(mapfile) + self:initMap(mapfile) end function BaseWorld:setActorList(actorlist) @@ -51,18 +51,11 @@ function BaseWorld:setActorList(actorlist) end end -function BaseWorld:setMap(mapfile) - if mapfile == nil then - self.haveMap = false - self.haveBackgroundColor = false - self.backcolor = {128, 128, 128} - else - self.haveMap = true - self.map = Sti(mapfile) - self.haveBackgroundColor = true - self.backcolor = self.map.backgroundcolor or {128, 128, 128} - self:loadMapObjects() - end +function BaseWorld:initMap(mapfile) + self.haveMap = false + self.haveBackgroundColor = false + self.backcolor = {128, 128, 128} + self.mapfile = mapfile end -- ACTOR MANAGEMENT FUNCTIONS @@ -130,6 +123,21 @@ end -- PLAYER MANAGEMENT FUNCTIONS -- Basic function to handle player actors +function BaseWorld:loadMap() + local mapfile = self.mapfile + if mapfile == nil then + self.haveMap = false + self.haveBackgroundColor = false + self.backcolor = {128, 128, 128} + else + self.haveMap = true + self.map = Sti(mapfile) + self.haveBackgroundColor = true + self.backcolor = self.map.backgroundcolor or {128, 128, 128} + self:loadMapObjects() + end +end + function BaseWorld:initPlayers() self.players = {} end diff --git a/gamecore/modules/world/world2D.lua b/gamecore/modules/world/world2D.lua index fd19969..de4136f 100644 --- a/gamecore/modules/world/world2D.lua +++ b/gamecore/modules/world/world2D.lua @@ -38,7 +38,7 @@ function World2D:new(scene, actorlist, mapfile) self:initPlayers() self:setActorList(actorlist) - self:setMap(mapfile) + self:initMap(mapfile) end -- ACTORS FUNCTIONS