Compare commits

..

10 commits

Author SHA1 Message Date
d7855c69c2 Small change 2025-01-15 19:59:05 +09:00
e89fa5f15c Add hint in Sundial Alley 2025-01-14 20:00:23 +09:00
755f1889c4 Change note impl 2025-01-14 19:36:39 +09:00
568a6c779c Update 2025-01-14 19:32:59 +09:00
3a6c9ec3ad Add inventort scroll 2025-01-14 19:32:35 +09:00
e45a0f4135 Update 2025-01-08 19:59:24 +09:00
069d4a03f6 Update 2025-01-08 14:13:49 +09:00
ada33393e5 Update 2025-01-08 12:47:12 +09:00
a96f8e1aa3 Change default room drawing 2025-01-07 20:08:08 +09:00
82c0976e3c Code improvements 2025-01-06 20:21:23 +09:00
26 changed files with 825 additions and 117 deletions

View file

@ -2,6 +2,8 @@ WIDTH = 528
HEIGHT = 300 HEIGHT = 300
MULTIPLIER = 1.2 MULTIPLIER = 1.2
Seed_colour = {0.4, 0.2, 0.4}
--[[ --[[
SCREEN_WIDTH = 320 SCREEN_WIDTH = 320
SCREEN_HEIGHT = 240 SCREEN_HEIGHT = 240

View file

@ -52,6 +52,11 @@ local edge = entity:from{
end) end)
} }
edge.draw = window.draw(function (self)
love.graphics.setLineJoin('bevel')
self:draw_lines(self.lines)
end)
local mt = { local mt = {
__index = function (t, k) __index = function (t, k)
if edge_data[t.dir][k] then if edge_data[t.dir][k] then
@ -62,8 +67,8 @@ local mt = {
end end
} }
function edge:set(room, dir, dst) function edge.set(room, dir, dst)
local e = self:from{ local e = edge:from{
dir = dir, dir = dir,
destination = dst, destination = dst,
} }

View file

@ -11,15 +11,13 @@ local m = {
m.__index = m m.__index = m
function m:new() function m:from(t)
local t = {}
t.__index = t t.__index = t
return setmetatable(t, self) return setmetatable(t, self)
end end
function m:from(t) function m:new()
t.__index = t return self:from({})
return setmetatable(t, self)
end end
function m:setpos(x, y) function m:setpos(x, y)
@ -48,9 +46,7 @@ local function draw_line(l)
end end
function m:draw_lines(lines) function m:draw_lines(lines)
love.graphics.push('all') love.graphics.setLineWidth(2)
love.graphics.translate(self.x, self.y)
love.graphics.setLineWidth(3)
if type(lines[1]) == 'string' then if type(lines[1]) == 'string' then
draw_line(lines) draw_line(lines)
@ -59,15 +55,17 @@ function m:draw_lines(lines)
draw_line(l) draw_line(l)
end end
end end
love.graphics.pop()
end end
function m:draw() m.draw = window.draw(function (self)
self:draw_lines(self.lines) self:draw_lines(self.lines)
end end)
m.mousepressed = window.mousepressed(function (self, x, y, button)
end)
function m:install(room, x, y) function m:install(room, x, y)
self.room = room
self:setpos(x, y) self:setpos(x, y)
room:insert(self) room:insert(self)
end end

View file

@ -27,16 +27,17 @@ function m:itemMode()
self.mousepressed = window.mousepressed(function (self, x, y, button) self.mousepressed = window.mousepressed(function (self, x, y, button)
log:info(self) log:info(self)
inventory.selected_item = self inventory.selected_item = self
log:format("selected idx : %s", inventory.selected_item.idx)
end) end)
end end
local install = m.install
function m:install(room, x, y) function m:install(room, x, y)
local i = self:new() self:pickupMode()
i.room = room install(self, room, x, y)
i:pickupMode() end
i:setpos(x, y)
room:insert(i) function m:spawn(room, x, y)
self:new():install(room, x, y)
end end
return m return m

24
item/flask.lua Normal file
View 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
View 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
View file

@ -1,8 +1,25 @@
-- Imports -- Imports
local util = require("util") local util = require("util")
local window = require("window") local window = require("window")
local entity = require("entity")
local button = require("button") 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 -- entities that has update method
active_entities = {} active_entities = {}
@ -17,14 +34,18 @@ end
--load room list --load room list
local rooms = require("rooms") local rooms = require("rooms")
current_room = rooms['default'] current_room = rooms['Alley']
--current_room = rooms['Vivarium']
function set_room_raw(r) function set_room_raw(r)
current_room:onexit()
current_room = r current_room = r
current_room:onenter()
end end
function set_room(r) function set_room(r)
current_room = rooms[r] assert(rooms[r])
set_room_raw(rooms[r])
end end
screen = { screen = {
@ -34,7 +55,6 @@ screen = {
} }
screen.mousepressed = window.mousepressed(function (self, x, y, button) screen.mousepressed = window.mousepressed(function (self, x, y, button)
log:log(string.format("%d, %d", x, y))
current_room:mousepressed(x, y, button) current_room:mousepressed(x, y, button)
end) end)
@ -49,14 +69,102 @@ inventory = {
height = 60, height = 60,
selected_item = nil, selected_item = nil,
items = {}, 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) inventory.draw = window.draw(function (self)
for i, item in pairs(self.items) do move_left:draw()
if self.selected_item and self.selected_item.idx == i then move_right:draw()
love.graphics.circle('line', 60*i - 30, 30, 25)
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 end
item:draw() item:draw()
@ -65,15 +173,6 @@ inventory.draw = window.draw(function (self)
window.draw_border(self.width, self.height) window.draw_border(self.width, self.height)
end) 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 = { log = {
x = inventory.width , y = 0, x = inventory.width , y = 0,
width = WIDTH - screen.width, width = WIDTH - screen.width,

View file

@ -19,32 +19,49 @@ local m = entity:from{
code = 0, code = 0,
} }
function m:draw() m.draw = window.draw(function (self)
if self.locked then if self.locked then
self:draw_lines(locked_door) self:draw_lines(locked_door)
else else
self:draw_lines(open_door) self:draw_lines(open_door)
end end
end
m.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
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: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 return m

View file

@ -3,9 +3,13 @@ local entity = require('entity')
local keypad = require('room/keypad') local keypad = require('room/keypad')
local m = entity:from{ local m = entity:from{
width = 50, width = 30,
height = 50, height = 40,
lines = {'fill', {0, 0, 0, 50, 50, 50, 50, 0}}, 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, code = 45100,
} }
@ -13,14 +17,13 @@ local install = m.install
function m:install(room, x, y) function m:install(room, x, y)
self.keypad = keypad:from{ self.keypad = keypad:from{
code = self.code, code = self.code,
oncorrect = self.oncorrect,
room = room room = room
} }
install(self, room, x, y) install(self, room, x, y)
end end
m.mousepressed = window.mousepressed(function (self) m.mousepressed = window.portal("keypad")
set_room_raw(self.keypad)
end)
return m return m

45
obj/plant.lua Normal file
View 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
View 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
View 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
View 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

View file

@ -1,3 +1,4 @@
local util = require('util')
local window = require('window') local window = require('window')
local entity = require('entity') local entity = require('entity')
@ -6,37 +7,29 @@ local entity = require('entity')
-- - objects -- - objects
-- - edges -- - edges
local room = entity:from{ local room = entity:from{
background = love.graphics.newImage("res/defaultbg.png"), lines = {
edges = {}, {'fill', {80, 60, 240, 60, 240, 180, 80, 180}},
objects = {}, {'line', {0, 0, 80, 60}},
{'line', {320, 0, 240, 60}},
{'line', {0, 240, 80, 180}},
{'line', {320, 240, 240, 180}},
},
} }
local oldnew = room.new local from = room.from
function room:new() function room:from(t)
local r = oldnew(room) local r = from(self, t)
r.edges = {} r.edges = {}
r.objects = {} r.objects = {}
return r return r
end 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'} room.mousepressed = window.propagate{'edges', 'objects'}
function room:draw() room.draw = window.draw(function (self)
love.graphics.draw(self.background, 0, 0) self:draw_lines(self.lines)
for i, v in ipairs(self.objects) do for i, v in ipairs(self.objects) do
v:draw() v:draw()
@ -45,6 +38,33 @@ function room:draw()
for i, v in ipairs(self.edges) do for i, v in ipairs(self.edges) do
v:draw() v:draw()
end 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 end
return room return room

9
room/alley.lua Normal file
View 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

View file

@ -5,9 +5,9 @@ local crowbar = require('item/crowbar')
local r = room:new() local r = room:new()
crowbar:install(r, 100, 160) crowbar:install(r, 100, 160)
edge:set(r, 'up', "default") edge.set(r, 'up', "default")
edge:set(r, 'down', "default") edge.set(r, 'down', "sundial_alley")
edge:set(r, 'left', "default") edge.set(r, 'left', "default")
edge:set(r, 'right', "doortest") edge.set(r, 'right', "doortest")
return r return r

View file

@ -11,22 +11,22 @@ local m = room:from{
local oldfrom = m.from local oldfrom = m.from
function m:from(t) function m:from(t)
local kp = oldfrom(m, t) local kp = oldfrom(self, t)
local ks = self.key_size local ks = kp.key_size
local kg = self.key_gap local kg = kp.key_gap
local kd = ks + kg local kd = ks + kg
local kw = kd*3 - kg local kw = kd*3 - kg
local kh = kd*5 - kg local kh = kd*5 - kg
local sx = (320 - kw)/2 local sx, sy = room.calc_align(kw, kh)
local sy = (240 - kh)/2
kp.number = 0 kp.number = 0
kp.keys = {} kp.keys = {}
kp.padx = sx kp.pad_width = kw
kp.pady = sy kp.pad_height = kh
kp.indicator_width = kw kp.pad_x = sx
kp.pad_y = sy
kp.state = 'normal' kp.state = 'normal'
kp.timer = 0 kp.timer = 0
@ -47,15 +47,13 @@ function m:from(t)
kp.keys[0] = button.new('0', kp.keys[0] = button.new('0',
function () kp:input(0) end, function () kp:input(0) end,
sx+kd, br, ks, ks) sx + kd, br, ks, ks)
kp.keys['A'] = button.new('A', kp.keys['A'] = button.new('A',
function () kp:accept() end, function () kp:accept() end,
sx+kd*2, br, ks, ks) sx + kd*2, br, ks, ks)
edge:set(m, "down", kp.room) edge.set(kp, "down", kp.room)
register(kp)
return kp return kp
end end
@ -70,12 +68,21 @@ function m:input(n)
end end
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() function m:accept()
if self.number == self.code then if self.number == self.code then
log:log("correct!") self.state = 'correct'
self:oncorrect()
else else
self.state = 'wrong' self.state = 'wrong'
log:log("it seeems that the number does not match.") self:onwrong()
end end
end end
@ -94,13 +101,21 @@ end
m.draw = window.draw(function (self) m.draw = window.draw(function (self)
love.graphics.setLineWidth(3) love.graphics.setLineWidth(3)
-- start drawing keypad
-- draw indicator box -- 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 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 elseif self.state == 'wrong' then
love.graphics.printf("wrong", self.padx + 5, self.pady + 5, self.indicator_width - 8, 'right') display("wrong")
else else
error("keypad is not in a defined state") error("keypad is not in a defined state")
end end
@ -115,9 +130,11 @@ end)
m.mousepressed = function (self, x, y, button) m.mousepressed = function (self, x, y, button)
local x, y = x - self.x, y - self.y local x, y = x - self.x, y - self.y
for i, v in pairs(self.keys) do if self.state == 'normal' then
if v:mousepressed(x, y, button) then for i, v in pairs(self.keys) do
return if v:mousepressed(x, y, button) then
return true
end
end end
end end

55
room/sundial.lua Normal file
View 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
View 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
View 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
View 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
View 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

View file

@ -1,6 +1,11 @@
local m = { local m = {
['default'] = require('room/default'), ['default'] = require('room/default'),
['doortest'] = require('room/doortest'), ['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 return m

View file

@ -23,14 +23,17 @@ end
function m.add_entity(a, x) function m.add_entity(a, x)
table.insert(a, x) table.insert(a, x)
x.idx = #a if not x.idx then
x.idx = {}
end
x.idx[a] = #a
end end
function m.del_entity(a, x) function m.del_entity(a, x)
table.remove(a, x.idx) table.remove(a, x.idx[a])
for i, v in ipairs(a) do for i, v in ipairs(a) do
v.idx = i v.idx[a] = i
end end
end end

View file

@ -25,20 +25,30 @@ function w.mousepressed(f)
end end
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) function w.propagate(tnames)
return function (self, x, y, button) return function (self, x, y, button)
local x, y = x - self.x, y - self.y local x, y = x - self.x, y - self.y
for _, tname in ipairs(tnames) do for _, tname in ipairs(tnames) do
for i, v in util.ipairs_rev(self[tname]) do w.iterate(self[tname], x, y, button)
if v:mousepressed(x, y, button) then
return
end
end
end end
end 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) function w.draw_border(width, height)
love.graphics.push('all') love.graphics.push('all')
love.graphics.setLineWidth(5) love.graphics.setLineWidth(5)