From ff78a6ecfe368e13a8c0d9e1a11c02a2ead62dec Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 27 Jun 2019 22:02:47 +0200 Subject: [PATCH] improvement(actor): put gravity that make sense functions in baseactor --- gamecore/modules/world/actors/actor2D.lua | 18 ------------- gamecore/modules/world/actors/baseactor.lua | 29 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 0427935..37c0c38 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -117,27 +117,9 @@ function Actor2D:checkCollision(dx, dy) return self.x, self.y, cols, colNumber 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 -- 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) self.ysp = self.ysp + self.grav * dt diff --git a/gamecore/modules/world/actors/baseactor.lua b/gamecore/modules/world/actors/baseactor.lua index 7a1269b..61b7827 100644 --- a/gamecore/modules/world/actors/baseactor.lua +++ b/gamecore/modules/world/actors/baseactor.lua @@ -132,6 +132,35 @@ function BaseActor:getViewCenter() return self:getCenter() 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 -- Theses functions are activated every steps