boxes n walls n movement etcgit status

This commit is contained in:
0x81c 2015-03-12 03:04:09 -04:00
parent 9763040c99
commit 2772ec2563
10 changed files with 318 additions and 45 deletions

View file

@ -1,22 +1,23 @@
Entity = class("Entity")
function Entity:initialize(t)
self.gridX, self.gridY = t.x, t.y
self.x, self.y = t.x, t.y
self.gridSize = {x = t.sizeX, y = t.sizeY}
self.color = Color:new(t.color)
self.collision = t.collision --either "none", "moveable", "unmoveable"
self.sprite = t.sprite
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
if x >= self.x and x <= self.x + self.gridSize.x and
y >= self.y and y <= self.gridSize.y then
return true
end
return false
end
function Entity:getGridPos()
return {x = self.gridX, y = self.gridY}
return {x = self.x, y = self.y}
end
function Entity:getDrawPos()
@ -25,4 +26,33 @@ function Entity:getDrawPos()
x = (gridPos.x - 1) * width / gridWidth,
y = (gridPos.y - 1) * height / gridHeight
}
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)
end