modules/world: refactor all cordinate functions together

This commit is contained in:
Kazhnuz 2019-05-05 21:22:41 +02:00
parent 6aa7fd6399
commit 4b4b8b4e85

View file

@ -36,10 +36,7 @@ function Actor2D:new(world, type, x, y, w, h, isSolid)
end end
function Actor2D:initPhysics(x, y, w, h, isSolid) function Actor2D:initPhysics(x, y, w, h, isSolid)
self.x = x or 0 self:initHitbox(x, y, w, h)
self.y = y or 0
self.w = w or 0
self.h = h or 0
self.xsp = 0 self.xsp = 0
self.ysp = 0 self.ysp = 0
@ -193,8 +190,15 @@ function Actor2D:applyGravity(dt)
end end
end end
-- DRAW FUNCTIONS -- COORDINATE FUNCTIONS
-- Draw the actors. -- 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() 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))
@ -204,15 +208,18 @@ function Actor2D:getViewCenter()
return self:getCenter() return self:getCenter()
end end
function Actor2D:draw()
local x, y = math.floor(self.x), math.floor(self.y)
self:drawSprite(x, y)
end
function Actor2D:drawHitbox() function Actor2D:drawHitbox()
local x, y = math.floor(self.x), math.floor(self.y) local x, y = math.floor(self.x), math.floor(self.y)
love.graphics.setColor(self.debug.r, self.debug.g, self.debug.b, 1) love.graphics.setColor(self.debug.r, self.debug.g, self.debug.b, 1)
utils.graphics.box(x, y, self.w, self.h) utils.graphics.box(x, y, self.w, self.h)
end 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 return Actor2D