big-refactor #106

Merged
kazhnuz merged 24 commits from big-refactor into master 2021-05-07 19:30:53 +02:00
7 changed files with 21 additions and 21 deletions
Showing only changes of commit c17338174b - Show all commits

View file

@ -92,16 +92,16 @@ end
function Actor2D:move(dx, dy)
local cols, colNumber = {}, 0
if (self.isDestroyed == false) then
self.x, self.y, cols, colNumber = self.mainHitbox:checkCollision(dx, dy, self.filter)
self.x, self.y, cols, colNumber = self.mainHitbox:checkCollisionAtPoint(dx, dy, self.filter)
self.mainHitbox:updatePosition()
end
return self.x, self.y, cols, colNumber
end
function Actor2D:checkCollision(dx, dy)
function Actor2D:checkCollisionAtPoint(dx, dy)
local x, y, cols, colNumber = dx, dy, {}, 0
if (self.isDestroyed == false) then
x, y, cols, colNumber = self.mainHitbox:checkCollision(dx, dy, self.filter)
x, y, cols, colNumber = self.mainHitbox:checkCollisionAtPoint(dx, dy, self.filter)
end
return self.x, self.y, cols, colNumber
end
@ -119,7 +119,7 @@ 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)
local newx, newy, cols, colNumber = self:checkCollisionAtPoint(dx, dy)
for i, col in ipairs(cols) do
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
@ -146,14 +146,14 @@ function Actor2D:packForHitbox()
end
function Actor2D:checkHitboxCollisions(name, filter)
self:checkHitboxCollisionsAtPoint(name, self.x, self.y, filter)
self:applyHitboxCollisionsAtPoint(name, self.x, self.y, filter)
end
function Actor2D:checkHitboxCollisionsAtPoint(name, dx, dy, filter)
function Actor2D:applyHitboxCollisionsAtPoint(name, dx, dy, filter)
local x, y, cols, colNumber = dx, dy, {}, 0
local filter = filter or self.filter
if (self.isDestroyed == false) and (self.hitboxes[name] ~= nil) then
x, y, cols, colNumber = self.hitboxes[name]:checkCollision(dx, dy, filter)
x, y, cols, colNumber = self.hitboxes[name]:checkCollisionAtPoint(dx, dy, filter)
local type = self.hitboxes[name].type
for i, col in ipairs(cols) do

View file

@ -107,7 +107,7 @@ function Actor3D:move(dx, dy, dz)
local cols, colNumber = {}, 0
local oldx, oldy, oldz = self.x, self.y, self.z
if (self.isDestroyed == false) then
self.x, self.y, self.z, cols, colNumber = self.mainHitbox:checkCollision(dx, dy, dz, self.filter)
self.x, self.y, self.z, cols, colNumber = self.mainHitbox:checkCollisionAtPoint(dx, dy, dz, self.filter)
self.mainHitbox:updatePosition()
self.world:updateShape(self)
end
@ -121,10 +121,10 @@ function Actor3D:move(dx, dy, dz)
return self.x, self.y, self.z, cols, colNumber
end
function Actor3D:checkCollision(dx, dy, dz)
function Actor3D:checkCollisionAtPoint(dx, dy, dz)
local x, y, z, cols, colNumber = dx, dy, dz, {}, 0
if (self.isDestroyed == false) then
x, y, z, cols, colNumber = self.mainHitbox:checkCollision(dx, dy, dz, self.filter)
x, y, z, cols, colNumber = self.mainHitbox:checkCollisionAtPoint(dx, dy, dz, self.filter)
end
return self.x, self.y, self.z, cols, colNumber
end
@ -143,7 +143,7 @@ end
function Actor3D:checkGround()
local dx, dy, dz = self.x, self.y, self.z - utils.math.sign(self.grav)
local newx, newy, newz, cols, colNumber = self:checkCollision(dx, dy, dz)
local newx, newy, newz, cols, colNumber = self:checkCollisionAtPoint(dx, dy, dz)
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
@ -169,14 +169,14 @@ function Actor3D:packForHitbox()
end
function Actor3D:checkHitboxCollisions(name, filter)
self:checkHitboxCollisionsAtPoint(name, self.x, self.y, self.z, filter)
self:applyHitboxCollisionsAtPoint(name, self.x, self.y, self.z, filter)
end
function Actor3D:checkHitboxCollisionsAtPoint(name, dx, dy, dz, filter)
function Actor3D:applyHitboxCollisionsAtPoint(name, dx, dy, dz, filter)
local x, y, z, cols, colNumber = dx, dy, dz, {}, 0
local filter = filter or self.filter
if (self.isDestroyed == false) and (self.hitboxes[name] ~= nil) then
x, y, z, cols, colNumber = self.hitboxes[name]:checkCollision(dx, dy, dz, filter)
x, y, z, cols, colNumber = self.hitboxes[name]:checkCollisionAtPoint(dx, dy, dz, filter)
local type = self.hitboxes[name].type
for i, col in ipairs(cols) do

View file

@ -119,7 +119,7 @@ end
-- COLLISION FUNCTIONS
-- Handle Hitbox position
function Hitbox2D:checkCollision(dx, dy, filter)
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)
self:updatePosition()
local nx, ny = self.ox + dx, self.oy + dy
@ -147,7 +147,7 @@ function Hitbox2D:checkCollision(dx, dy, filter)
self.owner.ysp = 0
end
end
local x, y, cols, colNumber = self.world:checkCollision(self, nx, ny, filter)
local x, y, cols, colNumber = self.world:checkCollisionAtPoint(self, nx, ny, filter)
local newx, newy = self:getNewOwnerPosition(x, y)
return newx, newy, cols, colNumber

View file

@ -123,11 +123,11 @@ end
-- COLLISION FUNCTIONS
-- Handle Hitbox position
function Hitbox3D:checkCollision(dx, dy, dz, filter)
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
self:updatePosition()
local dx, dy = self.ox + dx, self.oy + dy, self.oz + dz
local x, y, z, cols, colNumber = self.world:checkCollision(self, dx, dy, dz, filter)
local x, y, z, cols, colNumber = self.world:checkCollisionAtPoint(self, dx, dy, dz, filter)
local newx, newy, newz = self:getNewOwnerPosition(x, y, z)
return newx, newy, newz, cols, colNumber

View file

@ -208,7 +208,7 @@ function BaseWorld:moveActor(actor, x, y, filter)
return x, y, {}, 0
end
function BaseWorld:checkCollision(actor, x, y, filter)
function BaseWorld:checkCollisionAtPoint(actor, x, y, filter)
-- as the baseworld have no collision function, we return empty collision
-- datas, but from the same type than bump2D will return
return x, y, {}, 0

View file

@ -77,7 +77,7 @@ function World2D:removeBody(body)
return self.bodies:remove(body)
end
function World2D:checkCollision(body, x, y, filter)
function World2D:checkCollisionAtPoint(body, x, y, filter)
return self.bodies:check(body, x, y, filter)
end

View file

@ -108,7 +108,7 @@ function World3D:removeBody(body)
return self.bodies:remove(body)
end
function World3D:checkCollision(body, x, y, z, filter)
function World3D:checkCollisionAtPoint(body, x, y, z, filter)
return self.bodies:check(body, x, y, z, filter)
end