diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 48406f4..292c06d 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -129,57 +129,6 @@ end -- HITBOXES FUNCTIONS -- 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) local sx, sy = self:getSpriteScalling() local type = framedata[1] @@ -222,12 +171,6 @@ function Actor2D:addHitbox(name, type, ox, oy, w, h, isSolid) 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) self:checkHitboxCollisionsAtPoint(name, self.x, self.y, filter) end @@ -247,36 +190,6 @@ function Actor2D:checkHitboxCollisionsAtPoint(name, dx, dy, filter) return x, y, cols, colNumber 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 the actors. diff --git a/gamecore/modules/world/actors/baseactor.lua b/gamecore/modules/world/actors/baseactor.lua index ac5769d..190747a 100644 --- a/gamecore/modules/world/actors/baseactor.lua +++ b/gamecore/modules/world/actors/baseactor.lua @@ -246,6 +246,101 @@ function BaseActor:timerResponse(name) -- here come the timer responses 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 the actors. @@ -266,7 +361,6 @@ function BaseActor:drawHUD(id, height, width) end - -- SPRITES FUNCTIONS -- Handle the sprite of the actor