improvement(actor): put gravity that make sense functions in baseactor

This commit is contained in:
Kazhnuz 2019-06-27 22:02:47 +02:00
parent 10bbd5fd84
commit ff78a6ecfe
2 changed files with 29 additions and 18 deletions

View file

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

View file

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