big-refactor #106

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

View file

@ -145,25 +145,6 @@ function Actor2D:packForHitbox()
return {0, 0, self.w, self.h} return {0, 0, self.w, self.h}
end end
function Actor2D:checkHitboxCollisions(name, filter)
self:applyHitboxCollisionsAtPoint(name, self.x, self.y, filter)
end
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]:checkCollisionAtPoint(dx, dy, filter)
local type = self.hitboxes[name].type
for i, col in ipairs(cols) do
self:hitboxResponse(name, type, col)
end
end
return x, y, cols, colNumber
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- Draw the actors. -- Draw the actors.

View file

@ -168,25 +168,6 @@ function Actor3D:packForHitbox()
return {0, 0, 0, self.w, self.h, self.d} return {0, 0, 0, self.w, self.h, self.d}
end end
function Actor3D:checkHitboxCollisions(name, filter)
self:applyHitboxCollisionsAtPoint(name, self.x, self.y, self.z, filter)
end
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]:checkCollisionAtPoint(dx, dy, dz, filter)
local type = self.hitboxes[name].type
for i, col in ipairs(cols) do
self:hitboxResponse(name, type, col)
end
end
return x, y, z, cols, colNumber
end
-- SHADOW FUNCTIONS -- SHADOW FUNCTIONS
-- Handle everything related to shadow -- Handle everything related to shadow

View file

@ -220,12 +220,27 @@ function PhysicalActor:updateHitboxes()
end end
end end
function PhysicalActor:checkHitboxesCollisions(filter) function PhysicalActor:applyHitboxesCollisions(filter)
for k, v in pairs(self.hitboxes) do for k, v in pairs(self.hitboxes) do
self:checkHitboxCollisions(k, filter) self:applyHitboxCollisions(k, filter)
end end
end end
function PhysicalActor:applyHitboxCollisions(name, filter)
local cols, colNumber = {}, 0
local filter = filter or self.filter
if (self.isDestroyed == false) and (self.hitboxes[name] ~= nil) then
cols, colNumber = self.hitboxes[name]:checkCollision(filter)
local type = self.hitboxes[name].type
for i, col in ipairs(cols) do
self:hitboxResponse(name, type, col)
end
end
return cols, colNumber
end
function PhysicalActor:hitboxResponse(name, type, collision) function PhysicalActor:hitboxResponse(name, type, collision)
-- just a blank placeholder function -- just a blank placeholder function
end end

View file

@ -119,6 +119,11 @@ end
-- COLLISION FUNCTIONS -- COLLISION FUNCTIONS
-- Handle Hitbox position -- Handle Hitbox position
function Hitbox2D:checkCollision(filter)
local _, _, cols, colNumber = self:checkCollisionAtPoint(self.owner.x, self.owner.y, filter)
return cols, colNumber
end
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter) function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)
self:updatePosition() self:updatePosition()

View file

@ -123,6 +123,11 @@ end
-- COLLISION FUNCTIONS -- COLLISION FUNCTIONS
-- Handle Hitbox position -- Handle Hitbox position
function Hitbox3D:checkCollision(filter)
local _, _, _, cols, colNumber = self:checkCollisionAtPoint(self.owner.x, self.owner.y, self.owner.z, filter)
return cols, colNumber
end
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter) function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
self:updatePosition() self:updatePosition()