gamecore/world: make the world registerable directly by itself

This commit is contained in:
Kazhnuz 2019-05-28 19:28:05 +02:00
parent 5e95099af9
commit 23f17491ad
5 changed files with 24 additions and 3 deletions

View file

@ -36,7 +36,8 @@ function TestScene:new()
self.i = 0 self.i = 0
self.estImpair = false self.estImpair = false
self.world = World(self, "examples.basic.test_scene2.actors") World(self, "examples.basic.test_scene2.actors")
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)

View file

@ -29,7 +29,7 @@ local World = require "gamecore.modules.world.world2D"
function MovePlayer:new() function MovePlayer:new()
MovePlayer.super.new(self) MovePlayer.super.new(self)
self.world = World(self, "examples.gameplay.moveplayer.actors", "examples/gameplay/moveplayer/assets/arena.lua") World(self, "examples.gameplay.moveplayer.actors", "examples/gameplay/moveplayer/assets/arena.lua")
self.world:setPlayerNumber(4) self.world:setPlayerNumber(4)

View file

@ -33,7 +33,8 @@ 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") World(self, folder .. ".actors", "examples/gameplay/plateform/assets/platformer.lua")
self.world:loadMap() self.world:loadMap()
end end

View file

@ -43,6 +43,8 @@ function Scene:new()
self.inputLocked = false self.inputLocked = false
self.inputLockedTimer = 0 self.inputLockedTimer = 0
self:initWorld()
self:register() self:register()
end end
@ -72,6 +74,17 @@ function Scene:mousepressed( x, y, button, istouch )
-- Empty function, is just here to avoid crash -- Empty function, is just here to avoid crash
end end
-- WORLD FUNCTIONS
-- Basic functions to manage the world
function Scene:initWorld()
self.world = nil
end
function Scene:registerWorld(world)
self.world = world
end
-- KEYBOARD FUNCTIONS -- KEYBOARD FUNCTIONS
-- Add send keys functions to the scene -- Add send keys functions to the scene

View file

@ -42,6 +42,8 @@ function BaseWorld:new(scene, actorlist, mapfile)
self:setActorList(actorlist) self:setActorList(actorlist)
self:initMap(mapfile) self:initMap(mapfile)
self:setGravity() self:setGravity()
self:register()
end end
function BaseWorld:setActorList(actorlist) function BaseWorld:setActorList(actorlist)
@ -69,6 +71,10 @@ function BaseWorld:setGravity(xgrav, ygrav, isDefault)
self.gravity.isDefault = isDefault self.gravity.isDefault = isDefault
end end
function BaseWorld:register()
self.scene:registerWorld(self)
end
-- ACTOR MANAGEMENT FUNCTIONS -- ACTOR MANAGEMENT FUNCTIONS
-- Basic function to handle actors -- Basic function to handle actors