68 lines
No EOL
1.4 KiB
Lua
68 lines
No EOL
1.4 KiB
Lua
require "entity"
|
|
|
|
Door = class("Door", Entity)
|
|
|
|
function Door:initialize(x, y)
|
|
Entity.initialize(self, {
|
|
x = x,
|
|
y = y,
|
|
color = "white",
|
|
collision = "unmoveable",
|
|
sprites = {
|
|
red = sprites.door.red,
|
|
green = sprites.door.green,
|
|
blue = sprites.door.blue,
|
|
},
|
|
})
|
|
self.locked = true
|
|
|
|
self.colors = {}
|
|
for _, color in pairs({"red", "green", "blue"}) do
|
|
self.colors[color] = true --these are currently loc_ed
|
|
end
|
|
self:refreshSprites()
|
|
end
|
|
|
|
-- keep the per-channel sprite map in sync with lock state so the shared
|
|
-- Entity:draw(channel) renders the door with no door-specific draw code
|
|
function Door:refreshSprites()
|
|
self.sprites = {}
|
|
for _, c in ipairs({"red", "green", "blue"}) do
|
|
if self.locked then
|
|
if self.colors[c] then self.sprites[c] = sprites.door[c] end
|
|
else
|
|
self.sprites[c] = sprites.door.unlocked
|
|
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
|
|
|
|
self:refreshSprites()
|
|
end
|
|
|
|
function Door:unlock()
|
|
self.locked = false
|
|
self.collision = "none"
|
|
end
|
|
|
|
function Door:lock()
|
|
self.locked = true
|
|
self.collision = "unmoveable"
|
|
end |