From 23f17491add334aa1f18a9d3219ed3598e3b7ca8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 28 May 2019 19:28:05 +0200 Subject: [PATCH] gamecore/world: make the world registerable directly by itself --- examples/basic/test_scene2/init.lua | 3 ++- examples/gameplay/moveplayer/init.lua | 2 +- examples/gameplay/plateform/init.lua | 3 ++- gamecore/modules/scenes.lua | 13 +++++++++++++ gamecore/modules/world/baseworld.lua | 6 ++++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/examples/basic/test_scene2/init.lua b/examples/basic/test_scene2/init.lua index baab487..54ce290 100644 --- a/examples/basic/test_scene2/init.lua +++ b/examples/basic/test_scene2/init.lua @@ -36,7 +36,8 @@ function TestScene:new() self.i = 0 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", 1, 78) self.world:newActor("explosion", 40, 200) diff --git a/examples/gameplay/moveplayer/init.lua b/examples/gameplay/moveplayer/init.lua index c5dd94b..bc59962 100644 --- a/examples/gameplay/moveplayer/init.lua +++ b/examples/gameplay/moveplayer/init.lua @@ -29,7 +29,7 @@ local World = require "gamecore.modules.world.world2D" function MovePlayer:new() 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) diff --git a/examples/gameplay/plateform/init.lua b/examples/gameplay/plateform/init.lua index 9fb2963..500fc36 100644 --- a/examples/gameplay/plateform/init.lua +++ b/examples/gameplay/plateform/init.lua @@ -33,7 +33,8 @@ function Plateformer:new() 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() end diff --git a/gamecore/modules/scenes.lua b/gamecore/modules/scenes.lua index 02d6a23..c59af76 100644 --- a/gamecore/modules/scenes.lua +++ b/gamecore/modules/scenes.lua @@ -43,6 +43,8 @@ function Scene:new() self.inputLocked = false self.inputLockedTimer = 0 + self:initWorld() + self:register() end @@ -72,6 +74,17 @@ function Scene:mousepressed( x, y, button, istouch ) -- Empty function, is just here to avoid crash 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 -- Add send keys functions to the scene diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 28ea22e..11b9ca0 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -42,6 +42,8 @@ function BaseWorld:new(scene, actorlist, mapfile) self:setActorList(actorlist) self:initMap(mapfile) self:setGravity() + + self:register() end function BaseWorld:setActorList(actorlist) @@ -69,6 +71,10 @@ function BaseWorld:setGravity(xgrav, ygrav, isDefault) self.gravity.isDefault = isDefault end +function BaseWorld:register() + self.scene:registerWorld(self) +end + -- ACTOR MANAGEMENT FUNCTIONS -- Basic function to handle actors