-- Imports local window = require("window") local button = require("button") local rooms = require("rooms") local current_room = rooms['default'] 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, items = {} } inventory.mousepressed = window.propagate{'items'} inventory.draw = window.draw(function (self) local x = 0 for _, item in pairs(self.items) do item:setpos(x, 0) item:draw() x = item.width end window.draw_border(self.width, self.height) end) function inventory:pickup(item) table.insert(self.items, item) end log = { x = inventory.width , y = 0, width = WIDTH - screen.width, height = HEIGHT, lines = {}, } log.limit = log.width - 10 local font = love.graphics.getFont() local font_height = font:getHeight('L') local line_limit = log.height / font_height log.draw = window.draw(function (self) local i = 0 for _, l in ipairs(self.lines) do local rw, wl = font:getWrap(l, self.limit) local th = font:getHeight(l) love.graphics.printf(l, 5, 5 + i*th, self.limit) i = i + #wl end window.draw_border(self.width, self.height) end) function log:log(str) table.insert(self.lines, str) local i = 0 for _, l in ipairs(self.lines) do local rw, wl = font:getWrap(l, self.limit) local th = font:getHeight(l) i = i + #wl end while i > line_limit do local l = self.lines[1] local rw, wl = font:getWrap(l, self.limit) local th = font:getHeight(l) i = i - #wl table.remove(self.lines, 1) end 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