switches and chex and so forthgit add -A wow

This commit is contained in:
0x81c 2015-03-15 05:44:30 -04:00
parent b553d3f664
commit 7fcbd9e5da
2 changed files with 45 additions and 13 deletions

View file

@ -14,8 +14,9 @@ function Room:initialize(t)
self.name = t.name
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors)
self.switches = { red = {}, green = {}, blue = {} }
self.switchMatrices = {}
self.collideables = { red = {}, green = {}, blue = {} }
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...}
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
self.activeColors = {
red = true, green = true, blue = true
@ -34,13 +35,12 @@ function Room:initialize(t)
self.collideables[c]["b: " .. x .. ", " .. y]:getOccupiedCells()
end
for i=0, 5 do
local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
for color, active in pairs(self.activeColors) do
self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color)
end
end
-- for i=0, 5 do
-- local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
-- for color, active in pairs(self.activeColors) do
-- self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color)
-- end
-- end
for i = 0, 5 do
local x, y = randomPosition()
@ -89,11 +89,18 @@ function Room:draw()
end
end
function Room:createCollideablesMatrix(collideables)
function Room:createCollideablesMatrix()
for color, entities in pairs(self.collideables) do
self.collidableMatrices[color] = self:createEntityMatrix(entities)
end
end
function Room:createSwitchMatrix()
for color, switches in pairs(self.switches) do
self.switchMatrices[color] = self:createEntityMatrix(switches)
end
end
function Room:createEntityMatrix(entities)
local matrix = {}
@ -310,9 +317,31 @@ function Room:tick()
end
end
self:createCollideablesMatrix()
self:createSwitchMatrix()
local doorsToUnloc = self:switchChec()
for _, color in pairs(doorsToUnloc) do
print("unloc " .. color .. " doors!!")
end
self:nextRoomCheck()
end
function Room:switchChec()
local doorsToUnloc = {}
for color, switchArray in pairs(self.switches) do
local onSwitches = {}
for _, switch in pairs(switchArray) do
local targetCell = self:getCellInMatrix(self.collidableMatrices[color], switch:getGridPos())
if targetCell then
--switch is on
switch:activate()
table.insert(onSwitches, switch) --doesn't rly matter what we put here as long as it's true-y
end
end
if #onSwitches == #switchArray then table.insert(doorsToUnloc, color) end
end
return doorsToUnloc
end
function Room:isInBounds(cell)
if cell.x > 0 and cell.x <= gridWidth and
cell.y > 0 and cell.y <= gridHeight then