chore(world): prepate using an external hitbox object

This commit is contained in:
Kazhnuz 2019-06-22 17:27:36 +02:00
parent 2b1bdd0be5
commit cb97c2ceee

View file

@ -30,7 +30,8 @@ local Actor2D = BaseActor:extend()
-- Initialise the actor and its base functions -- Initialise the actor and its base functions
function Actor2D:new(world, type, x, y, w, h, isSolid) function Actor2D:new(world, type, x, y, w, h, isSolid)
self:initHitbox(x, y, w, h) self:setCoordinate(x, y)
self:initMainHitbox(w, h)
Actor2D.super.new(self, world, type, isSolid) Actor2D.super.new(self, world, type, isSolid)
end end
@ -165,16 +166,28 @@ function Actor2D:applyGravity(dt)
end end
end end
-- COORDINATE FUNCTIONS -- HITBOXES FUNCTIONS
-- Functions related to coordinate and hitbox -- Functions related to actor hitboxes
function Actor2D:initHitbox(x, y, w, h) function Actor2D:initMainHitbox(w, h)
self.x = x or 0
self.y = y or 0
self.w = w or 0 self.w = w or 0
self.h = h or 0 self.h = h or 0
end end
function Actor2D:drawMainHitbox()
local x, y = math.floor(self.x), math.floor(self.y)
love.graphics.setColor(self.debug.r, self.debug.g, self.debug.b, 1)
utils.graphics.box(x, y, self.w, self.h)
end
-- COORDINATE FUNCTION
-- Handle the coordinate system
function Actor2D:setCoordinate(x, y)
self.x = x or self.x
self.y = y or self.y
end
function Actor2D:getCenter() function Actor2D:getCenter()
return (self.x + (self.w / 2)), (self.y + (self.h / 2)) return (self.x + (self.w / 2)), (self.y + (self.h / 2))
end end
@ -183,12 +196,6 @@ function Actor2D:getViewCenter()
return self:getCenter() return self:getCenter()
end end
function Actor2D:drawHitbox()
local x, y = math.floor(self.x), math.floor(self.y)
love.graphics.setColor(self.debug.r, self.debug.g, self.debug.b, 1)
utils.graphics.box(x, y, self.w, self.h)
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- Draw the actors. -- Draw the actors.