modules/world: separate map loading from level initialization
This commit is contained in:
parent
98fb57afaa
commit
18d75f825c
5 changed files with 27 additions and 14 deletions
|
@ -40,6 +40,8 @@ function TestScene:new()
|
||||||
self.world:newActor("explosion", 12, 12)
|
self.world:newActor("explosion", 12, 12)
|
||||||
self.world:newActor("explosion", 1, 78)
|
self.world:newActor("explosion", 1, 78)
|
||||||
self.world:newActor("explosion", 40, 200)
|
self.world:newActor("explosion", 40, 200)
|
||||||
|
|
||||||
|
self.world:loadMap()
|
||||||
end
|
end
|
||||||
|
|
||||||
function TestScene:update(dt)
|
function TestScene:update(dt)
|
||||||
|
|
|
@ -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, 16, 16, 1), 1, true)
|
||||||
self.world:addPlayer(self.world.obj.Player(self.world, 424 - 16, 16, 2), 2, true)
|
self.world:addPlayer(self.world.obj.Player(self.world, 424 - 16, 16, 2), 2, true)
|
||||||
|
|
||||||
|
self.world:loadMap()
|
||||||
end
|
end
|
||||||
|
|
||||||
function MovePlayer:update(dt)
|
function MovePlayer:update(dt)
|
||||||
|
|
|
@ -34,6 +34,7 @@ function Plateformer:new()
|
||||||
self.assets:batchImport("examples.gameplay.plateform.assets")
|
self.assets:batchImport("examples.gameplay.plateform.assets")
|
||||||
|
|
||||||
self.world = World(self, folder .. ".actors", "examples/gameplay/plateform/assets/platformer.lua")
|
self.world = World(self, folder .. ".actors", "examples/gameplay/plateform/assets/platformer.lua")
|
||||||
|
self.world:loadMap()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Plateformer:update(dt)
|
function Plateformer:update(dt)
|
||||||
|
|
|
@ -40,7 +40,7 @@ function BaseWorld:new(scene, actorlist, mapfile)
|
||||||
|
|
||||||
self:initPlayers()
|
self:initPlayers()
|
||||||
self:setActorList(actorlist)
|
self:setActorList(actorlist)
|
||||||
self:setMap(mapfile)
|
self:initMap(mapfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWorld:setActorList(actorlist)
|
function BaseWorld:setActorList(actorlist)
|
||||||
|
@ -51,18 +51,11 @@ function BaseWorld:setActorList(actorlist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWorld:setMap(mapfile)
|
function BaseWorld:initMap(mapfile)
|
||||||
if mapfile == nil then
|
self.haveMap = false
|
||||||
self.haveMap = false
|
self.haveBackgroundColor = false
|
||||||
self.haveBackgroundColor = false
|
self.backcolor = {128, 128, 128}
|
||||||
self.backcolor = {128, 128, 128}
|
self.mapfile = mapfile
|
||||||
else
|
|
||||||
self.haveMap = true
|
|
||||||
self.map = Sti(mapfile)
|
|
||||||
self.haveBackgroundColor = true
|
|
||||||
self.backcolor = self.map.backgroundcolor or {128, 128, 128}
|
|
||||||
self:loadMapObjects()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ACTOR MANAGEMENT FUNCTIONS
|
-- ACTOR MANAGEMENT FUNCTIONS
|
||||||
|
@ -130,6 +123,21 @@ end
|
||||||
-- PLAYER MANAGEMENT FUNCTIONS
|
-- PLAYER MANAGEMENT FUNCTIONS
|
||||||
-- Basic function to handle player actors
|
-- 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()
|
function BaseWorld:initPlayers()
|
||||||
self.players = {}
|
self.players = {}
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ function World2D:new(scene, actorlist, mapfile)
|
||||||
|
|
||||||
self:initPlayers()
|
self:initPlayers()
|
||||||
self:setActorList(actorlist)
|
self:setActorList(actorlist)
|
||||||
self:setMap(mapfile)
|
self:initMap(mapfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ACTORS FUNCTIONS
|
-- ACTORS FUNCTIONS
|
||||||
|
|
Loading…
Reference in a new issue