This commit is contained in:
백현웅 2025-01-08 19:59:24 +09:00
parent 069d4a03f6
commit e45a0f4135
11 changed files with 176 additions and 9 deletions

View file

@ -65,6 +65,9 @@ function m:draw()
self:draw_lines(self.lines)
end
m.mousepressed = window.mousepressed(function (self, x, y, button)
end)
function m:install(room, x, y)
self:setpos(x, y)
room:insert(self)

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

View file

@ -17,7 +17,8 @@ end
--load room list
local rooms = require("rooms")
current_room = rooms['Alley']
--current_room = rooms['Alley']
current_room = rooms['Vivarium']
function set_room_raw(r)
current_room:onexit()

22
obj/plant.lua Normal file
View file

@ -0,0 +1,22 @@
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}},
}
local m = entity:from{
width = 120,
height = 120,
}
function m:update()
end
m.draw = window.draw(function (self)
self:draw_lines(pot)
end)
return m

View file

@ -48,7 +48,6 @@ function room:remove(obj)
util.del_entity(self.objects, obj)
end
function room:onenter()
if self.update then
register(self)

View file

@ -11,7 +11,7 @@ sundial:from{
}:install(m, 140, 160)
local d = door:from{
destination = 'vivarium',
destination = 'Vivarium',
}
d:install(m, 80, 60)
@ -24,6 +24,6 @@ keypad:from{
end,
}:install(m, 160, 90)
edge.set(m, 'up', "Alley")
edge.set(m, 'down', "Alley")
return m

18
room/vivarium.lua Normal file
View file

@ -0,0 +1,18 @@
local window = require("window")
local room = require("room")
local edge = require("edge")
local plant = require("obj/plant")
local m = room:from{
}
local p = plant:from{
}
p:install(m, 50, 40)
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

19
room/vivarium_table.lua Normal file
View file

@ -0,0 +1,19 @@
local window = require("window")
local room = require("room")
local edge = require("edge")
local m = room:from{
}
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)
self.edges[1]:draw()
end)
return m

View file

@ -3,6 +3,9 @@ local m = {
['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

View file

@ -25,16 +25,20 @@ 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
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
end
w.iterate(self[tname], x, y, button)
end
end
end