From cd62f9c7d1f8674ebde2db204d47da4ae1810662 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 May 2019 20:49:28 +0200 Subject: [PATCH] modules/world: put basic initilisation in baseactor --- gamecore/modules/world/actors/actor2D.lua | 29 +-------------------- gamecore/modules/world/actors/baseactor.lua | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 13c9e16..a7501aa 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -33,28 +33,11 @@ local Timer = require(cwd .. "utils.timer") function Actor2D:new(world, type, x, y, w, h, isSolid) Actor2D.super.new(self, world, type) - self:setManagers(world) self:initPhysics(x, y, w, h, isSolid) + self:register() self:initKeys() - self:register() self:initTimers() - - self:setDebugColor(1, 1, 1) -end - -function Actor2D:setManagers(world) - self.world = world - self.scene = world.scene - self.obj = world.obj - self.assets = self.scene.assets -end - -function Actor2D:setDebugColor(r,g,b) - self.debug = {} - self.debug.r = r - self.debug.g = g - self.debug.b = b end function Actor2D:initPhysics(x, y, w, h, isSolid) @@ -78,20 +61,10 @@ function Actor2D:initPhysics(x, y, w, h, isSolid) self:setSprite() end -function Actor2D:register() - self.world:registerActor(self) - self.isDestroyed = false -end - function Actor2D:setBounceFactor(newBounceFactor) self.bounceFactor = newBounceFactor or 0 end -function Actor2D:destroy() - self.world:removeActor(self) - self.isDestroyed = true -end - -- INPUT FUNCTIONS -- get input from the world object diff --git a/gamecore/modules/world/actors/baseactor.lua b/gamecore/modules/world/actors/baseactor.lua index ad77b79..57dcade 100644 --- a/gamecore/modules/world/actors/baseactor.lua +++ b/gamecore/modules/world/actors/baseactor.lua @@ -24,9 +24,38 @@ local BaseActor = Object:extend() +-- INIT FUNCTIONS +-- Initialise the actor and its base functions + function BaseActor:new(world, type) self.type = type or "" + self:setManagers(world) + self:setDebugColor(1, 1, 1) +end + +function BaseActor:setManagers(world) + self.world = world + self.scene = world.scene + self.obj = world.obj + self.assets = self.scene.assets +end + +function BaseActor:setDebugColor(r,g,b) + self.debug = {} + self.debug.r = r + self.debug.g = g + self.debug.b = b +end + +function BaseActor:register() + self.world:registerActor(self) + self.isDestroyed = false +end + +function BaseActor:destroy() + self.world:removeActor(self) + self.isDestroyed = true end return BaseActor