wowgit add -A!

This commit is contained in:
0x81c 2015-03-15 16:25:00 -04:00
parent 1156564fa2
commit 747a7b7b58
3 changed files with 44 additions and 25 deletions

View file

@ -4,6 +4,7 @@ function Entity:initialize(t)
self.x, self.y = t.x, t.y
self.spriteSize = {w = t.sprite:getWidth(), h = t.sprite:getHeight()}
self.size = {w = self.spriteSize.w / 16, h = self.spriteSize.h / 16}
self.cellShape = t.cellShape or self:cellShapeFromBox(self.size)
self.color = Color:new(t.color)
self.collision = t.collision --"none", "moveable", "unmoveable"
self.sprite = t.sprite
@ -32,18 +33,36 @@ end
function Entity:getOccupiedCells(coords)
--we have this offset so we can project what a movement would do
local offset = coords or {x = 0, y = 0}
local box = self:getGridBox()
local cells = {}
local pos = self:getGridPos()
for _, cell in ipairs(self:getCellShape()) do
local adjustedCell = {}
adjustedCell.x = pos.x + cell.x - 1 + offset.x
adjustedCell.y = pos.y + cell.y - 1 + offset.y
table.insert(cells, adjustedCell)
end
for i = box.x + offset.x, box.x + box.w - 1 + offset.x do
for j = box.y + offset.y, box.y + box.h - 1 + offset.y do
return cells
end
function Entity:cellShapeFromBox(box)
local cells = {}
for i = 1, box.w do
for j = 1, box.h do
table.insert(cells, {x = i, y = j})
io.write(" boop: " .. i .. ", " .. j)
end
end
io.write("\n")
return cells
end
function Entity:getCellShape()
return self.cellShape
end
function Entity:getDrawBox()
local drawPos = self:getDrawPos()
return {x = drawPos.x, y = drawPos.y, w = self.spriteSize.w * drawScale, h = self.spriteSize.h * drawScale}
@ -80,14 +99,14 @@ function Entity:draw()
end
function Entity:canMove()
if self.collision == "moveable" then
if self:getCollision() == "moveable" then
return true
end
return false
end
function Entity:canPassOver()
if self.collision == "none" then
if self:getCollision() == "none" then
return true
end
return false