doors worxlove .
This commit is contained in:
parent
7fcbd9e5da
commit
85dd66b1e4
8 changed files with 105 additions and 24 deletions
35
room.lua
35
room.lua
|
|
@ -8,8 +8,10 @@ require "npc"
|
|||
require "art"
|
||||
require "assorted"
|
||||
require "switch"
|
||||
require "door"
|
||||
|
||||
function Room:initialize(t)
|
||||
self.colorsPlayerHas = {"red", "green", "blue"}
|
||||
self.exits = t.exits
|
||||
self.name = t.name
|
||||
self.player = Player:new(t.player.x, t.player.y, t.player.activeColors)
|
||||
|
|
@ -18,6 +20,7 @@ function Room:initialize(t)
|
|||
self.collideables = { red = {}, green = {}, blue = {} }
|
||||
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
|
||||
|
||||
self.doors = {}
|
||||
self.activeColors = {
|
||||
red = true, green = true, blue = true
|
||||
}
|
||||
|
|
@ -28,11 +31,14 @@ function Room:initialize(t)
|
|||
-- self.activeColors[color] = true
|
||||
-- end
|
||||
|
||||
for i=0, 2 do
|
||||
local c = randomColor()
|
||||
local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
|
||||
self.collideables[c]["b: " .. x .. ", " .. y] = Box:new(x, y, c)
|
||||
self.collideables[c]["b: " .. x .. ", " .. y]:getOccupiedCells()
|
||||
for i=1, 3 do
|
||||
local x, y = randomPosition()
|
||||
local door = Door:new(x, y, self.colorsPlayerHas)
|
||||
table.insert(self.doors, door)
|
||||
|
||||
for color, active in pairs(self.activeColors) do
|
||||
self.collideables[color]["w: " .. x .. ", " .. y] = door
|
||||
end
|
||||
end
|
||||
|
||||
-- for i=0, 5 do
|
||||
|
|
@ -165,6 +171,8 @@ function Room:movePlayer(key)
|
|||
|
||||
if not self:isInBounds(initialTargetCell) then
|
||||
move = true
|
||||
elseif self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell) and self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell):canPassOver() then
|
||||
move = true
|
||||
else
|
||||
local targetCells
|
||||
|
||||
|
|
@ -318,15 +326,16 @@ function Room:tick()
|
|||
end
|
||||
self:createCollideablesMatrix()
|
||||
self:createSwitchMatrix()
|
||||
local doorsToUnloc = self:switchChec()
|
||||
for _, color in pairs(doorsToUnloc) do
|
||||
print("unloc " .. color .. " doors!!")
|
||||
local setDoorColors = self:switchCheck()
|
||||
for _, door in pairs(self.doors) do
|
||||
print(door)
|
||||
door:setColors(setDoorColors)
|
||||
end
|
||||
self:nextRoomCheck()
|
||||
end
|
||||
|
||||
function Room:switchChec()
|
||||
local doorsToUnloc = {}
|
||||
function Room:switchCheck()
|
||||
local doorsToUnlock = {}
|
||||
for color, switchArray in pairs(self.switches) do
|
||||
local onSwitches = {}
|
||||
for _, switch in pairs(switchArray) do
|
||||
|
|
@ -337,9 +346,11 @@ function Room:switchChec()
|
|||
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
|
||||
if #onSwitches == #switchArray then doorsToUnlock[color] = true else doorsToUnlock[color] = false end
|
||||
print(color, doorsToUnlock[color])
|
||||
end
|
||||
return doorsToUnloc
|
||||
|
||||
return doorsToUnlock
|
||||
end
|
||||
|
||||
function Room:isInBounds(cell)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue