From 7fcbd9e5da2a0027e9d1578efa90e62cf75f2f08 Mon Sep 17 00:00:00 2001 From: 0x81c Date: Sun, 15 Mar 2015 05:44:30 -0400 Subject: [PATCH] switches and chex and so forthgit add -A wow --- room.lua | 47 ++++++++++++++++++++++++++++++++++++++--------- switch.lua | 11 +++++++---- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/room.lua b/room.lua index da42c82..636e613 100644 --- a/room.lua +++ b/room.lua @@ -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 diff --git a/switch.lua b/switch.lua index 1bb19ae..a072519 100644 --- a/switch.lua +++ b/switch.lua @@ -3,15 +3,18 @@ require "entity" Switch = class("Switch", Entity) function Switch:initialize(x, y, color) - print("hey!!", x, y, color) - print(color) Entity.initialize(self, { x = x, y = y, - sizeX = 1, - sizeY = 1, color = color, collision = "none", --switches are floor elements that can't be pushed or bloc movement!! 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 \ No newline at end of file