chroma_solstice/door.lua
0x81c ffa35aec89 player ca
Player.static.sounds = {
switchFail = love.audio.newSource(sounds/switch_fail.wav),
switchSuccess = love.audio.newSource(sounds/switch_success.wav)

}
2015-03-15 08:00:59 -04:00

69 lines
No EOL
1.7 KiB
Lua

require "entity"
Door = class("Door", Entity)
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: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
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:lock()
self.locked = true
self.collision = "unmoveable"
end