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
1 changed files with 18 additions and 11 deletions

View File

@ -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