From 3c4c6df308a9ede4dbb783b98890f9ddb21ec9af Mon Sep 17 00:00:00 2001 From: Hyeonung Baek Date: Wed, 1 Jan 2025 15:12:54 +0900 Subject: [PATCH] Update --- button.lua | 4 ++-- conf.lua | 6 ++--- export.sh | 2 +- main.lua | 55 ++++++++++++++++++++++++++++++---------------- res/defaultbg.png | Bin 0 -> 1202 bytes room.lua | 51 ++++++++++++++++++++++++++++++++++++++++++ room/default.lua | 7 ++++++ rooms.lua | 5 +++++ window.lua | 18 ++++++++++++++- 9 files changed, 122 insertions(+), 26 deletions(-) create mode 100644 res/defaultbg.png create mode 100644 room.lua create mode 100644 room/default.lua create mode 100644 rooms.lua diff --git a/button.lua b/button.lua index 87baba0..be86e7d 100644 --- a/button.lua +++ b/button.lua @@ -17,11 +17,11 @@ function m.new(text, callback, x, y, width, height) ty = (height - th) / 2 } - btn.mousepressed = window.mousepressed(function(self, x, y, button) + btn.mousepressed = window.mousepressed(function (self, x, y, button) callback(x, y, button) end) - btn.draw = window.draw(function(self) + btn.draw = window.draw(function (self) love.graphics.printf(self.text, self.tx, self.ty, self.width) window.draw_border(self.width, self.height) end) diff --git a/conf.lua b/conf.lua index 02abbaa..95270a8 100644 --- a/conf.lua +++ b/conf.lua @@ -1,6 +1,6 @@ -WIDTH = 320 -HEIGHT = 240 -MULTIPLIER = 1.5 +WIDTH = 400 +HEIGHT = 300 +MULTIPLIER = 1.2 function love.conf(t) t.window.width = MULTIPLIER * WIDTH diff --git a/export.sh b/export.sh index ddea6f1..20b8b36 100755 --- a/export.sh +++ b/export.sh @@ -1,5 +1,5 @@ #!/bin/sh rm garden.love -zip garden.love *.lua +zip -r garden.love res/ room/ *.lua cp garden.love ~/storage/downloads/ diff --git a/main.lua b/main.lua index 80fac86..317507c 100644 --- a/main.lua +++ b/main.lua @@ -1,36 +1,46 @@ -- Imports local window = require("window") local button = require("button") +local rooms = require("rooms") -local inventory = { +local current_room = rooms['default'] + +screen = { + x = 0, y = 60, + width = 320, + height = 240, +} + +screen.mousepressed = window.mousepressed(function (self, x, y, button) + end) + +screen.draw = window.draw(function (self) + current_room:draw() + window.draw_border(self.width, self.height) +end) + +inventory = { x = 0, y = 0, - width = WIDTH*0.7, - height = HEIGHT*0.2, + width = screen.width, + height = 60, + items = {} } -inventory.draw = window.draw(function(self) +inventory.draw = window.draw(function (self) + for _, item in ipairs(self.items) do + -- item:setpos(x, y) + item:draw() + end window.draw_border(self.width, self.height) end) -local screen = { - x = 0, y = inventory.height, - width = inventory.width, - height = HEIGHT - inventory.height, -} - - -screen.draw = window.draw(function(self) - window.draw_border(self.width, self.height) -end) - -local log = { +log = { x = inventory.width , y = 0, - width = WIDTH*0.3, + width = 80, height = HEIGHT, } - -log.draw = window.draw(function(self) +log.draw = window.draw(function (self) window.draw_border(self.width, self.height) end) @@ -46,8 +56,15 @@ function love.update(dt) timer = timer + dt end +mw, mh = 0, 0 +if love.system.getOS() == 'android' then + mw = (love.window.getWidth() - WIDTH) / 2 + mh = (love.window.getHeight() - HEIGHT) / 2 +end + function love.draw() love.graphics.push() + love.graphics.translate(mw, mh) love.graphics.scale(MULTIPLIER) screen:draw() diff --git a/res/defaultbg.png b/res/defaultbg.png new file mode 100644 index 0000000000000000000000000000000000000000..2628d1e566ef1cc2ce40cbf91de30b5ed13f8a31 GIT binary patch literal 1202 zcmeAS@N?(olHy`uVBq!ia0y~yU~~YoKX3pEh7h+$+Zh;GDm`5sLn`LHy>q+hwuK1m z#lutn|DQgy{m4hvEi4Q86&T*s$#+-JY*-azTUOaVew}4IV_Nm&k$)9e& z+g>Q^SQ2IB7vnnNu34S;q^ArA4(F5$4gg#a1}U| z_dDzn_lF&G#q^GeU;J|-)=ck&_{EAo>oqY`^cQs+)IL8{Bgorw(p&s__b=9!(bu1M zuc+k|zW(l@c%b`?ZRPU&I;0LQIa>YE_2_~rXK#OW71`gyxqADPZVi)=+9W zz5QADq}q(%?`j0kn>T$ef6!e~);Ih6{Z{=)hKY+0%>AJxCuk;lr&nLjCof=!V*HVQ z{lu+@eSa#|DXf{Y!!Z7cYU0$RXMaBOTHxfouj9XHm+h14_pdGWL?*s3p3m9s^W^tE z_Qb}n8u7o*mCuYW?~k$%ua7@;+~||-tC#bmpH^S{>EXVw>70D+6YV!qC-m<<(wn&K zSN|rp_f4MrX8miPw0>QFNL=04+KrRe?>iqg?_QhTo+sI_Vtw`<`!}QVr)hah%?f9` qYY(3uuj2k0vH8#aHD`d})h}NA9T(CVuc~{43L{TfKbLh*2~7YaN*x#g literal 0 HcmV?d00001 diff --git a/room.lua b/room.lua new file mode 100644 index 0000000..1577722 --- /dev/null +++ b/room.lua @@ -0,0 +1,51 @@ +local window = require('window') + +-- prototype of room +-- - background +-- - objects +-- - edges +local room = { + background = love.graphics.newImage("res/defaultbg.png"), + edges = {}, + objects = {}, +} + +function edge_position(e) + local wd = screen.width - e.width + local hd = screen.height - e.height + + local t = { + ['left'] = { 0, hd/2 }, + ['right'] = { wd, hd/2 }, + ['up'] = { wd/2, 0 }, + ['down'] = { wd/2, hd }, + } + + local p = t[e.dir] + return p[1], p[2] +end + +local mt = { __index = room } + +function room:new() + local m = {} + setmetatable(m, mt) + return m +end + +room.mousepressed = window.propagate{'edges', 'objects'} + +function room:draw() + love.graphics.draw(self.background, 0, 0) + + for i, v in ipairs(self.objects) do + v:draw() + end + + for i, v in ipairs(self.edges) do + local x, y = edge_position(v) + love.graphics.draw(edge_arrow[v.dir], x, y) + end +end + +return room diff --git a/room/default.lua b/room/default.lua new file mode 100644 index 0000000..41f24d1 --- /dev/null +++ b/room/default.lua @@ -0,0 +1,7 @@ +local room = require('room') + +local r = room:new() + +r.background = love.graphics.newImage("res/defaultbg.png") + +return r diff --git a/rooms.lua b/rooms.lua new file mode 100644 index 0000000..d0b7ddf --- /dev/null +++ b/rooms.lua @@ -0,0 +1,5 @@ +local m = { + ['default'] = require('room/default'), +} + +return m diff --git a/window.lua b/window.lua index c1f6524..5160b41 100644 --- a/window.lua +++ b/window.lua @@ -1,4 +1,5 @@ --- primitive of drawing objects +-- function generator for window functions + local w = {} function w.draw(f) @@ -20,6 +21,21 @@ function w.mousepressed(f) end end +function w.propagate(tnames) + return function(self, x, y, button) + for _, tname in ipairs(tnames) do + for i, v in pairs(self[tname]) do + local x, y = x - v.x, y - v.y + + if 0 <= x and x <= v.width and 0 <= y and y <= v.height then + v:mousepressed(x, y, button) + return + end + end + end + end +end + function w.draw_border(width, height) love.graphics.push('all') love.graphics.setLineWidth(5)