From 4b4b8b4e85c73428293f22331b65ee064a3ba1b4 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 5 May 2019 21:22:41 +0200 Subject: [PATCH] modules/world: refactor all cordinate functions together --- gamecore/modules/world/actors/actor2D.lua | 29 ++++++++++++++--------- 1 file changed, 18 insertions(+), 11 deletions(-) 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