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.name = t.name
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors) self.player = Player:new(t.player.x, t.player.y, t.player.activeColors)
self.switches = { red = {}, green = {}, blue = {} } self.switches = { red = {}, green = {}, blue = {} }
self.switchMatrices = {}
self.collideables = { red = {}, green = {}, blue = {} } self.collideables = { red = {}, green = {}, blue = {} }
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...} self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
self.activeColors = { self.activeColors = {
red = true, green = true, blue = true red = true, green = true, blue = true
@ -34,13 +35,12 @@ function Room:initialize(t)
self.collideables[c]["b: " .. x .. ", " .. y]:getOccupiedCells() self.collideables[c]["b: " .. x .. ", " .. y]:getOccupiedCells()
end end
-- for i=0, 5 do
for i=0, 5 do -- local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
local x, y = math.random(1, gridWidth), math.random(1, gridHeight) -- for color, active in pairs(self.activeColors) do
for color, active in pairs(self.activeColors) do -- self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color)
self.collideables[color]["w: " .. x .. ", " .. y] = Wall:new(x, y, color) -- end
end -- end
end
for i = 0, 5 do for i = 0, 5 do
local x, y = randomPosition() local x, y = randomPosition()
@ -89,11 +89,18 @@ function Room:draw()
end end
end end
function Room:createCollideablesMatrix(collideables) function Room:createCollideablesMatrix()
for color, entities in pairs(self.collideables) do for color, entities in pairs(self.collideables) do
self.collidableMatrices[color] = self:createEntityMatrix(entities) self.collidableMatrices[color] = self:createEntityMatrix(entities)
end end
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) function Room:createEntityMatrix(entities)
local matrix = {} local matrix = {}
@ -310,9 +317,31 @@ function Room:tick()
end end
end end
self:createCollideablesMatrix() self:createCollideablesMatrix()
self:createSwitchMatrix()
local doorsToUnloc = self:switchChec()
for _, color in pairs(doorsToUnloc) do
print("unloc " .. color .. " doors!!")
end
self:nextRoomCheck() self:nextRoomCheck()
end 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) function Room:isInBounds(cell)
if cell.x > 0 and cell.x <= gridWidth and if cell.x > 0 and cell.x <= gridWidth and
cell.y > 0 and cell.y <= gridHeight then cell.y > 0 and cell.y <= gridHeight then

View file

@ -3,15 +3,18 @@ require "entity"
Switch = class("Switch", Entity) Switch = class("Switch", Entity)
function Switch:initialize(x, y, color) function Switch:initialize(x, y, color)
print("hey!!", x, y, color)
print(color)
Entity.initialize(self, { Entity.initialize(self, {
x = x, x = x,
y = y, y = y,
sizeX = 1,
sizeY = 1,
color = color, color = color,
collision = "none", --switches are floor elements that can't be pushed or bloc movement!! collision = "none", --switches are floor elements that can't be pushed or bloc movement!!
sprite = switchSprite[color] sprite = switchSprite[color]
}) })
self.activated = false
end
function Switch:activate()
if self.activated == false then self.activated = true end
print("i am: ", self.activated)
end end