chroma_solstice/door.lua

69 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-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",
sprite = sprites.door["green"] --doesn't matter for now which we put here b/c, we override the draw function neway
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
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(sprites.door[color], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
2015-03-15 07:08:35 -04:00
end
end
love.graphics.setColor(gColor.white:set())
local p = self:getDrawPos()
love.graphics.draw(sprites.door["white"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
2015-03-15 07:08:35 -04:00
else
for color, active in pairs(self.colors) do
love.graphics.setColor(gColor[color]:set())
local p = self:getDrawPos()
love.graphics.draw(sprites.door["unlocked"], p.x + self.drawOffset.x, p.y + self.drawOffset.y, 0, drawScale, drawScale)
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
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