big-refactor #106
7 changed files with 21 additions and 21 deletions
|
@ -92,16 +92,16 @@ end
|
||||||
function Actor2D:move(dx, dy)
|
function Actor2D:move(dx, dy)
|
||||||
local cols, colNumber = {}, 0
|
local cols, colNumber = {}, 0
|
||||||
if (self.isDestroyed == false) then
|
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()
|
self.mainHitbox:updatePosition()
|
||||||
end
|
end
|
||||||
return self.x, self.y, cols, colNumber
|
return self.x, self.y, cols, colNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:checkCollision(dx, dy)
|
function Actor2D:checkCollisionAtPoint(dx, dy)
|
||||||
local x, y, cols, colNumber = dx, dy, {}, 0
|
local x, y, cols, colNumber = dx, dy, {}, 0
|
||||||
if (self.isDestroyed == false) then
|
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
|
end
|
||||||
return self.x, self.y, cols, colNumber
|
return self.x, self.y, cols, colNumber
|
||||||
end
|
end
|
||||||
|
@ -119,7 +119,7 @@ end
|
||||||
|
|
||||||
function Actor2D:checkGround()
|
function Actor2D:checkGround()
|
||||||
local dx, dy = self.x, self.y + utils.math.sign(self.grav)
|
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
|
for i, col in ipairs(cols) do
|
||||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||||
|
@ -146,14 +146,14 @@ function Actor2D:packForHitbox()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:checkHitboxCollisions(name, filter)
|
function Actor2D:checkHitboxCollisions(name, filter)
|
||||||
self:checkHitboxCollisionsAtPoint(name, self.x, self.y, filter)
|
self:applyHitboxCollisionsAtPoint(name, self.x, self.y, filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:checkHitboxCollisionsAtPoint(name, dx, dy, filter)
|
function Actor2D:applyHitboxCollisionsAtPoint(name, dx, dy, filter)
|
||||||
local x, y, cols, colNumber = dx, dy, {}, 0
|
local x, y, cols, colNumber = dx, dy, {}, 0
|
||||||
local filter = filter or self.filter
|
local filter = filter or self.filter
|
||||||
if (self.isDestroyed == false) and (self.hitboxes[name] ~= nil) then
|
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
|
local type = self.hitboxes[name].type
|
||||||
|
|
||||||
for i, col in ipairs(cols) do
|
for i, col in ipairs(cols) do
|
||||||
|
|
|
@ -107,7 +107,7 @@ function Actor3D:move(dx, dy, dz)
|
||||||
local cols, colNumber = {}, 0
|
local cols, colNumber = {}, 0
|
||||||
local oldx, oldy, oldz = self.x, self.y, self.z
|
local oldx, oldy, oldz = self.x, self.y, self.z
|
||||||
if (self.isDestroyed == false) then
|
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.mainHitbox:updatePosition()
|
||||||
self.world:updateShape(self)
|
self.world:updateShape(self)
|
||||||
end
|
end
|
||||||
|
@ -121,10 +121,10 @@ function Actor3D:move(dx, dy, dz)
|
||||||
return self.x, self.y, self.z, cols, colNumber
|
return self.x, self.y, self.z, cols, colNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor3D:checkCollision(dx, dy, dz)
|
function Actor3D:checkCollisionAtPoint(dx, dy, dz)
|
||||||
local x, y, z, cols, colNumber = dx, dy, dz, {}, 0
|
local x, y, z, cols, colNumber = dx, dy, dz, {}, 0
|
||||||
if (self.isDestroyed == false) then
|
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
|
end
|
||||||
return self.x, self.y, self.z, cols, colNumber
|
return self.x, self.y, self.z, cols, colNumber
|
||||||
end
|
end
|
||||||
|
@ -143,7 +143,7 @@ end
|
||||||
|
|
||||||
function Actor3D:checkGround()
|
function Actor3D:checkGround()
|
||||||
local dx, dy, dz = self.x, self.y, self.z - utils.math.sign(self.grav)
|
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
|
for i, col in ipairs(cols) do
|
||||||
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
if (col.type == "touch") or (col.type == "bounce") or (col.type == "slide") then
|
||||||
if not (self.grav == 0) then
|
if not (self.grav == 0) then
|
||||||
|
@ -169,14 +169,14 @@ function Actor3D:packForHitbox()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor3D:checkHitboxCollisions(name, filter)
|
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
|
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 x, y, z, cols, colNumber = dx, dy, dz, {}, 0
|
||||||
local filter = filter or self.filter
|
local filter = filter or self.filter
|
||||||
if (self.isDestroyed == false) and (self.hitboxes[name] ~= nil) then
|
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
|
local type = self.hitboxes[name].type
|
||||||
|
|
||||||
for i, col in ipairs(cols) do
|
for i, col in ipairs(cols) do
|
||||||
|
|
|
@ -119,7 +119,7 @@ end
|
||||||
-- COLLISION FUNCTIONS
|
-- COLLISION FUNCTIONS
|
||||||
-- Handle Hitbox position
|
-- Handle Hitbox position
|
||||||
|
|
||||||
function Hitbox2D:checkCollision(dx, dy, filter)
|
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)
|
||||||
self:updatePosition()
|
self:updatePosition()
|
||||||
|
|
||||||
local nx, ny = self.ox + dx, self.oy + dy
|
local nx, ny = self.ox + dx, self.oy + dy
|
||||||
|
@ -147,7 +147,7 @@ function Hitbox2D:checkCollision(dx, dy, filter)
|
||||||
self.owner.ysp = 0
|
self.owner.ysp = 0
|
||||||
end
|
end
|
||||||
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)
|
local newx, newy = self:getNewOwnerPosition(x, y)
|
||||||
|
|
||||||
return newx, newy, cols, colNumber
|
return newx, newy, cols, colNumber
|
||||||
|
|
|
@ -123,11 +123,11 @@ end
|
||||||
-- COLLISION FUNCTIONS
|
-- COLLISION FUNCTIONS
|
||||||
-- Handle Hitbox position
|
-- Handle Hitbox position
|
||||||
|
|
||||||
function Hitbox3D:checkCollision(dx, dy, dz, filter)
|
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
|
||||||
self:updatePosition()
|
self:updatePosition()
|
||||||
|
|
||||||
local dx, dy = self.ox + dx, self.oy + dy, self.oz + dz
|
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)
|
local newx, newy, newz = self:getNewOwnerPosition(x, y, z)
|
||||||
|
|
||||||
return newx, newy, newz, cols, colNumber
|
return newx, newy, newz, cols, colNumber
|
||||||
|
|
|
@ -208,7 +208,7 @@ function BaseWorld:moveActor(actor, x, y, filter)
|
||||||
return x, y, {}, 0
|
return x, y, {}, 0
|
||||||
end
|
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
|
-- as the baseworld have no collision function, we return empty collision
|
||||||
-- datas, but from the same type than bump2D will return
|
-- datas, but from the same type than bump2D will return
|
||||||
return x, y, {}, 0
|
return x, y, {}, 0
|
||||||
|
|
|
@ -77,7 +77,7 @@ function World2D:removeBody(body)
|
||||||
return self.bodies:remove(body)
|
return self.bodies:remove(body)
|
||||||
end
|
end
|
||||||
|
|
||||||
function World2D:checkCollision(body, x, y, filter)
|
function World2D:checkCollisionAtPoint(body, x, y, filter)
|
||||||
return self.bodies:check(body, x, y, filter)
|
return self.bodies:check(body, x, y, filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ function World3D:removeBody(body)
|
||||||
return self.bodies:remove(body)
|
return self.bodies:remove(body)
|
||||||
end
|
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)
|
return self.bodies:check(body, x, y, z, filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue