Compare commits
10 commits
d2610ee690
...
d7855c69c2
Author | SHA1 | Date | |
---|---|---|---|
d7855c69c2 | |||
e89fa5f15c | |||
755f1889c4 | |||
568a6c779c | |||
3a6c9ec3ad | |||
e45a0f4135 | |||
069d4a03f6 | |||
ada33393e5 | |||
a96f8e1aa3 | |||
82c0976e3c |
26 changed files with 825 additions and 117 deletions
2
conf.lua
2
conf.lua
|
@ -2,6 +2,8 @@ WIDTH = 528
|
|||
HEIGHT = 300
|
||||
MULTIPLIER = 1.2
|
||||
|
||||
Seed_colour = {0.4, 0.2, 0.4}
|
||||
|
||||
--[[
|
||||
SCREEN_WIDTH = 320
|
||||
SCREEN_HEIGHT = 240
|
||||
|
|
9
edge.lua
9
edge.lua
|
@ -52,6 +52,11 @@ local edge = entity:from{
|
|||
end)
|
||||
}
|
||||
|
||||
edge.draw = window.draw(function (self)
|
||||
love.graphics.setLineJoin('bevel')
|
||||
self:draw_lines(self.lines)
|
||||
end)
|
||||
|
||||
local mt = {
|
||||
__index = function (t, k)
|
||||
if edge_data[t.dir][k] then
|
||||
|
@ -62,8 +67,8 @@ local mt = {
|
|||
end
|
||||
}
|
||||
|
||||
function edge:set(room, dir, dst)
|
||||
local e = self:from{
|
||||
function edge.set(room, dir, dst)
|
||||
local e = edge:from{
|
||||
dir = dir,
|
||||
destination = dst,
|
||||
}
|
||||
|
|
22
entity.lua
22
entity.lua
|
@ -11,15 +11,13 @@ local m = {
|
|||
|
||||
m.__index = m
|
||||
|
||||
function m:new()
|
||||
local t = {}
|
||||
function m:from(t)
|
||||
t.__index = t
|
||||
return setmetatable(t, self)
|
||||
end
|
||||
|
||||
function m:from(t)
|
||||
t.__index = t
|
||||
return setmetatable(t, self)
|
||||
function m:new()
|
||||
return self:from({})
|
||||
end
|
||||
|
||||
function m:setpos(x, y)
|
||||
|
@ -48,9 +46,7 @@ local function draw_line(l)
|
|||
end
|
||||
|
||||
function m:draw_lines(lines)
|
||||
love.graphics.push('all')
|
||||
love.graphics.translate(self.x, self.y)
|
||||
love.graphics.setLineWidth(3)
|
||||
love.graphics.setLineWidth(2)
|
||||
|
||||
if type(lines[1]) == 'string' then
|
||||
draw_line(lines)
|
||||
|
@ -59,15 +55,17 @@ function m:draw_lines(lines)
|
|||
draw_line(l)
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
function m:draw()
|
||||
m.draw = window.draw(function (self)
|
||||
self:draw_lines(self.lines)
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
end)
|
||||
|
||||
function m:install(room, x, y)
|
||||
self.room = room
|
||||
self:setpos(x, y)
|
||||
room:insert(self)
|
||||
end
|
||||
|
|
13
item.lua
13
item.lua
|
@ -27,16 +27,17 @@ function m:itemMode()
|
|||
self.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
log:info(self)
|
||||
inventory.selected_item = self
|
||||
log:format("selected idx : %s", inventory.selected_item.idx)
|
||||
end)
|
||||
end
|
||||
|
||||
local install = m.install
|
||||
function m:install(room, x, y)
|
||||
local i = self:new()
|
||||
i.room = room
|
||||
i:pickupMode()
|
||||
i:setpos(x, y)
|
||||
room:insert(i)
|
||||
self:pickupMode()
|
||||
install(self, room, x, y)
|
||||
end
|
||||
|
||||
function m:spawn(room, x, y)
|
||||
self:new():install(room, x, y)
|
||||
end
|
||||
|
||||
return m
|
||||
|
|
24
item/flask.lua
Normal file
24
item/flask.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
local window = require('window')
|
||||
local item = require('item')
|
||||
|
||||
local line = {
|
||||
15, 0, 25, 0,
|
||||
40, 40, 0, 40,
|
||||
}
|
||||
|
||||
local m = item:from{
|
||||
width = 40,
|
||||
height = 40,
|
||||
colour = {0, 0, 0},
|
||||
name = "Flask",
|
||||
description = "A glass container filled with liquid.",
|
||||
}
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.setColor(self.colour)
|
||||
love.graphics.polygon('fill', line)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.polygon('line', line)
|
||||
end)
|
||||
|
||||
return m
|
11
item/seed.lua
Normal file
11
item/seed.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
local item = require("item")
|
||||
|
||||
local m = item:from{
|
||||
name = "Seed",
|
||||
description = "A reproductive capsule for plants.",
|
||||
width = 20,
|
||||
height = 20,
|
||||
lines = {'fill', {0, 5, 5, 0, 20, 10, 20, 15, 15, 20, 10, 15}},
|
||||
}
|
||||
|
||||
return m
|
131
main.lua
131
main.lua
|
@ -1,8 +1,25 @@
|
|||
-- Imports
|
||||
local util = require("util")
|
||||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
local button = require("button")
|
||||
|
||||
function min(a, b)
|
||||
if a < b then
|
||||
return a
|
||||
else
|
||||
return b
|
||||
end
|
||||
end
|
||||
|
||||
function max(a, b)
|
||||
if a > b then
|
||||
return a
|
||||
else
|
||||
return b
|
||||
end
|
||||
end
|
||||
|
||||
-- entities that has update method
|
||||
active_entities = {}
|
||||
|
||||
|
@ -17,14 +34,18 @@ end
|
|||
--load room list
|
||||
local rooms = require("rooms")
|
||||
|
||||
current_room = rooms['default']
|
||||
current_room = rooms['Alley']
|
||||
--current_room = rooms['Vivarium']
|
||||
|
||||
function set_room_raw(r)
|
||||
current_room:onexit()
|
||||
current_room = r
|
||||
current_room:onenter()
|
||||
end
|
||||
|
||||
function set_room(r)
|
||||
current_room = rooms[r]
|
||||
assert(rooms[r])
|
||||
set_room_raw(rooms[r])
|
||||
end
|
||||
|
||||
screen = {
|
||||
|
@ -34,7 +55,6 @@ screen = {
|
|||
}
|
||||
|
||||
screen.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
log:log(string.format("%d, %d", x, y))
|
||||
current_room:mousepressed(x, y, button)
|
||||
end)
|
||||
|
||||
|
@ -49,14 +69,102 @@ inventory = {
|
|||
height = 60,
|
||||
selected_item = nil,
|
||||
items = {},
|
||||
item_idx = 1,
|
||||
}
|
||||
|
||||
inventory.mousepressed = window.propagate{'items'}
|
||||
local cells = math.floor((inventory.width - 60) / 60)
|
||||
|
||||
function inventory:setpos(idx, item)
|
||||
local x = 30 + (idx - 1) * 60 + (60 - item.width) / 2
|
||||
local y = (60 - item.height) / 2
|
||||
|
||||
item:setpos(x, y)
|
||||
end
|
||||
|
||||
function inventory:move(d)
|
||||
self.item_idx = self.item_idx + d
|
||||
|
||||
if self.item_idx < 1 then
|
||||
self.item_idx = 1
|
||||
elseif self.item_idx + cells - 1 > #self.items then
|
||||
self.item_idx = max(1, #self.items - cells + 1)
|
||||
end
|
||||
|
||||
for i = 1, min(#self.items, cells) do
|
||||
local idx = self.item_idx + i - 1
|
||||
self:setpos(i, self.items[idx])
|
||||
end
|
||||
end
|
||||
|
||||
function inventory:pickup(item)
|
||||
util.add_entity(self.items, item)
|
||||
self:move(#self.items)
|
||||
end
|
||||
|
||||
function inventory:drop(item)
|
||||
util.del_entity(self.items, item)
|
||||
self:move(0)
|
||||
end
|
||||
|
||||
function inventory:use()
|
||||
self:drop(self.selected_item)
|
||||
self.selected_item = nil
|
||||
end
|
||||
|
||||
local move_left = entity:from{
|
||||
x = 0, y = 0,
|
||||
width = 20,
|
||||
height = 60,
|
||||
}
|
||||
|
||||
move_left.draw = window.draw(function (self)
|
||||
love.graphics.polygon('line', 15, 5, 5, 30, 15, 55)
|
||||
end)
|
||||
|
||||
move_left.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
inventory:move(-1)
|
||||
end)
|
||||
|
||||
local move_right = entity:from{
|
||||
x = inventory.width - 20,
|
||||
y = 0,
|
||||
width = 20,
|
||||
height = 60,
|
||||
}
|
||||
|
||||
move_right.draw = window.draw(function (self)
|
||||
love.graphics.polygon('line', 5, 5, 15, 30, 5, 55)
|
||||
end)
|
||||
|
||||
move_right.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
inventory:move(1)
|
||||
end)
|
||||
|
||||
inventory.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
move_left:mousepressed(x, y, button)
|
||||
move_right:mousepressed(x, y, button)
|
||||
|
||||
for i = 1, min(cells, #self.items) do
|
||||
local item = self.items[self.item_idx + i - 1]
|
||||
|
||||
if item:mousepressed(x, y, button) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
inventory.selected_item = nil
|
||||
end)
|
||||
|
||||
inventory.draw = window.draw(function (self)
|
||||
for i, item in pairs(self.items) do
|
||||
if self.selected_item and self.selected_item.idx == i then
|
||||
love.graphics.circle('line', 60*i - 30, 30, 25)
|
||||
move_left:draw()
|
||||
move_right:draw()
|
||||
|
||||
for i = 1, min(#self.items, cells) do
|
||||
local idx = i + self.item_idx - 1
|
||||
local item = self.items[idx]
|
||||
|
||||
if self.selected_item and self.selected_item == item then
|
||||
love.graphics.circle('line', 60*i, 30, 25)
|
||||
end
|
||||
|
||||
item:draw()
|
||||
|
@ -65,15 +173,6 @@ inventory.draw = window.draw(function (self)
|
|||
window.draw_border(self.width, self.height)
|
||||
end)
|
||||
|
||||
function inventory:pickup(item)
|
||||
util.add_entity(self.items, item)
|
||||
|
||||
local x = (#self.items - 1) * 60 + (60 - item.width) / 2
|
||||
local y = (60 - item.height) / 2
|
||||
|
||||
item:setpos(x, y)
|
||||
end
|
||||
|
||||
log = {
|
||||
x = inventory.width , y = 0,
|
||||
width = WIDTH - screen.width,
|
||||
|
|
23
obj/door.lua
23
obj/door.lua
|
@ -19,20 +19,23 @@ local m = entity:from{
|
|||
code = 0,
|
||||
}
|
||||
|
||||
function m:draw()
|
||||
m.draw = window.draw(function (self)
|
||||
if self.locked then
|
||||
self:draw_lines(locked_door)
|
||||
else
|
||||
self:draw_lines(open_door)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self)
|
||||
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.")
|
||||
|
@ -46,5 +49,19 @@ m.mousepressed = window.mousepressed(function (self)
|
|||
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
|
||||
|
|
|
@ -3,9 +3,13 @@ local entity = require('entity')
|
|||
local keypad = require('room/keypad')
|
||||
|
||||
local m = entity:from{
|
||||
width = 50,
|
||||
height = 50,
|
||||
lines = {'fill', {0, 0, 0, 50, 50, 50, 50, 0}},
|
||||
width = 30,
|
||||
height = 40,
|
||||
lines = {
|
||||
{'fill', {0, 0, 0, 40, 30, 40, 30, 0}},
|
||||
{'fill', {5, 5, 25, 5, 25, 10, 5, 10}},
|
||||
{'fill', {5, 15, 25, 15, 25, 35, 5, 35}},
|
||||
},
|
||||
code = 45100,
|
||||
}
|
||||
|
||||
|
@ -13,14 +17,13 @@ local install = m.install
|
|||
function m:install(room, x, y)
|
||||
self.keypad = keypad:from{
|
||||
code = self.code,
|
||||
oncorrect = self.oncorrect,
|
||||
room = room
|
||||
}
|
||||
|
||||
install(self, room, x, y)
|
||||
end
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self)
|
||||
set_room_raw(self.keypad)
|
||||
end)
|
||||
m.mousepressed = window.portal("keypad")
|
||||
|
||||
return m
|
||||
|
|
45
obj/plant.lua
Normal file
45
obj/plant.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
local entity = require("entity")
|
||||
local window = require("window")
|
||||
local seed = require("item/seed")
|
||||
|
||||
local pot = {
|
||||
{'fill', {60, 80, 100, 80, 100, 90, 60, 90}},
|
||||
{'fill', {65, 90, 95, 90, 90, 120, 70, 120}},
|
||||
{'line', {80, 80, 70, 60, 60, 50}},
|
||||
{'line', {70, 60, 80, 50}},
|
||||
}
|
||||
|
||||
local m = entity:from{
|
||||
width = 120,
|
||||
height = 120,
|
||||
grown = false,
|
||||
}
|
||||
|
||||
function m:update()
|
||||
end
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
self:draw_lines(pot)
|
||||
|
||||
if grown then
|
||||
love.graphics.circle('fill', 80, 50, 5)
|
||||
for i = 0, 7 do
|
||||
local x = 80 + 7 * math.sin(math.pi * i)
|
||||
local y = 50 + 7 * math.cos(math.pi * i)
|
||||
love.graphics.line(80, 50, x, y)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
local i = inventory.selected_item
|
||||
|
||||
if i and i.name == "Flask" then
|
||||
inventory:use()
|
||||
local seed = seed:from{ colour = i.colour }
|
||||
self.grown = true
|
||||
seed:install(self.room, self.width + 80, self.height + 50)
|
||||
end
|
||||
end)
|
||||
|
||||
return m
|
23
obj/sign.lua
Normal file
23
obj/sign.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
local entity = require("entity")
|
||||
local window = require("window")
|
||||
|
||||
local m = entity:from{
|
||||
width = 40,
|
||||
height = 20,
|
||||
text = "sample text",
|
||||
}
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.rectangle('fill', 0, 0, self.width, self.height)
|
||||
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
for i = 1, self.height/5 - 1 do
|
||||
love.graphics.line(5, 5*i, self.width - 5, 5*i)
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
log:log("It reads: " .. self.text)
|
||||
end)
|
||||
|
||||
return m
|
31
obj/sundial.lua
Normal file
31
obj/sundial.lua
Normal file
|
@ -0,0 +1,31 @@
|
|||
local entity = require("entity")
|
||||
local window = require("window")
|
||||
local sundial = require("room/sundial")
|
||||
|
||||
local m = entity:from{
|
||||
width = 60,
|
||||
height = 60,
|
||||
}
|
||||
|
||||
local install = m.install
|
||||
function m:install(room, x, y)
|
||||
self.sundial = sundial:from{
|
||||
numbers = self.numbers,
|
||||
room = room,
|
||||
}
|
||||
|
||||
install(self, room, x, y)
|
||||
end
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.ellipse('fill', 30, 45, 30, 15, 12)
|
||||
love.graphics.polygon('fill', 30, 45, 55, 45, 30, 15)
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
love.graphics.polygon('fill', 30, 45, 55, 45, 40, 55)
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self)
|
||||
set_room_raw(self.sundial)
|
||||
end)
|
||||
|
||||
return m
|
24
obj/trashcan.lua
Normal file
24
obj/trashcan.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
local util = require("util")
|
||||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
|
||||
local m = entity:from{
|
||||
width = 50,
|
||||
height = 50,
|
||||
lines = {'fill', {0, 0, 50, 0, 40, 50, 10, 50}},
|
||||
items = {},
|
||||
}
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
local i = inventory.selected_item
|
||||
if i then
|
||||
util.add_entity(self.items, i)
|
||||
inventory:use()
|
||||
elseif #self.items > 0 then
|
||||
local last = self.items[#self.items]
|
||||
util.del_entity(self.items, last)
|
||||
inventory:pickup(last)
|
||||
end
|
||||
end)
|
||||
|
||||
return m
|
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
62
room.lua
62
room.lua
|
@ -1,3 +1,4 @@
|
|||
local util = require('util')
|
||||
local window = require('window')
|
||||
local entity = require('entity')
|
||||
|
||||
|
@ -6,37 +7,29 @@ local entity = require('entity')
|
|||
-- - objects
|
||||
-- - edges
|
||||
local room = entity:from{
|
||||
background = love.graphics.newImage("res/defaultbg.png"),
|
||||
edges = {},
|
||||
objects = {},
|
||||
lines = {
|
||||
{'fill', {80, 60, 240, 60, 240, 180, 80, 180}},
|
||||
{'line', {0, 0, 80, 60}},
|
||||
{'line', {320, 0, 240, 60}},
|
||||
{'line', {0, 240, 80, 180}},
|
||||
{'line', {320, 240, 240, 180}},
|
||||
},
|
||||
}
|
||||
|
||||
local oldnew = room.new
|
||||
function room:new()
|
||||
local r = oldnew(room)
|
||||
local from = room.from
|
||||
function room:from(t)
|
||||
local r = from(self, t)
|
||||
|
||||
r.edges = {}
|
||||
r.objects = {}
|
||||
|
||||
return r
|
||||
end
|
||||
|
||||
function room:insert(obj)
|
||||
table.insert(self.objects, obj)
|
||||
obj.idx = #self.objects
|
||||
end
|
||||
|
||||
function room:remove(obj)
|
||||
table.remove(self.objects, obj.idx)
|
||||
|
||||
for i, v in ipairs(self.objects) do
|
||||
v.idx = i
|
||||
end
|
||||
end
|
||||
|
||||
room.mousepressed = window.propagate{'edges', 'objects'}
|
||||
|
||||
function room:draw()
|
||||
love.graphics.draw(self.background, 0, 0)
|
||||
room.draw = window.draw(function (self)
|
||||
self:draw_lines(self.lines)
|
||||
|
||||
for i, v in ipairs(self.objects) do
|
||||
v:draw()
|
||||
|
@ -45,6 +38,33 @@ function room:draw()
|
|||
for i, v in ipairs(self.edges) do
|
||||
v:draw()
|
||||
end
|
||||
end)
|
||||
|
||||
function room:insert(obj)
|
||||
util.add_entity(self.objects, obj)
|
||||
end
|
||||
|
||||
function room:remove(obj)
|
||||
util.del_entity(self.objects, obj)
|
||||
end
|
||||
|
||||
function room:onenter()
|
||||
if self.update then
|
||||
register(self)
|
||||
end
|
||||
end
|
||||
|
||||
function room:onexit()
|
||||
if self.update then
|
||||
unregister(self)
|
||||
end
|
||||
end
|
||||
|
||||
function room.calc_align(width, height)
|
||||
local sx = (320 - width)/2
|
||||
local sy = (240 - height)/2
|
||||
|
||||
return sx, sy
|
||||
end
|
||||
|
||||
return room
|
||||
|
|
9
room/alley.lua
Normal file
9
room/alley.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
|
||||
local m = room:new()
|
||||
|
||||
edge.set(m, 'down', "Sundial alley")
|
||||
--edge.set(m, 'left', "alley2")
|
||||
|
||||
return m
|
|
@ -5,9 +5,9 @@ local crowbar = require('item/crowbar')
|
|||
local r = room:new()
|
||||
|
||||
crowbar:install(r, 100, 160)
|
||||
edge:set(r, 'up', "default")
|
||||
edge:set(r, 'down', "default")
|
||||
edge:set(r, 'left', "default")
|
||||
edge:set(r, 'right', "doortest")
|
||||
edge.set(r, 'up', "default")
|
||||
edge.set(r, 'down', "sundial_alley")
|
||||
edge.set(r, 'left', "default")
|
||||
edge.set(r, 'right', "doortest")
|
||||
|
||||
return r
|
||||
|
|
|
@ -11,22 +11,22 @@ local m = room:from{
|
|||
|
||||
local oldfrom = m.from
|
||||
function m:from(t)
|
||||
local kp = oldfrom(m, t)
|
||||
local kp = oldfrom(self, t)
|
||||
|
||||
local ks = self.key_size
|
||||
local kg = self.key_gap
|
||||
local ks = kp.key_size
|
||||
local kg = kp.key_gap
|
||||
|
||||
local kd = ks + kg
|
||||
local kw = kd*3 - kg
|
||||
local kh = kd*5 - kg
|
||||
local sx = (320 - kw)/2
|
||||
local sy = (240 - kh)/2
|
||||
local sx, sy = room.calc_align(kw, kh)
|
||||
|
||||
kp.number = 0
|
||||
kp.keys = {}
|
||||
kp.padx = sx
|
||||
kp.pady = sy
|
||||
kp.indicator_width = kw
|
||||
kp.pad_width = kw
|
||||
kp.pad_height = kh
|
||||
kp.pad_x = sx
|
||||
kp.pad_y = sy
|
||||
kp.state = 'normal'
|
||||
kp.timer = 0
|
||||
|
||||
|
@ -53,9 +53,7 @@ function m:from(t)
|
|||
function () kp:accept() end,
|
||||
sx + kd*2, br, ks, ks)
|
||||
|
||||
edge:set(m, "down", kp.room)
|
||||
|
||||
register(kp)
|
||||
edge.set(kp, "down", kp.room)
|
||||
|
||||
return kp
|
||||
end
|
||||
|
@ -70,12 +68,21 @@ function m:input(n)
|
|||
end
|
||||
end
|
||||
|
||||
function m:oncorrect()
|
||||
log:log("Correct!")
|
||||
end
|
||||
|
||||
function m:onwrong()
|
||||
log:log("it seeems that the number does not match.")
|
||||
end
|
||||
|
||||
function m:accept()
|
||||
if self.number == self.code then
|
||||
log:log("correct!")
|
||||
self.state = 'correct'
|
||||
self:oncorrect()
|
||||
else
|
||||
self.state = 'wrong'
|
||||
log:log("it seeems that the number does not match.")
|
||||
self:onwrong()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -94,13 +101,21 @@ end
|
|||
m.draw = window.draw(function (self)
|
||||
love.graphics.setLineWidth(3)
|
||||
|
||||
-- start drawing keypad
|
||||
|
||||
-- draw indicator box
|
||||
love.graphics.rectangle('line', self.padx, self.pady, self.indicator_width, self.key_size)
|
||||
love.graphics.rectangle('line', self.pad_x, self.pad_y, self.pad_width, self.key_size)
|
||||
|
||||
local function display(str)
|
||||
love.graphics.printf(str, self.pad_x + 5, self.pad_y + 5, self.pad_width - 8, 'right')
|
||||
end
|
||||
|
||||
if self.state == 'normal' then
|
||||
love.graphics.printf(tostring(self.number), self.padx + 5, self.pady + 5, self.indicator_width - 8, 'right')
|
||||
display(tostring(self.number))
|
||||
elseif self.state == 'correct' then
|
||||
display("correct")
|
||||
elseif self.state == 'wrong' then
|
||||
love.graphics.printf("wrong", self.padx + 5, self.pady + 5, self.indicator_width - 8, 'right')
|
||||
display("wrong")
|
||||
else
|
||||
error("keypad is not in a defined state")
|
||||
end
|
||||
|
@ -115,9 +130,11 @@ end)
|
|||
m.mousepressed = function (self, x, y, button)
|
||||
local x, y = x - self.x, y - self.y
|
||||
|
||||
if self.state == 'normal' then
|
||||
for i, v in pairs(self.keys) do
|
||||
if v:mousepressed(x, y, button) then
|
||||
return
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
55
room/sundial.lua
Normal file
55
room/sundial.lua
Normal file
|
@ -0,0 +1,55 @@
|
|||
local window = require("window")
|
||||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
|
||||
local clock_size = 60
|
||||
local arm_size = 55
|
||||
|
||||
local m = room:new()
|
||||
|
||||
local from = m.from
|
||||
function m:from(t)
|
||||
local sd = from(self, t)
|
||||
|
||||
sd.tick = 0
|
||||
sd.ni = 1
|
||||
|
||||
edge.set(sd, 'down', sd.room)
|
||||
|
||||
register(sd)
|
||||
|
||||
return sd
|
||||
end
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.circle('fill', 160, 120, clock_size, 12)
|
||||
|
||||
local s = math.pi * self.numbers[self.ni] / 6
|
||||
local x = 160 + arm_size * math.sin(s)
|
||||
local y = 120 - arm_size * math.cos(s)
|
||||
local n = 120 - arm_size
|
||||
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
love.graphics.polygon('fill', 160, n, 160, 120, x, y)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.polygon('fill', 160, n, 160, 120, 140, n)
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
love.graphics.polygon('line', 160, n, 160, 120, 140, n)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
|
||||
self.edges[1]:draw()
|
||||
end)
|
||||
|
||||
function m:update(dt)
|
||||
self.tick = self.tick + dt
|
||||
|
||||
if self.tick > 2 then
|
||||
self.tick = self.tick - 2
|
||||
self.ni = self.ni + 1
|
||||
if self.ni > #self.numbers then
|
||||
self.ni = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
34
room/sundial_alley.lua
Normal file
34
room/sundial_alley.lua
Normal file
|
@ -0,0 +1,34 @@
|
|||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local sundial = require("obj/sundial")
|
||||
local keypad = require("obj/keypad")
|
||||
local door = require("obj/door")
|
||||
local sign = require("obj/sign")
|
||||
|
||||
local m = room:new()
|
||||
|
||||
sundial:from{
|
||||
numbers = {3, 5, 8, 2, 7},
|
||||
}:install(m, 135, 155)
|
||||
|
||||
local d = door:from{
|
||||
destination = 'Vivarium',
|
||||
}
|
||||
|
||||
d.mousepressed = d.keypadMode
|
||||
d:install(m, 80, 60)
|
||||
|
||||
keypad:from{
|
||||
code = 35827,
|
||||
oncorrect = function (self)
|
||||
d.locked = false
|
||||
end,
|
||||
}:install(m, 165, 110)
|
||||
|
||||
sign:from{
|
||||
text = "If you desire to enter, you should follow the shadow"
|
||||
}:install(m, 160, 80)
|
||||
|
||||
edge.set(m, 'down', "Alley")
|
||||
|
||||
return m
|
23
room/vivarium.lua
Normal file
23
room/vivarium.lua
Normal file
|
@ -0,0 +1,23 @@
|
|||
local window = require("window")
|
||||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local plant = require("obj/plant")
|
||||
local trashcan = require("obj/trashcan")
|
||||
|
||||
local m = room:from{
|
||||
}
|
||||
|
||||
local p = plant:from{
|
||||
colour = Seed_colour,
|
||||
room = m,
|
||||
}
|
||||
|
||||
p:install(m, 40, 80)
|
||||
|
||||
trashcan:new():install(m, 180, 140)
|
||||
|
||||
edge.set(m, 'left', "vivarium_table")
|
||||
edge.set(m, 'right', "vivarium_lock")
|
||||
edge.set(m, 'down', "Sundial alley")
|
||||
|
||||
return m
|
87
room/vivarium_lock.lua
Normal file
87
room/vivarium_lock.lua
Normal file
|
@ -0,0 +1,87 @@
|
|||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local button = require("button")
|
||||
local seed = require("item/seed")
|
||||
|
||||
local shelf = entity:from{
|
||||
width = 60,
|
||||
height = 60,
|
||||
item = nil
|
||||
}
|
||||
|
||||
shelf.draw = window.draw(function (self)
|
||||
love.graphics.setLineWidth(3)
|
||||
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
love.graphics.rectangle('fill', 0, 0, self.width, self.height)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
||||
|
||||
if self.item then
|
||||
self.item:draw()
|
||||
end
|
||||
end)
|
||||
|
||||
shelf.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
if self.item then
|
||||
inventory:pickup(self.item)
|
||||
self.item = nil
|
||||
self.item:setpos(20, 20)
|
||||
else
|
||||
local i = inventory.selected_item
|
||||
if i and i.name == "Seed" then
|
||||
self.item = i
|
||||
inventory:use()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local indicator = entity:from{
|
||||
width = 100,
|
||||
height = 20,
|
||||
text = "",
|
||||
}
|
||||
|
||||
indicator.draw = window.draw(function (self)
|
||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
||||
love.graphics.printf(self.text, 5, 5, self.width - 10)
|
||||
end)
|
||||
|
||||
local m = room:from{
|
||||
state = 'normal',
|
||||
timer = 0,
|
||||
lines = {},
|
||||
}
|
||||
|
||||
local btn = button.new("Check", function ()
|
||||
indicator.text = "Checking..."
|
||||
m.state = 'checking'
|
||||
end,
|
||||
200, 120, 60, 30)
|
||||
|
||||
function m:update(dt)
|
||||
if self.state == 'checking' then
|
||||
self.timer = self.timer + dt
|
||||
|
||||
if self.timer > 5 then
|
||||
indicator.text = "done"
|
||||
self.state = 'normal'
|
||||
self.timer = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
m:insert(btn)
|
||||
|
||||
indicator:install(m, 200, 90)
|
||||
|
||||
seed:new():install(m, 150, 120)
|
||||
|
||||
shelf:install(m, 60, 90)
|
||||
|
||||
edge.set(m, 'down', "Vivarium")
|
||||
|
||||
return m
|
162
room/vivarium_table.lua
Normal file
162
room/vivarium_table.lua
Normal file
|
@ -0,0 +1,162 @@
|
|||
local util = require("util")
|
||||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local button = require("button")
|
||||
local flask = require("item/flask")
|
||||
|
||||
local function getColor(c)
|
||||
local t = {
|
||||
Red = { 1, 0, 0 },
|
||||
Green = { 0, 1, 0 },
|
||||
Blue = { 0, 0, 1 },
|
||||
}
|
||||
|
||||
if type(c) == "string" then
|
||||
return t[c]
|
||||
else
|
||||
return c
|
||||
end
|
||||
end
|
||||
|
||||
local mixer = entity:from{
|
||||
width = 130,
|
||||
height = 110,
|
||||
con_width = 60,
|
||||
con_height = 100,
|
||||
colours = {},
|
||||
timer = 0,
|
||||
anim = 0,
|
||||
}
|
||||
|
||||
function mixer:empty()
|
||||
self.colours = {}
|
||||
self.anim = 0
|
||||
end
|
||||
|
||||
local mempty = button.new("Empty", function ()
|
||||
mixer:empty()
|
||||
end,
|
||||
75, 5, 50, 45)
|
||||
|
||||
local mmix = button.new("Mix", function ()
|
||||
local len = #mixer.colours
|
||||
local c = {0, 0, 0}
|
||||
|
||||
for k, v in ipairs(mixer.colours) do
|
||||
local v = getColor(v)
|
||||
for i = 1, 3 do
|
||||
c[i] = c[i] + v[i]
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
c[i] = c[i] / len
|
||||
end
|
||||
|
||||
mixer.colours = {}
|
||||
for i = 1, len do
|
||||
mixer.colours[i] = c
|
||||
end
|
||||
end,
|
||||
75, 60, 50, 45)
|
||||
|
||||
mixer.draw = window.draw(function (self)
|
||||
local y = self.con_height + 5
|
||||
for i, v in ipairs(self.colours) do
|
||||
love.graphics.setColor(getColor(v))
|
||||
local h = 5
|
||||
if i == #self.colours then
|
||||
h = h * self.anim
|
||||
end
|
||||
y = y - h
|
||||
|
||||
love.graphics.rectangle('fill', 5, y, self.con_width, h)
|
||||
end
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
|
||||
mempty:draw()
|
||||
mmix:draw()
|
||||
|
||||
love.graphics.rectangle('line', 5, 5, self.con_width, self.con_height)
|
||||
|
||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
||||
end)
|
||||
|
||||
mixer.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
if util.inside(x, y, 5, 5, self.con_width, self.con_height) and #self.colours > 0 then
|
||||
local f = flask:from{ colour = getColor(self.colours[1]) }
|
||||
f:itemMode()
|
||||
inventory:pickup(f)
|
||||
self:empty()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
window.iterate({mempty, mmix}, x, y, button)
|
||||
end)
|
||||
|
||||
mixer.update = function (self, dt)
|
||||
self.timer = self.timer + dt
|
||||
if self.timer > 1/20 then
|
||||
self.timer = self.timer - 1/20
|
||||
self.anim = self.anim + 1/20
|
||||
if self.anim > 1 then
|
||||
self.anim = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mixer:add(colour)
|
||||
table.insert(self.colours, colour)
|
||||
self.anim = 0
|
||||
end
|
||||
|
||||
local vial = entity:from {
|
||||
width = 20,
|
||||
height = 60,
|
||||
colour = ""
|
||||
}
|
||||
|
||||
vial.draw = window.draw(function (self)
|
||||
love.graphics.setColor(getColor(self.colour))
|
||||
love.graphics.rectangle('fill', 0, 0, 20, 50)
|
||||
love.graphics.arc('fill', 'open', 10, 50, 10, 0, math.pi)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.line(0, 50, 0, 0, 20, 0, 20, 50)
|
||||
love.graphics.arc('line', 'open', 10, 50, 10, 0, math.pi)
|
||||
end)
|
||||
|
||||
vial.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
mixer:add(self.colour)
|
||||
end)
|
||||
|
||||
local m = room:new()
|
||||
|
||||
mixer:install(m, 160, 40)
|
||||
vial:from{ colour = "Red" }:install(m, 20, 40)
|
||||
vial:from{ colour = "Green" }:install(m, 60, 40)
|
||||
vial:from{ colour = "Blue" }:install(m, 100, 40)
|
||||
|
||||
edge.set(m, 'down', "Vivarium")
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.setLineWidth(3)
|
||||
love.graphics.line(0, 200, 320, 200)
|
||||
love.graphics.rectangle('line', 10, 200, 20, 40)
|
||||
love.graphics.rectangle('line', 290, 200, 20, 40)
|
||||
|
||||
for i, v in ipairs(self.objects) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
self.edges[1]:draw()
|
||||
end)
|
||||
|
||||
m.update = function (self, dt)
|
||||
mixer:update(dt)
|
||||
end
|
||||
|
||||
return m
|
|
@ -1,6 +1,11 @@
|
|||
local m = {
|
||||
['default'] = require('room/default'),
|
||||
['doortest'] = require('room/doortest'),
|
||||
['Alley'] = require("room/alley"),
|
||||
['Sundial alley'] = require("room/sundial_alley"),
|
||||
['Vivarium'] = require("room/vivarium"),
|
||||
['vivarium_table'] = require("room/vivarium_table"),
|
||||
['vivarium_lock'] = require("room/vivarium_lock"),
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
9
util.lua
9
util.lua
|
@ -23,14 +23,17 @@ end
|
|||
|
||||
function m.add_entity(a, x)
|
||||
table.insert(a, x)
|
||||
x.idx = #a
|
||||
if not x.idx then
|
||||
x.idx = {}
|
||||
end
|
||||
x.idx[a] = #a
|
||||
end
|
||||
|
||||
function m.del_entity(a, x)
|
||||
table.remove(a, x.idx)
|
||||
table.remove(a, x.idx[a])
|
||||
|
||||
for i, v in ipairs(a) do
|
||||
v.idx = i
|
||||
v.idx[a] = i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
18
window.lua
18
window.lua
|
@ -25,18 +25,28 @@ function w.mousepressed(f)
|
|||
end
|
||||
end
|
||||
|
||||
function w.iterate(t, x, y, button)
|
||||
for i, v in util.ipairs_rev(t) do
|
||||
if v:mousepressed(x, y, button) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function w.propagate(tnames)
|
||||
return function (self, x, y, button)
|
||||
local x, y = x - self.x, y - self.y
|
||||
|
||||
for _, tname in ipairs(tnames) do
|
||||
for i, v in util.ipairs_rev(self[tname]) do
|
||||
if v:mousepressed(x, y, button) then
|
||||
return
|
||||
end
|
||||
w.iterate(self[tname], x, y, button)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function w.portal(room)
|
||||
return w.mousepressed(function (self, x, y, button)
|
||||
set_room_raw(self[room])
|
||||
end)
|
||||
end
|
||||
|
||||
function w.draw_border(width, height)
|
||||
|
|
Loading…
Add table
Reference in a new issue