chore(actor2D): group gravity functions together
This commit is contained in:
parent
e916c28630
commit
0a66082e99
1 changed files with 16 additions and 13 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue