From 568a6c779c5c62393a1af8e14a264d117d078305 Mon Sep 17 00:00:00 2001 From: Hyeonung Baek Date: Tue, 14 Jan 2025 19:32:59 +0900 Subject: [PATCH] Update --- conf.lua | 2 + edge.lua | 5 ++ entity.lua | 8 +-- item/flask.lua | 24 +++++++ obj/door.lua | 4 +- obj/plant.lua | 23 +++++++ obj/trashcan.lua | 24 +++++++ room.lua | 4 +- room/vivarium.lua | 9 ++- room/vivarium_table.lua | 145 +++++++++++++++++++++++++++++++++++++++- window.lua | 2 +- 11 files changed, 236 insertions(+), 14 deletions(-) create mode 100644 item/flask.lua create mode 100644 obj/trashcan.lua diff --git a/conf.lua b/conf.lua index 62ba675..b33727c 100644 --- a/conf.lua +++ b/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 diff --git a/edge.lua b/edge.lua index 68f0753..bb11ae6 100644 --- a/edge.lua +++ b/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 diff --git a/entity.lua b/entity.lua index 755d944..69f3b93 100644 --- a/entity.lua +++ b/entity.lua @@ -46,8 +46,6 @@ 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(2) if type(lines[1]) == 'string' then @@ -57,13 +55,11 @@ 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) diff --git a/item/flask.lua b/item/flask.lua new file mode 100644 index 0000000..a14422d --- /dev/null +++ b/item/flask.lua @@ -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 diff --git a/obj/door.lua b/obj/door.lua index a820d26..845c6cc 100644 --- a/obj/door.lua +++ b/obj/door.lua @@ -19,13 +19,13 @@ 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) function m:keyMode() self.mousepressed = window.mousepressed(function (self) diff --git a/obj/plant.lua b/obj/plant.lua index 7222b26..952c2a4 100644 --- a/obj/plant.lua +++ b/obj/plant.lua @@ -5,11 +5,14 @@ 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() @@ -17,6 +20,26 @@ 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 diff --git a/obj/trashcan.lua b/obj/trashcan.lua new file mode 100644 index 0000000..b4e49cb --- /dev/null +++ b/obj/trashcan.lua @@ -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 diff --git a/room.lua b/room.lua index bea6fe5..c506738 100644 --- a/room.lua +++ b/room.lua @@ -28,7 +28,7 @@ end room.mousepressed = window.propagate{'edges', 'objects'} -function room:draw() +room.draw = window.draw(function (self) self:draw_lines(self.lines) for i, v in ipairs(self.objects) do @@ -38,7 +38,7 @@ function room:draw() for i, v in ipairs(self.edges) do v:draw() end -end +end) function room:insert(obj) util.add_entity(self.objects, obj) diff --git a/room/vivarium.lua b/room/vivarium.lua index f6aaec8..01a12bf 100644 --- a/room/vivarium.lua +++ b/room/vivarium.lua @@ -2,17 +2,22 @@ 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, 50, 40) +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") +edge.set(m, 'down', "Sundial alley") return m diff --git a/room/vivarium_table.lua b/room/vivarium_table.lua index f093b1e..3839e35 100644 --- a/room/vivarium_table.lua +++ b/room/vivarium_table.lua @@ -1,10 +1,145 @@ +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 m = room:from{ +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) @@ -13,7 +148,15 @@ m.draw = window.draw(function (self) 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 diff --git a/window.lua b/window.lua index db22637..f8eeb28 100644 --- a/window.lua +++ b/window.lua @@ -28,7 +28,7 @@ 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 + return true end end end