chroma_solstice/door.lua
2026-08-07 01:57:48 -04:00

48 lines
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.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)
if colors[self.doorColor] 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