chore: pack and unpack the coordinates

It'll allow us to unify the hitbox loading system
This commit is contained in:
Kazhnuz 2020-11-26 19:41:13 +01:00
parent 79902a097f
commit 92c08e30ee
4 changed files with 30 additions and 22 deletions

View file

@ -161,24 +161,24 @@ function Actor2D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxI
end
if (type == "main") then
self.mainHitbox:modify(ox, oy, w, h)
self.mainHitbox:setFromData({ox, oy, w, h})
else
local hitboxName = anim .. frame .. type .. id
self:addHitbox(hitboxName, type, ox, oy, w, h, isSolid)
self:addHitbox(hitboxName, type, {ox, oy, w, h}, isSolid)
return hitboxName
end
end
function Actor2D:initMainHitbox()
self.mainHitbox = Hitbox(self, self.type, 0, 0, self.w, self.h, self.isSolid)
self.mainHitbox = Hitbox(self, self.type, {0, 0, self.w, self.h}, self.isSolid)
self.mainHitbox:advertiseAsMainHitbox()
end
function Actor2D:addHitbox(name, type, ox, oy, w, h, isSolid)
function Actor2D:addHitbox(name, type, data, isSolid)
if (self.hitboxes[name] ~= nil) then
core.debug:logWarn("actor2D", "the hitbox " .. name .. " already exists")
else
local hitbox = Hitbox(self, type, ox, oy, w, h, isSolid)
local hitbox = Hitbox(self, type, data, isSolid)
self.hitboxes[name] = hitbox
return hitbox
end

View file

@ -185,24 +185,24 @@ function Actor3D:addHitboxFromFrameData(framedata, animationID, frameID, hitboxI
end
if (type == "main") then
self.mainHitbox:modify(ox, oy, oz, w, h, d)
self.mainHitbox:setFromData({ox, oy, oz, w, h, d})
else
local hitboxName = anim .. frame .. type .. id
self:addHitbox(hitboxName, type, ox, oy, oz, w, h, d, isSolid)
self:addHitbox(hitboxName, type, {ox, oy, oz, w, h, d}, isSolid)
return hitboxName
end
end
function Actor3D:initMainHitbox()
self.mainHitbox = Hitbox(self, self.type, 0, 0, 0, self.w, self.h, self.d, self.isSolid)
self.mainHitbox = Hitbox(self, self.type, {0, 0, 0, self.w, self.h, self.d}, self.isSolid)
self.mainHitbox:advertiseAsMainHitbox()
end
function Actor3D:addHitbox(name, type, ox, oy, oz, w, h, d, isSolid)
function Actor3D:addHitbox(name, type, data, isSolid)
if (self.hitboxes[name] ~= nil) then
core.debug:logWarn("actor3D", "the hitbox " .. name .. " already exists")
else
local hitbox = Hitbox(self, type, ox, oy, oz, w, h, d, isSolid)
local hitbox = Hitbox(self, type, data, isSolid)
self.hitboxes[name] = hitbox
return hitbox
end

View file

@ -27,16 +27,13 @@ local Hitbox2D = Object:extend()
-- INIT FUNCTIONS
-- Initialise the actor and its base functions
function Hitbox2D:new(owner, type, ox, oy, w, h, isSolid)
function Hitbox2D:new(owner, type, data, isSolid)
self.owner = owner
self.world = owner.world
self.type = type
self.ox = ox
self.oy = oy
self:setFromData(data)
self.x, self.y = self:getPosition()
self.w = w
self.h = h
self.isSolid = isSolid
self.isMainHitBox = false
@ -45,6 +42,13 @@ function Hitbox2D:new(owner, type, ox, oy, w, h, isSolid)
self:register()
end
function Hitbox2D:setFromData(data)
self.ox = data[1]
self.oy = data[2]
self.w = data[3]
self.h = data[4]
end
function Hitbox2D:advertiseAsMainHitbox()
self.isMainHitBox = true
end

View file

@ -27,18 +27,13 @@ local Hitbox3D = Object:extend()
-- INIT FUNCTIONS
-- Initialise the actor and its base functions
function Hitbox3D:new(owner, type, ox, oy, oz, w, h, d, isSolid)
function Hitbox3D:new(owner, type, data, isSolid)
self.owner = owner
self.world = owner.world
self.type = type
self.ox = ox
self.oy = oy
self.oz = oz
self:setFromData(data)
self.x, self.y, self.z = self:getPosition()
self.w = w
self.h = h
self.d = d
self.isSolid = isSolid
self.isMainHitBox = false
@ -47,6 +42,15 @@ function Hitbox3D:new(owner, type, ox, oy, oz, w, h, d, isSolid)
self:register()
end
function Hitbox3D:setFromData(data)
self.ox = data[1]
self.oy = data[2]
self.oz = data[3]
self.w = data[4]
self.h = data[5]
self.d = data[6]
end
function Hitbox3D:advertiseAsMainHitbox()
self.isMainHitBox = true
end