From cb97c2ceee65ce15c92b29aeb36946360092973b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 22 Jun 2019 17:27:36 +0200 Subject: [PATCH] chore(world): prepate using an external hitbox object --- gamecore/modules/world/actors/actor2D.lua | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index a6613d2..d67df15 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -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.