diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 5ddc4ba..ca4f2b4 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -36,10 +36,7 @@ function Actor2D:new(world, type, x, y, w, h, isSolid) end function Actor2D:initPhysics(x, y, w, h, isSolid) - self.x = x or 0 - self.y = y or 0 - self.w = w or 0 - self.h = h or 0 + self:initHitbox(x, y, w, h) self.xsp = 0 self.ysp = 0 @@ -193,8 +190,15 @@ function Actor2D:applyGravity(dt) end end --- DRAW FUNCTIONS --- Draw the actors. +-- COORDINATE FUNCTIONS +-- Functions related to coordinate and hitbox + +function Actor2D:initHitbox(x, y, w, h) + self.x = x or 0 + self.y = y or 0 + self.w = w or 0 + self.h = h or 0 +end function Actor2D:getCenter() return (self.x + (self.w / 2)), (self.y + (self.h / 2)) @@ -204,15 +208,18 @@ function Actor2D:getViewCenter() return self:getCenter() end -function Actor2D:draw() - local x, y = math.floor(self.x), math.floor(self.y) - self:drawSprite(x, y) -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. + +function Actor2D:draw() + local x, y = math.floor(self.x), math.floor(self.y) + self:drawSprite(x, y) +end + return Actor2D