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 0000000..2628d1e Binary files /dev/null and b/res/defaultbg.png differ 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)