chore: simplify hitbox applciation

This commit is contained in:
Kazhnuz Klappsthul 2020-11-26 20:54:16 +01:00
parent 9eb0d321c8
commit dcc2965431
5 changed files with 19 additions and 46 deletions

View File

@ -142,28 +142,6 @@ function Actor2D:getViewCenter()
return x, y
end
-- HITBOXES FUNCTIONS
-- Functions related to actor hitboxes
function Actor2D:applyHitboxCollisions(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 cols, colNumber
end
-- DRAW FUNCTIONS
-- Draw the actors.

View File

@ -165,28 +165,6 @@ function Actor3D:getViewCenter()
return x, y - (self.d/2)
end
-- HITBOXES FUNCTIONS
-- Functions related to actor hitboxes
function Actor3D:applyHitboxCollisions(name, filter)
return 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 cols, colNumber
end
-- SHADOW FUNCTIONS
-- Handle everything related to shadow

View File

@ -230,6 +230,21 @@ function PhysicalActor:checkHitboxesCollisions(filter)
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)
-- just a blank placeholder function
end

View File

@ -116,7 +116,8 @@ end
-- Handle Hitbox position
function Hitbox2D:checkCollision(filter)
return self:checkCollisionAtPoint(self.owner.x, self.owner.y, filter)
local _, _, cols, colNumber = self:checkCollisionAtPoint(self.owner.x, self.owner.y, filter)
return cols, colNumber
end
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)

View File

@ -119,7 +119,8 @@ end
-- Handle Hitbox position
function Hitbox3D:checkCollision(filter)
return self:checkCollisionAtPoint(self.owner.x, self.owner.y, self.owner.z, 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)