chroma_solstice/door.lua

68 lines
1.7 KiB
Lua
Raw Normal View History

2015-03-12 03:04:09 -04:00
require "entity"
Door = class("Door", Entity)
2015-03-15 07:08:35 -04:00
function Door:initialize(x, y, colors)
Entity.initialize(self, {
x = x,
y = y,
color = "white",
collision = "unmoveable",
sprite = doorSprite["white"] --doesn't matter for now which we put here b/c, we override the draw function neway
})
self.locked = true
2015-03-12 03:04:09 -04:00
2015-03-15 07:08:35 -04:00
self.colors = {}
for _, color in pairs(colors) do
self.colors[color] = true --these are currently loc_ed
end
2015-03-12 03:04:09 -04:00
end
2015-03-15 07:08:35 -04:00
function Door:draw()
if self.locked then
for color, active in pairs(self.colors) do
if active then
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite[color], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
end
end
love.graphics.setColor(gColor.white:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite["white"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
else
for color, active in pairs(self.colors) do
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(doorSprite["unlocked"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
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
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