chroma_solstice/door.lua

68 lines
1.5 KiB
Lua
Raw Normal View History

2015-03-12 03:04:09 -04:00
require "entity"
Door = class("Door", Entity)
2015-03-17 01:59:14 -04:00
function Door:initialize(x, y)
2015-03-15 07:08:35 -04:00
Entity.initialize(self, {
x = x,
y = y,
color = "white",
collision = "unmoveable",
2026-08-07 00:40:45 -04:00
sprites = {
2026-08-07 01:05:08 -04:00
red = loadSprite("art/game/door_r.png"),
green = loadSprite("art/game/door_g.png"),
blue = loadSprite("art/game/door_b.png"),
2026-08-07 00:40:45 -04:00
},
2015-03-15 07:08:35 -04:00
})
self.locked = true
2015-03-12 03:04:09 -04:00
2015-03-15 07:08:35 -04:00
self.colors = {}
2015-03-17 01:59:14 -04:00
for _, color in pairs({"red", "green", "blue"}) do
2015-03-15 07:08:35 -04:00
self.colors[color] = true --these are currently loc_ed
end
2026-08-07 00:40:45 -04:00
self:refreshSprites()
2015-03-12 03:04:09 -04:00
end
2026-08-07 00:40:45 -04:00
-- 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
2026-08-07 01:05:08 -04:00
if self.colors[c] then self.sprites[c] = loadSprite("art/game/door_" .. c:sub(1, 1) .. ".png") end
2026-08-07 00:40:45 -04:00
else
2026-08-07 01:05:08 -04:00
self.sprites[c] = loadSprite("art/game/door_unlocked.png")
2015-03-15 07:08:35 -04:00
end
end
end
function Door:setColors(colors)
local offColors = {}
2015-03-17 01:59:14 -04:00
2015-03-15 07:08:35 -04:00
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
2026-08-07 00:40:45 -04:00
self:refreshSprites()
2015-03-15 07:08:35 -04:00
end
function Door:unlock()
self.locked = false
2015-03-12 03:04:09 -04:00
self.collision = "none"
end
2015-03-15 07:08:35 -04:00
function Door:lock()
self.locked = true
2015-03-12 03:04:09 -04:00
self.collision = "unmoveable"
end