we're back baby

This commit is contained in:
Your Name 2026-08-07 01:57:48 -04:00
parent febaaaacc7
commit e065ab83de
3 changed files with 575 additions and 577 deletions

View file

@ -2,53 +2,33 @@ require "entity"
Door = class("Door", Entity)
function Door:initialize(x, y)
function Door:initialize(x, y, color)
self.doorColor = color
Entity.initialize(self, {
x = x,
y = y,
color = "white",
color = color,
collision = "unmoveable",
sprites = {
red = loadSprite("art/game/door_r.png"),
green = loadSprite("art/game/door_g.png"),
blue = loadSprite("art/game/door_b.png"),
},
sprite = loadSprite("art/game/door_" .. color:sub(1, 1) .. ".png"),
})
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
-- 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()
self.sprites = {}
for _, c in ipairs({"red", "green", "blue"}) do
if self.locked then
if self.colors[c] then self.sprites[c] = loadSprite("art/game/door_" .. c:sub(1, 1) .. ".png") end
else
self.sprites[c] = loadSprite("art/game/door_unlocked.png")
end
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)
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 colors[self.doorColor] then
if self.locked then self:unlock() end
else
if not self.locked then self:lock() end
@ -65,4 +45,4 @@ end
function Door:lock()
self.locked = true
self.collision = "unmoveable"
end
end