improvement(actor): put gravity that make sense functions in baseactor
This commit is contained in:
parent
10bbd5fd84
commit
ff78a6ecfe
2 changed files with 29 additions and 18 deletions
|
@ -117,27 +117,9 @@ function Actor2D:checkCollision(dx, dy)
|
||||||
return self.x, self.y, cols, colNumber
|
return self.x, self.y, cols, colNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:initGravity()
|
|
||||||
if (self.world.gravity.isDefault) then
|
|
||||||
self.grav = self.world.gravity.grav
|
|
||||||
else
|
|
||||||
self.grav = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
self.onGround = false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- GRAVITY SYSTEM FUNCTIONS
|
-- GRAVITY SYSTEM FUNCTIONS
|
||||||
-- All functions related to gravity
|
-- All functions related to gravity
|
||||||
|
|
||||||
function Actor2D:setGravity(grav)
|
|
||||||
-- It's basically now a function with two roles at once :
|
|
||||||
-- - activate the gravity
|
|
||||||
-- - use the gravity value the dev want
|
|
||||||
|
|
||||||
self.grav = grav or self.world.gravity.grav
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:applyGravity(dt)
|
function Actor2D:applyGravity(dt)
|
||||||
self.ysp = self.ysp + self.grav * dt
|
self.ysp = self.ysp + self.grav * dt
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,35 @@ function BaseActor:getViewCenter()
|
||||||
return self:getCenter()
|
return self:getCenter()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- GRAVITY SYSTEM FUNCTIONS
|
||||||
|
-- All functions related to gravity
|
||||||
|
|
||||||
|
function BaseActor:initGravity()
|
||||||
|
if (self.world.gravity.isDefault) then
|
||||||
|
self.grav = self.world.gravity.grav
|
||||||
|
else
|
||||||
|
self.grav = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
self.onGround = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:setGravity(grav)
|
||||||
|
-- It's basically now a function with two roles at once :
|
||||||
|
-- - activate the gravity
|
||||||
|
-- - use the gravity value the dev want
|
||||||
|
|
||||||
|
self.grav = grav or self.world.gravity.grav
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:applyGravity(dt)
|
||||||
|
-- Empty function in baseactor
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:checkGround()
|
||||||
|
-- Empty function in baseactor
|
||||||
|
end
|
||||||
|
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
-- Theses functions are activated every steps
|
-- Theses functions are activated every steps
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue