improvement(actor): put hitbox functions that make sense in baseactor
This commit is contained in:
parent
b4f3008552
commit
369e0ceec0
2 changed files with 95 additions and 88 deletions
|
@ -129,57 +129,6 @@ end
|
||||||
-- HITBOXES FUNCTIONS
|
-- HITBOXES FUNCTIONS
|
||||||
-- Functions related to actor hitboxes
|
-- Functions related to actor hitboxes
|
||||||
|
|
||||||
function Actor2D:initHitboxes()
|
|
||||||
self:initMainHitbox()
|
|
||||||
|
|
||||||
self.hitboxes = {}
|
|
||||||
self.hitboxListFile = ""
|
|
||||||
self.hitboxList = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:setHitboxFile(file)
|
|
||||||
self.hitboxList = require(file)
|
|
||||||
self.hitboxListFile = file
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:getAutomaticHitboxLoading()
|
|
||||||
return (self.hitboxList ~= nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:getHitboxFile()
|
|
||||||
return self.hitboxListFile
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:getHitboxList(animation, frame)
|
|
||||||
if (animation == nil) or (self.hitboxList == nil) then
|
|
||||||
return self.hitboxList
|
|
||||||
else
|
|
||||||
local list = self.hitboxList[animation]
|
|
||||||
|
|
||||||
if (frame == nil) or (list == nil) then
|
|
||||||
return list
|
|
||||||
else
|
|
||||||
return list[frame]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:updateHitboxes()
|
|
||||||
if (self.hitboxList ~= nil) then
|
|
||||||
self:purgeHitbox()
|
|
||||||
local animation, frame
|
|
||||||
animation = self:getCurrentAnimation()
|
|
||||||
frame = self:getRelativeFrame()
|
|
||||||
local hitboxList = self:getHitboxList(animation, frame)
|
|
||||||
|
|
||||||
if (hitboxList ~= nil) then
|
|
||||||
for i,v in ipairs(hitboxList) do
|
|
||||||
self:addHitboxFromFrameData(v, animation, frame, i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxID)
|
function Actor2D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxID)
|
||||||
local sx, sy = self:getSpriteScalling()
|
local sx, sy = self:getSpriteScalling()
|
||||||
local type = framedata[1]
|
local type = framedata[1]
|
||||||
|
@ -222,12 +171,6 @@ function Actor2D:addHitbox(name, type, ox, oy, w, h, isSolid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:checkHitboxesCollisions(filter)
|
|
||||||
for k,v in pairs(self.hitboxes) do
|
|
||||||
self:checkHitboxCollisionsAtPoint(k, self.x, self.y, filter)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:checkHitboxCollisions(name, filter)
|
function Actor2D:checkHitboxCollisions(name, filter)
|
||||||
self:checkHitboxCollisionsAtPoint(name, self.x, self.y, filter)
|
self:checkHitboxCollisionsAtPoint(name, self.x, self.y, filter)
|
||||||
end
|
end
|
||||||
|
@ -247,36 +190,6 @@ function Actor2D:checkHitboxCollisionsAtPoint(name, dx, dy, filter)
|
||||||
return x, y, cols, colNumber
|
return x, y, cols, colNumber
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:hitboxResponse(name, type, collision)
|
|
||||||
-- just a blank placeholder function
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:removeHitbox(name)
|
|
||||||
if (self.hitboxes[name] ~= nil) then
|
|
||||||
self.hitboxes[name]:destroy()
|
|
||||||
self.hitboxes[name] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:purgeHitbox()
|
|
||||||
for k,v in pairs(self.hitboxes) do
|
|
||||||
v:destroy()
|
|
||||||
end
|
|
||||||
self.hitboxes = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:drawHitboxes()
|
|
||||||
for k,v in pairs(self.hitboxes) do
|
|
||||||
v:draw()
|
|
||||||
end
|
|
||||||
self.mainHitbox:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function Actor2D:drawMainHitbox()
|
|
||||||
self.mainHitbox:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
|
|
|
@ -246,6 +246,101 @@ function BaseActor:timerResponse(name)
|
||||||
-- here come the timer responses
|
-- here come the timer responses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- HITBOX FUNCTIONS
|
||||||
|
-- All functions to handle hitboxes
|
||||||
|
|
||||||
|
function BaseActor:initHitboxes()
|
||||||
|
self:initMainHitbox()
|
||||||
|
|
||||||
|
self.hitboxes = {}
|
||||||
|
self.hitboxListFile = ""
|
||||||
|
self.hitboxList = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:initMainHitbox()
|
||||||
|
-- Empty function : don't load ANY real hitbox function into baseactor
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:setHitboxFile(file)
|
||||||
|
self.hitboxList = require(file)
|
||||||
|
self.hitboxListFile = file
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:getAutomaticHitboxLoading()
|
||||||
|
return (self.hitboxList ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:getHitboxFile()
|
||||||
|
return self.hitboxListFile
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:getHitboxList(animation, frame)
|
||||||
|
if (animation == nil) or (self.hitboxList == nil) then
|
||||||
|
return self.hitboxList
|
||||||
|
else
|
||||||
|
local list = self.hitboxList[animation]
|
||||||
|
|
||||||
|
if (frame == nil) or (list == nil) then
|
||||||
|
return list
|
||||||
|
else
|
||||||
|
return list[frame]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:updateHitboxes()
|
||||||
|
if (self.hitboxList ~= nil) then
|
||||||
|
self:purgeHitbox()
|
||||||
|
local animation, frame
|
||||||
|
animation = self:getCurrentAnimation()
|
||||||
|
frame = self:getRelativeFrame()
|
||||||
|
local hitboxList = self:getHitboxList(animation, frame)
|
||||||
|
|
||||||
|
if (hitboxList ~= nil) then
|
||||||
|
for i,v in ipairs(hitboxList) do
|
||||||
|
self:addHitboxFromFrameData(v, animation, frame, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:checkHitboxesCollisions(filter)
|
||||||
|
for k,v in pairs(self.hitboxes) do
|
||||||
|
self:checkHitboxCollisions(k, filter)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:hitboxResponse(name, type, collision)
|
||||||
|
-- just a blank placeholder function
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:removeHitbox(name)
|
||||||
|
if (self.hitboxes[name] ~= nil) then
|
||||||
|
self.hitboxes[name]:destroy()
|
||||||
|
self.hitboxes[name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:purgeHitbox()
|
||||||
|
for k,v in pairs(self.hitboxes) do
|
||||||
|
v:destroy()
|
||||||
|
end
|
||||||
|
self.hitboxes = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:drawHitboxes()
|
||||||
|
for k,v in pairs(self.hitboxes) do
|
||||||
|
v:draw()
|
||||||
|
end
|
||||||
|
self:drawMainHitbox()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:drawMainHitbox()
|
||||||
|
if (self.mainHitbox ~= nil) then
|
||||||
|
self.mainHitbox:draw()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
|
@ -266,7 +361,6 @@ function BaseActor:drawHUD(id, height, width)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- SPRITES FUNCTIONS
|
-- SPRITES FUNCTIONS
|
||||||
-- Handle the sprite of the actor
|
-- Handle the sprite of the actor
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue