modules/world: put non-hitbox related physics function in baseactor
This commit is contained in:
parent
1e42fac57c
commit
2344bd5a9a
2 changed files with 35 additions and 23 deletions
|
@ -36,32 +36,9 @@ function Actor2D:new(world, type, x, y, w, h, isSolid)
|
||||||
self:register()
|
self:register()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:initPhysics()
|
|
||||||
self:initMovement()
|
|
||||||
self:setBounceFactor()
|
|
||||||
self:initGravity()
|
|
||||||
|
|
||||||
self:setFilter()
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:setBounceFactor(newBounceFactor)
|
|
||||||
self.bounceFactor = newBounceFactor or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- MOVEMENT FUNCTIONS
|
-- MOVEMENT FUNCTIONS
|
||||||
-- Basic functions from the movement.
|
-- Basic functions from the movement.
|
||||||
|
|
||||||
function Actor2D:setFilter()
|
|
||||||
-- Init the bump filter
|
|
||||||
self.filter = function(item, other)
|
|
||||||
if (other.isSolid) then
|
|
||||||
return "slide"
|
|
||||||
else
|
|
||||||
return "cross"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:initMovement()
|
function Actor2D:initMovement()
|
||||||
self.xsp = 0
|
self.xsp = 0
|
||||||
self.ysp = 0
|
self.ysp = 0
|
||||||
|
|
|
@ -66,6 +66,41 @@ function BaseActor:destroy()
|
||||||
self.isDestroyed = true
|
self.isDestroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- PHYSICS INITIALISATION
|
||||||
|
-- Basic initialization of the physic systems
|
||||||
|
|
||||||
|
function BaseActor:initPhysics()
|
||||||
|
self:initMovement()
|
||||||
|
self:initGravity()
|
||||||
|
|
||||||
|
self:setBounceFactor()
|
||||||
|
self:setFilter()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:setBounceFactor(newBounceFactor)
|
||||||
|
self.bounceFactor = newBounceFactor or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:setFilter()
|
||||||
|
-- Init the bump filter
|
||||||
|
self.filter = function(item, other)
|
||||||
|
if (other.isSolid) then
|
||||||
|
return "slide"
|
||||||
|
else
|
||||||
|
return "cross"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:initMovement( )
|
||||||
|
-- Empty placeholder function
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:initGravity( )
|
||||||
|
-- Empty placeholder function
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
-- Theses functions are activated every steps
|
-- Theses functions are activated every steps
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue