67 lines
1.5 KiB
Lua
67 lines
1.5 KiB
Lua
local window = require('window')
|
|
local entity = require('entity')
|
|
|
|
local locked_door = {
|
|
{'fill', {0, 0, 0, 120, 60, 120, 60, 0}},
|
|
{'fill', {10, 10, 50, 10, 50, 50, 10, 50}},
|
|
{'line', {30, 10, 30, 50}},
|
|
{'line', {10, 30, 50, 30}},
|
|
}
|
|
|
|
local open_door = {
|
|
{'fill', {0, 0, 0, 120, 60, 120, 60, 0}},
|
|
}
|
|
|
|
local m = entity:from{
|
|
width = 60,
|
|
height = 120,
|
|
locked = true,
|
|
code = 0,
|
|
}
|
|
|
|
function m:draw()
|
|
if self.locked then
|
|
self:draw_lines(locked_door)
|
|
else
|
|
self:draw_lines(open_door)
|
|
end
|
|
end
|
|
|
|
function m:keyMode()
|
|
self.mousepressed = window.mousepressed(function (self)
|
|
if self.locked then
|
|
local i = inventory.selected_item
|
|
if i and i.code then
|
|
if i.code == self.code then
|
|
self.locked = false
|
|
inventory:use()
|
|
|
|
log:log("Door opened.")
|
|
else
|
|
log:log("This seems not a matching key.")
|
|
inventory.selected_item = nil
|
|
end
|
|
else
|
|
log:log("It's locked.")
|
|
end
|
|
else
|
|
log:format("You enter %s", self.destination)
|
|
set_room(self.destination)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function m:keypadMode()
|
|
self.mousepressed = window.mousepressed(function (self)
|
|
if self.locked then
|
|
log:log("It's locked.")
|
|
else
|
|
log:format("You enter %s", self.destination)
|
|
set_room(self.destination)
|
|
end
|
|
end)
|
|
end
|
|
|
|
m:keyMode()
|
|
|
|
return m
|