From e45a0f41357c135669ac453e05218eb554e96756 Mon Sep 17 00:00:00 2001 From: Hyeonung Baek Date: Wed, 8 Jan 2025 19:59:24 +0900 Subject: [PATCH] Update --- entity.lua | 3 ++ item/seed.lua | 11 ++++++ main.lua | 3 +- obj/plant.lua | 22 +++++++++++ room.lua | 1 - room/sundial_alley.lua | 4 +- room/vivarium.lua | 18 +++++++++ room/vivarium_lock.lua | 87 +++++++++++++++++++++++++++++++++++++++++ room/vivarium_table.lua | 19 +++++++++ rooms.lua | 3 ++ window.lua | 14 ++++--- 11 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 item/seed.lua create mode 100644 obj/plant.lua create mode 100644 room/vivarium.lua create mode 100644 room/vivarium_lock.lua create mode 100644 room/vivarium_table.lua diff --git a/entity.lua b/entity.lua index 945d934..755d944 100644 --- a/entity.lua +++ b/entity.lua @@ -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) diff --git a/item/seed.lua b/item/seed.lua new file mode 100644 index 0000000..3c666ef --- /dev/null +++ b/item/seed.lua @@ -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 diff --git a/main.lua b/main.lua index 61a4f91..fd68cdc 100644 --- a/main.lua +++ b/main.lua @@ -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() diff --git a/obj/plant.lua b/obj/plant.lua new file mode 100644 index 0000000..7222b26 --- /dev/null +++ b/obj/plant.lua @@ -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 diff --git a/room.lua b/room.lua index c4156be..bea6fe5 100644 --- a/room.lua +++ b/room.lua @@ -48,7 +48,6 @@ function room:remove(obj) util.del_entity(self.objects, obj) end - function room:onenter() if self.update then register(self) diff --git a/room/sundial_alley.lua b/room/sundial_alley.lua index c1cf425..c559658 100644 --- a/room/sundial_alley.lua +++ b/room/sundial_alley.lua @@ -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 diff --git a/room/vivarium.lua b/room/vivarium.lua new file mode 100644 index 0000000..f6aaec8 --- /dev/null +++ b/room/vivarium.lua @@ -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 diff --git a/room/vivarium_lock.lua b/room/vivarium_lock.lua new file mode 100644 index 0000000..bd8c64b --- /dev/null +++ b/room/vivarium_lock.lua @@ -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 diff --git a/room/vivarium_table.lua b/room/vivarium_table.lua new file mode 100644 index 0000000..f093b1e --- /dev/null +++ b/room/vivarium_table.lua @@ -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 diff --git a/rooms.lua b/rooms.lua index 0e8c044..eca6a3f 100644 --- a/rooms.lua +++ b/rooms.lua @@ -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 diff --git a/window.lua b/window.lua index ffdd9a3..db22637 100644 --- a/window.lua +++ b/window.lua @@ -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