modules/world: put basic initilisation in baseactor

This commit is contained in:
Kazhnuz 2019-05-05 20:49:28 +02:00
parent 1b5a2e9c6e
commit cd62f9c7d1
2 changed files with 30 additions and 28 deletions

View file

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

View file

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