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-12 05:13:04 -04:00
|
|
|
self.size = {x = t.sizeX, y = t.sizeY}
|
2015-03-11 20:11:29 -04:00
|
|
|
self.color = Color:new(t.color)
|
2015-03-12 05:13:04 -04:00
|
|
|
self.collision = t.collision --"none", "moveable", "unmoveable"
|
2015-03-12 03:04:09 -04:00
|
|
|
self.sprite = t.sprite
|
2015-03-12 04:05:39 -04:00
|
|
|
self.shaAmount = t.sha or 1
|
2015-03-11 20:11:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Entity:atGridPos(x, y)
|
2015-03-12 05:13:04 -04:00
|
|
|
-- print(x, y, self.x, self.y, self.x + self.size.x, self.y + self.size.y)
|
|
|
|
|
if x >= self.x and y >= self.y and x < self.x + self.size.y and y < self.y + self.size.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
|
|
|
|
|
|
2015-03-12 05:13:04 -04:00
|
|
|
function Entity:tick()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-12 03:04:09 -04:00
|
|
|
function Entity:draw()
|
|
|
|
|
love.graphics.setColor(self.color:set())
|
|
|
|
|
local p = self:getDrawPos()
|
2015-03-12 04:05:39 -04:00
|
|
|
love.graphics.draw(self.sprite, p.x + self:sha(), p.y + self:sha(), 0, drawScale, drawScale)
|
2015-03-12 03:04:09 -04:00
|
|
|
end
|
|
|
|
|
|
2015-03-12 05:13:04 -04:00
|
|
|
function Entity:isAlignedWithPlayerMovement(axis, pos, direction)
|
|
|
|
|
-- print(axis, pos[axis], self:getGridPos()[axis], self:getGridPos()[axis] + self.size[axis])
|
|
|
|
|
if self:getGridPos()[axis] <= pos[axis] and self:getGridPos()[axis] + self.size[axis] > pos[axis] then
|
|
|
|
|
print("true!!")
|
2015-03-12 03:04:09 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2015-03-12 04:05:39 -04:00
|
|
|
function Entity:sha()
|
|
|
|
|
return math.random(-self.shaAmount, self.shaAmount) * .5
|
2015-03-11 20:11:29 -04:00
|
|
|
end
|