chroma_solstice/door.lua
2026-08-12 12:27:52 -04:00

50 lines
1.1 KiB
Lua

require "entity"
Door = class("Door", Entity)
function Door:initialize(x, y, color)
self.doorColor = color
Entity.initialize(self, {
x = x,
y = y,
color = color,
collision = "unmoveable",
sprite = loadSprite("art/game/door_" .. color:sub(1, 1) .. ".png"),
})
self.isDoor = true
self.locked = true
self:refreshSprites()
end
-- A door is one normal, colour-layered entity. The editor can therefore place,
-- delete, and serialize its red/green/blue instances independently.
function Door:refreshSprites()
local sprite
if self.locked then
sprite = loadSprite("art/game/door_" .. self.doorColor:sub(1, 1) .. ".png")
else
sprite = loadSprite("art/game/door_unlocked.png")
end
self.sprites = { [self.doorColor] = sprite }
end
function Door:setColors(colors, canClose)
if colors[self.doorColor] then
if self.locked then self:unlock() end
elseif canClose ~= false then
if not self.locked then self:lock() end
end
self:refreshSprites()
end
function Door:unlock()
self.locked = false
self.collision = "none"
if Sound then Sound.play("doorUnlock") end
end
function Door:lock()
self.locked = true
self.collision = "unmoveable"
end