diff options
Diffstat (limited to 'main.lua')
| -rw-r--r-- | main.lua | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..6d3fadc --- /dev/null +++ b/main.lua @@ -0,0 +1,76 @@ +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 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 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" |
