level serializes now

This commit is contained in:
0x81c 2015-03-16 10:17:06 -04:00
parent 7fa31726f4
commit d76ace8f69
2 changed files with 81 additions and 12 deletions

View file

@ -2,7 +2,6 @@ Entity = class("Entity")
function Entity:initialize(t)
self.x, self.y = t.x, t.y
self.name = t.name
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)
@ -11,6 +10,7 @@ function Entity:initialize(t)
self.sprite = t.sprite
self.shaAmount = t.sha or 1
self.onBump = t.onBump or function(self) return true end
self.tick = t.tick or function(self) return true end
self.drawOffset = {x = 0, y = 0}
if self.size.w < 1 or self.size.h < 1 then
@ -19,13 +19,6 @@ function Entity:initialize(t)
end
end
Entity.static.positionsAreEqual = function(cell1, cell2)
if cell1.x == cell2.x and cell1.y == cell2.y then
return true
end
return false
end
function Entity:getCollision()
return self.collision
end
@ -95,8 +88,12 @@ function Entity:getGridSize()
return {x = self.size.w, y = self.size.h}
end
function Entity:tick()
function Entity:getname()
return self.name
end
function Entity:tick()
return self.tick()
end
function Entity:draw()
@ -119,6 +116,18 @@ function Entity:canPassOver()
return false
end
function Entity:getClass()
return self.class.name
end
function Entity:getSerializationTable()
local pos = self:getGridPos()
local table = {}
table.x, table.y, table.color = pos.x, pos.y, color
if self.name then table.name = self.name end
return table
end
function Entity:move(axis, direction)
self[axis] = self[axis] + direction
@ -134,4 +143,12 @@ end
function Entity:bump()
return self:onBump()
end
end
Entity.static.positionsAreEqual = function(cell1, cell2)
if cell1.x == cell2.x and cell1.y == cell2.y then
return true
end
return false
end