doors worxlove .
This commit is contained in:
parent
7fcbd9e5da
commit
85dd66b1e4
8 changed files with 105 additions and 24 deletions
BIN
art/door_locked_W.png
Normal file
BIN
art/door_locked_W.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 B |
BIN
art/door_locked_w.png
Normal file
BIN
art/door_locked_w.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 B |
Binary file not shown.
|
Before Width: | Height: | Size: 95 B After Width: | Height: | Size: 91 B |
61
door.lua
61
door.lua
|
|
@ -2,14 +2,69 @@ require "entity"
|
|||
|
||||
Door = class("Door", Entity)
|
||||
|
||||
function Door:initialize()
|
||||
function Door:initialize(x, y, colors)
|
||||
Entity.initialize(self, {
|
||||
x = x,
|
||||
y = y,
|
||||
color = "white",
|
||||
collision = "unmoveable",
|
||||
sprite = doorSprite["white"] --doesn't matter for now which we put here b/c, we override the draw function neway
|
||||
})
|
||||
self.locked = true
|
||||
|
||||
self.colors = {}
|
||||
for _, color in pairs(colors) do
|
||||
self.colors[color] = true --these are currently loc_ed
|
||||
end
|
||||
end
|
||||
|
||||
function Door:unloc()
|
||||
function Door:draw()
|
||||
if self.locked then
|
||||
for color, active in pairs(self.colors) do
|
||||
if active then
|
||||
love.graphics.setColor(gColor[color]:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(doorSprite[color], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||
end
|
||||
end
|
||||
love.graphics.setColor(gColor.white:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(doorSprite["white"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||
else
|
||||
for color, active in pairs(self.colors) do
|
||||
love.graphics.setColor(gColor[color]:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(doorSprite["unlocked"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Door:setColors(colors)
|
||||
local offColors = {}
|
||||
for color, off in pairs(colors) do
|
||||
print(color, active)
|
||||
if off then
|
||||
if self.colors[color] then self.colors[color] = false end
|
||||
table.insert(offColors, color)
|
||||
else
|
||||
if not self.colors[color] then self.colors[color] = true end
|
||||
end
|
||||
end
|
||||
|
||||
if #offColors == 3 then
|
||||
if self.locked then self:unlock() end
|
||||
else
|
||||
if not self.locked then self:lock() end
|
||||
end
|
||||
end
|
||||
|
||||
function Door:unlock()
|
||||
print("wow")
|
||||
self.locked = false
|
||||
self.collision = "none"
|
||||
end
|
||||
|
||||
function Door:loc()
|
||||
function Door:lock()
|
||||
self.locked = true
|
||||
self.collision = "unmoveable"
|
||||
end
|
||||
13
entity.lua
13
entity.lua
|
|
@ -80,10 +80,17 @@ function Entity:draw()
|
|||
end
|
||||
|
||||
function Entity:canMove()
|
||||
if self.collision == "unmoveable" then
|
||||
return false
|
||||
if self.collision == "moveable" then
|
||||
return true
|
||||
end
|
||||
return true
|
||||
return false
|
||||
end
|
||||
|
||||
function Entity:canPassOver()
|
||||
if self.collision == "none" then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
13
main.lua
13
main.lua
|
|
@ -13,6 +13,7 @@ function love.load()
|
|||
_initDefaults()
|
||||
_initGridVars()
|
||||
_initSounds()
|
||||
_initGlobalColors()
|
||||
loadSprites()
|
||||
|
||||
gameCanvas = love.graphics.newCanvas()
|
||||
|
|
@ -109,6 +110,11 @@ function _initGridVars()
|
|||
worldSha = 1
|
||||
end
|
||||
|
||||
function _initGlobalColors()
|
||||
gColor = {}
|
||||
gColor.red, gColor.green, gColor.blue, gColor.white = Color:new("red"), Color:new("green"), Color:new("blue"), Color:new("white")
|
||||
end
|
||||
|
||||
function _initSounds()
|
||||
staticWave = sfxr.newSound()
|
||||
staticWave.wavetype = 3
|
||||
|
|
@ -133,6 +139,13 @@ function loadSprites()
|
|||
green = love.graphics.newImage("art/wall_g.png"),
|
||||
blue = love.graphics.newImage("art/wall_b.png")
|
||||
}
|
||||
doorSprite = {
|
||||
white = love.graphics.newImage("art/door_locked_w.png"),
|
||||
red = love.graphics.newImage("art/door_locked_r.png"),
|
||||
green = love.graphics.newImage("art/door_locked_g.png"),
|
||||
blue = love.graphics.newImage("art/door_locked_b.png"),
|
||||
unlocked = love.graphics.newImage("art/door_unlocked.png")
|
||||
}
|
||||
switchSprite = {
|
||||
red = love.graphics.newImage("art/switch_r.png"),
|
||||
green = love.graphics.newImage("art/switch_g.png"),
|
||||
|
|
|
|||
|
|
@ -6,15 +6,10 @@ function Player:initialize(x, y, activeColors)
|
|||
Entity.initialize(self, {
|
||||
x = x,
|
||||
y = y,
|
||||
sizeX = 1,
|
||||
sizeY = 1,
|
||||
color = "white",
|
||||
collision = "none", --player can't push other player
|
||||
sprite = playerSprite
|
||||
})
|
||||
|
||||
self.red, self.green, self.blue = Color:new("red"), Color:new("green"), Color:new("blue")
|
||||
|
||||
self.activeColors = activeColors or {"red", "green", "blue"}
|
||||
end
|
||||
|
||||
|
|
@ -32,7 +27,7 @@ end
|
|||
|
||||
function Player:draw()
|
||||
for _, color in ipairs(self.activeColors) do
|
||||
love.graphics.setColor(self[color]:set())
|
||||
love.graphics.setColor(gColor[color]:set())
|
||||
local p = self:getDrawPos()
|
||||
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
|
||||
end
|
||||
|
|
|
|||
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