chore: simplify hitbox applciation
This commit is contained in:
parent
9eb0d321c8
commit
dcc2965431
5 changed files with 19 additions and 46 deletions
|
@ -142,28 +142,6 @@ function Actor2D:getViewCenter()
|
||||||
return x, y
|
return x, y
|
||||||
end
|
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 FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
|
|
|
@ -165,28 +165,6 @@ function Actor3D:getViewCenter()
|
||||||
return x, y - (self.d/2)
|
return x, y - (self.d/2)
|
||||||
end
|
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
|
-- SHADOW FUNCTIONS
|
||||||
-- Handle everything related to shadow
|
-- Handle everything related to shadow
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,21 @@ function PhysicalActor:checkHitboxesCollisions(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
|
||||||
|
|
|
@ -116,7 +116,8 @@ end
|
||||||
-- Handle Hitbox position
|
-- Handle Hitbox position
|
||||||
|
|
||||||
function Hitbox2D:checkCollision(filter)
|
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
|
end
|
||||||
|
|
||||||
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)
|
function Hitbox2D:checkCollisionAtPoint(dx, dy, filter)
|
||||||
|
|
|
@ -119,7 +119,8 @@ end
|
||||||
-- Handle Hitbox position
|
-- Handle Hitbox position
|
||||||
|
|
||||||
function Hitbox3D:checkCollision(filter)
|
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
|
end
|
||||||
|
|
||||||
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
|
function Hitbox3D:checkCollisionAtPoint(dx, dy, dz, filter)
|
||||||
|
|
Loading…
Reference in a new issue