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)
|
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
|
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"
|
self.collision = "none"
|
||||||
end
|
end
|
||||||
|
|
||||||
function Door:loc()
|
function Door:lock()
|
||||||
|
self.locked = true
|
||||||
self.collision = "unmoveable"
|
self.collision = "unmoveable"
|
||||||
end
|
end
|
||||||
13
entity.lua
13
entity.lua
|
|
@ -80,10 +80,17 @@ function Entity:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:canMove()
|
function Entity:canMove()
|
||||||
if self.collision == "unmoveable" then
|
if self.collision == "moveable" then
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
return true
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Entity:canPassOver()
|
||||||
|
if self.collision == "none" then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
13
main.lua
13
main.lua
|
|
@ -13,6 +13,7 @@ function love.load()
|
||||||
_initDefaults()
|
_initDefaults()
|
||||||
_initGridVars()
|
_initGridVars()
|
||||||
_initSounds()
|
_initSounds()
|
||||||
|
_initGlobalColors()
|
||||||
loadSprites()
|
loadSprites()
|
||||||
|
|
||||||
gameCanvas = love.graphics.newCanvas()
|
gameCanvas = love.graphics.newCanvas()
|
||||||
|
|
@ -109,6 +110,11 @@ function _initGridVars()
|
||||||
worldSha = 1
|
worldSha = 1
|
||||||
end
|
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()
|
function _initSounds()
|
||||||
staticWave = sfxr.newSound()
|
staticWave = sfxr.newSound()
|
||||||
staticWave.wavetype = 3
|
staticWave.wavetype = 3
|
||||||
|
|
@ -133,6 +139,13 @@ function loadSprites()
|
||||||
green = love.graphics.newImage("art/wall_g.png"),
|
green = love.graphics.newImage("art/wall_g.png"),
|
||||||
blue = love.graphics.newImage("art/wall_b.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 = {
|
switchSprite = {
|
||||||
red = love.graphics.newImage("art/switch_r.png"),
|
red = love.graphics.newImage("art/switch_r.png"),
|
||||||
green = love.graphics.newImage("art/switch_g.png"),
|
green = love.graphics.newImage("art/switch_g.png"),
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,10 @@ function Player:initialize(x, y, activeColors)
|
||||||
Entity.initialize(self, {
|
Entity.initialize(self, {
|
||||||
x = x,
|
x = x,
|
||||||
y = y,
|
y = y,
|
||||||
sizeX = 1,
|
|
||||||
sizeY = 1,
|
|
||||||
color = "white",
|
color = "white",
|
||||||
collision = "none", --player can't push other player
|
collision = "none", --player can't push other player
|
||||||
sprite = playerSprite
|
sprite = playerSprite
|
||||||
})
|
})
|
||||||
|
|
||||||
self.red, self.green, self.blue = Color:new("red"), Color:new("green"), Color:new("blue")
|
|
||||||
|
|
||||||
self.activeColors = activeColors or {"red", "green", "blue"}
|
self.activeColors = activeColors or {"red", "green", "blue"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -32,7 +27,7 @@ end
|
||||||
|
|
||||||
function Player:draw()
|
function Player:draw()
|
||||||
for _, color in ipairs(self.activeColors) do
|
for _, color in ipairs(self.activeColors) do
|
||||||
love.graphics.setColor(self[color]:set())
|
love.graphics.setColor(gColor[color]:set())
|
||||||
local p = self:getDrawPos()
|
local p = self:getDrawPos()
|
||||||
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
|
love.graphics.draw(self.sprite, p.x, p.y, 0, drawScale, drawScale)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
35
room.lua
35
room.lua
|
|
@ -8,8 +8,10 @@ require "npc"
|
||||||
require "art"
|
require "art"
|
||||||
require "assorted"
|
require "assorted"
|
||||||
require "switch"
|
require "switch"
|
||||||
|
require "door"
|
||||||
|
|
||||||
function Room:initialize(t)
|
function Room:initialize(t)
|
||||||
|
self.colorsPlayerHas = {"red", "green", "blue"}
|
||||||
self.exits = t.exits
|
self.exits = t.exits
|
||||||
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)
|
||||||
|
|
@ -18,6 +20,7 @@ function Room:initialize(t)
|
||||||
self.collideables = { red = {}, green = {}, blue = {} }
|
self.collideables = { red = {}, green = {}, blue = {} }
|
||||||
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
|
self.collidableMatrices = {} --{red = {{...}{...}{...}}, ...
|
||||||
|
|
||||||
|
self.doors = {}
|
||||||
self.activeColors = {
|
self.activeColors = {
|
||||||
red = true, green = true, blue = true
|
red = true, green = true, blue = true
|
||||||
}
|
}
|
||||||
|
|
@ -28,11 +31,14 @@ function Room:initialize(t)
|
||||||
-- self.activeColors[color] = true
|
-- self.activeColors[color] = true
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
for i=0, 2 do
|
for i=1, 3 do
|
||||||
local c = randomColor()
|
local x, y = randomPosition()
|
||||||
local x, y = math.random(1, gridWidth), math.random(1, gridHeight)
|
local door = Door:new(x, y, self.colorsPlayerHas)
|
||||||
self.collideables[c]["b: " .. x .. ", " .. y] = Box:new(x, y, c)
|
table.insert(self.doors, door)
|
||||||
self.collideables[c]["b: " .. x .. ", " .. y]:getOccupiedCells()
|
|
||||||
|
for color, active in pairs(self.activeColors) do
|
||||||
|
self.collideables[color]["w: " .. x .. ", " .. y] = door
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for i=0, 5 do
|
-- for i=0, 5 do
|
||||||
|
|
@ -165,6 +171,8 @@ function Room:movePlayer(key)
|
||||||
|
|
||||||
if not self:isInBounds(initialTargetCell) then
|
if not self:isInBounds(initialTargetCell) then
|
||||||
move = true
|
move = true
|
||||||
|
elseif self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell) and self:getCellInMatrix(self.collidableMatrices["red"], initialTargetCell):canPassOver() then
|
||||||
|
move = true
|
||||||
else
|
else
|
||||||
local targetCells
|
local targetCells
|
||||||
|
|
||||||
|
|
@ -318,15 +326,16 @@ function Room:tick()
|
||||||
end
|
end
|
||||||
self:createCollideablesMatrix()
|
self:createCollideablesMatrix()
|
||||||
self:createSwitchMatrix()
|
self:createSwitchMatrix()
|
||||||
local doorsToUnloc = self:switchChec()
|
local setDoorColors = self:switchCheck()
|
||||||
for _, color in pairs(doorsToUnloc) do
|
for _, door in pairs(self.doors) do
|
||||||
print("unloc " .. color .. " doors!!")
|
print(door)
|
||||||
|
door:setColors(setDoorColors)
|
||||||
end
|
end
|
||||||
self:nextRoomCheck()
|
self:nextRoomCheck()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:switchChec()
|
function Room:switchCheck()
|
||||||
local doorsToUnloc = {}
|
local doorsToUnlock = {}
|
||||||
for color, switchArray in pairs(self.switches) do
|
for color, switchArray in pairs(self.switches) do
|
||||||
local onSwitches = {}
|
local onSwitches = {}
|
||||||
for _, switch in pairs(switchArray) do
|
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
|
table.insert(onSwitches, switch) --doesn't rly matter what we put here as long as it's true-y
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
return doorsToUnloc
|
|
||||||
|
return doorsToUnlock
|
||||||
end
|
end
|
||||||
|
|
||||||
function Room:isInBounds(cell)
|
function Room:isInBounds(cell)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue