From 0a66082e99d5d44ec05faf11a35b682c416cd61b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 27 Jun 2019 21:05:23 +0200 Subject: [PATCH] chore(actor2D): group gravity functions together --- gamecore/modules/world/actors/actor2D.lua | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 1838669..a201ea4 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -98,19 +98,6 @@ function Actor2D:changeSpeedToCollisionNormal(nx, ny) self.xsp, self.ysp = xsp, ysp end -function Actor2D:checkGround() - local dx, dy = self.x, self.y + utils.math.sign(self.grav) - local newx, newy, cols, colNumber = self:checkCollision(dx, dy) - - for i, col in ipairs(cols) do - if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then - if not (self.grav == 0) then - if col.normal.y ~= utils.math.sign(self.grav) then self.onGround = true end - end - end - end -end - function Actor2D:move(dx, dy) local cols, colNumber = {}, 0 if (self.isDestroyed == false) then @@ -138,6 +125,9 @@ function Actor2D:initGravity() 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 @@ -154,6 +144,19 @@ function Actor2D:applyGravity(dt) end end +function Actor2D:checkGround() + local dx, dy = self.x, self.y + utils.math.sign(self.grav) + local newx, newy, cols, colNumber = self:checkCollision(dx, dy) + + for i, col in ipairs(cols) do + if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then + if not (self.grav == 0) then + if col.normal.y ~= utils.math.sign(self.grav) then self.onGround = true end + end + end + end +end + -- HITBOXES FUNCTIONS -- Functions related to actor hitboxes