local game = require 'game' local physics = require 'physics' local Bolvis = require 'Bolvis' local stuff = require 'stuff' local camera function love.load() love.mouse.setRelativeMode(true) local bolvis = Bolvis({960, 540}) camera = bolvis.camera stuff.Teapot({400, 540}, 0) stuff.Apioform({600, 540}, 0) stuff.TestPlatform({960, 300}) stuff.TestPlatform({960, 700}) stuff.TestPlatform({430, 700}) stuff.TestPlatform({1490, 700}) end local function screen_transform() local ww, wh = love.graphics.getDimensions() local sw, sh = 1920, 1080 local scalex, scaley = ww / sw, wh / sh local scale if scalex * sh < wh then scale = scalex else scale = scaley end local dimx, dimy = sw * scale, sh * scale local x, y = ww / 2 - dimx / 2, wh / 2 - dimy / 2 return love.math.newTransform(x, y, 0, scale, scale) end local to_draw local events = {} local handlers = {} local function event(name) love[name] = function(...) table.insert(events, {type = name, ...}) end end function love.update(dt) to_draw = {} physics.world:update(dt, 20, 20) for _, e in ipairs(events) do if handlers[e.type] then handlers[e.type](unpack(e)) end end for o in pairs(game.all_objects) do for _, e in ipairs(events) do if o[e.type] then o[e.type](o, unpack(e)) end end o:update(dt) if o:visible() then table.insert(to_draw, o) end end events = {} end function love.draw() love.graphics.applyTransform(screen_transform()) camera:use() table.sort(to_draw, function(a, b) return a.z < b.z end) for _, o in ipairs(to_draw) do o:draw() end end event "mousemoved" event "mousepressed" event "mousereleased" event "keypressed" event "keyreleased" function handlers.keypressed(key) if key == 'tab' and (love.keyboard.isDown 'ralt' or love.keyboard.isDown 'lalt') then love.mouse.setRelativeMode(false) end end function handlers.mousepressed() love.mouse.setRelativeMode(true) end