chroma_solstice/entity.lua

58 lines
1.2 KiB
Lua
Raw Normal View History

2015-03-11 20:11:29 -04:00
Entity = class("Entity")
function Entity:initialize(t)
2015-03-12 03:04:09 -04:00
self.x, self.y = t.x, t.y
2015-03-11 20:11:29 -04:00
self.gridSize = {x = t.sizeX, y = t.sizeY}
self.color = Color:new(t.color)
2015-03-11 21:41:02 -04:00
self.collision = t.collision --either "none", "moveable", "unmoveable"
2015-03-12 03:04:09 -04:00
self.sprite = t.sprite
2015-03-11 20:11:29 -04:00
end
function Entity:atGridPos(x, y)
2015-03-12 03:04:09 -04:00
if x >= self.x and x <= self.x + self.gridSize.x and
y >= self.y and y <= self.gridSize.y then
2015-03-11 20:11:29 -04:00
return true
end
return false
end
function Entity:getGridPos()
2015-03-12 03:04:09 -04:00
return {x = self.x, y = self.y}
2015-03-11 20:11:29 -04:00
end
function Entity:getDrawPos()
local gridPos = self:getGridPos()
return {
x = (gridPos.x - 1) * width / gridWidth,
y = (gridPos.y - 1) * height / gridHeight
}
2015-03-12 03:04:09 -04:00
end
function Entity:draw()
love.graphics.setColor(self.color:set())
local p = self:getDrawPos()
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
end
function Entity:isAlignedWithPlayerMovement(axis, pos)
if self:getGridPos()[axis] == pos then
return true
end
return false
end
function Entity:canMove()
if self.collision == "unmoveable" then
return false
end
return true
end
function Entity:move(axis, direction)
self[axis] = self[axis] + direction
end
function Entity:push(direction)
2015-03-11 20:11:29 -04:00
end