-- Imports local util = require("util") local window = require("window") local button = require("button") local rooms = require("rooms") current_room = rooms['default'] function set_room(r) current_room = rooms[r] end screen = { x = 0, y = 60, width = 320, height = 240, } screen.mousepressed = window.mousepressed(function (self, x, y, button) log:log(string.format("%d, %d", x, y)) current_room:mousepressed(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 = screen.width, height = 60, selected_item = nil, items = {}, } inventory.mousepressed = window.propagate{'items'} inventory.draw = window.draw(function (self) for i, item in pairs(self.items) do if self.selected_item and self.selected_item.idx == i then love.graphics.circle('line', 60*i - 30, 30, 25) end item:draw() end window.draw_border(self.width, self.height) end) function inventory:pickup(item) util.add_entity(self.items, item) local x = (#self.items - 1) * 60 + (60 - item.width) / 2 local y = (60 - item.height) / 2 item:setpos(x, y) end log = { x = inventory.width , y = 0, width = WIDTH - screen.width, height = HEIGHT, lines = {}, } local font = love.graphics.getFont() local font_height = font:getHeight('L') local line_limit = log.height / font_height log.limit = log.width - 10 log.draw = window.draw(function (self) local h = 0 for i, l in ipairs(self.lines) do local th = font:getHeight(l) love.graphics.printf(l, 5, 5 + h, self.limit) h = h + th end window.draw_border(self.width, self.height) end) function log:log(str) local rw, wl = font:getWrap(str, self.limit) for _, l in ipairs(wl) do table.insert(self.lines, l) end while #self.lines > line_limit do table.remove(self.lines, 1) end end function log:format(...) log:log(string.format(...)) end function log:info(o) if o._t == 'item' then self:log(string.format("It's %s. %s", o.name, o.description)) else self:log("There's no info for that.") end end function love.load() log:log("Welcome to the garden.") end function love.update(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.mousepressed(x, y, button) local x, y = (x - mw) / MULTIPLIER, (y - mh) / MULTIPLIER screen:mousepressed(x, y, button) inventory:mousepressed(x, y, button) end function love.draw() love.graphics.push() love.graphics.translate(mw, mh) love.graphics.scale(MULTIPLIER) screen:draw() inventory:draw() log:draw() love.graphics.pop() end