chroma_solstice/entity.lua

28 lines
669 B
Lua
Raw Normal View History

2015-03-11 20:11:29 -04:00
Entity = class("Entity")
function Entity:initialize(t)
self.gridX, self.gridY = t.x, t.y
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-11 20:11:29 -04:00
end
function Entity:atGridPos(x, y)
if x >= self.gridX and x <= self.gridX + self.gridSize.x and
y >= self.gridY and y <= self.gridSize.y then
return true
end
return false
end
function Entity:getGridPos()
return {x = self.gridX, y = self.gridY}
end
function Entity:getDrawPos()
local gridPos = self:getGridPos()
return {
x = (gridPos.x - 1) * width / gridWidth,
y = (gridPos.y - 1) * height / gridHeight
}
end