modules/world: separate map loading from level initialization

This commit is contained in:
Kazhnuz 2019-05-01 14:36:40 +02:00
parent 98fb57afaa
commit 18d75f825c
5 changed files with 27 additions and 14 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -38,7 +38,7 @@ function World2D:new(scene, actorlist, mapfile)
self:initPlayers()
self:setActorList(actorlist)
self:setMap(mapfile)
self:initMap(mapfile)
end
-- ACTORS FUNCTIONS