require "globals" local Drawable = require 'Drawable' local Input = require 'Input' global "level" love.load = require "load" 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 function call(ct, method, ...) for o in level:iterate(ct) do o:call(method, ...) end end function love.draw() love.graphics.applyTransform(screen_transform()) level.camera:transform() local to_draw = {} for o in level:iterate(Drawable) do table.insert(to_draw, o) end table.sort(to_draw, function(a, b) return a:get(Drawable).i.z < b:get(Drawable).i.z end) for _, o in ipairs(to_draw) do love.graphics.push() local cmps = {} for c in o:all_components() do table.insert(cmps, c) end table.sort(cmps, function(a, b) return (a.i.z or 0) < (b.i.z or 0) end) for _, c in ipairs(cmps) do if c.draw then c:draw() end end love.graphics.pop() end end function love.update(dt) -- physics.world:update(dt, 20, 20) call(nil, 'update', dt) end function love.mousemoved(...) call(Input, 'mousemoved', ...) end function love.mousepressed(...) love.mouse.setRelativeMode(true) call(Input, 'mousepressed', ...) end function love.mousereleased(...) call(Input, 'mousereleased', ...) end function love.keypressed(key, ...) if key == 'tab' and (love.keyboard.isDown 'ralt' or love.keyboard.isDown 'lalt') then love.mouse.setRelativeMode(false) end call(Input, 'keypressed', key, ...) end function love.keyreleased(...) call(Input, 'keyreleased', ...) end