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
1 changed files with 19 additions and 12 deletions

View File

@ -30,7 +30,8 @@ local Actor2D = BaseActor:extend()
-- Initialise the actor and its base functions
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)
end
@ -165,16 +166,28 @@ function Actor2D:applyGravity(dt)
end
end
-- COORDINATE FUNCTIONS
-- Functions related to coordinate and hitbox
-- HITBOXES FUNCTIONS
-- Functions related to actor hitboxes
function Actor2D:initHitbox(x, y, w, h)
self.x = x or 0
self.y = y or 0
function Actor2D:initMainHitbox(w, h)
self.w = w or 0
self.h = h or 0
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()
return (self.x + (self.w / 2)), (self.y + (self.h / 2))
end
@ -183,12 +196,6 @@ function Actor2D:getViewCenter()
return self:getCenter()
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 the actors.