notsanequarium/main.lua

91 lines
2 KiB
Lua
Raw Normal View History

2021-01-22 22:33:08 +00:00
require 'const'
require 'util'
constr = require 'constructors'
2021-01-23 16:37:37 +00:00
require 'lib.audio'
2021-01-22 22:33:08 +00:00
assets = require 'lib.assets'
ease = require 'lib.ease'
bench = require 'lib.benchmark'
2021-01-23 16:37:37 +00:00
tick = require 'lib.tick'
2021-01-22 22:33:08 +00:00
2021-01-23 23:30:01 +00:00
scenes = {
gameplay = require('scenes/gameplay/main')
}
local defaultscene = scenes.gameplay
scene = defaultscene
2021-01-22 22:33:08 +00:00
sprites = {}
sound_path = {}
music_path = {}
2021-01-23 13:46:02 +00:00
fonts = {}
2021-01-22 22:33:08 +00:00
debug = false
2021-01-23 23:30:01 +00:00
function newAnimation(image, width, height)
2021-01-22 22:33:08 +00:00
local animation = {}
animation.spriteSheet = image;
animation.quads = {};
animation.width = width
animation.height = height
for y = 0, image:getHeight() - height, height do
for x = 0, image:getWidth() - width, width do
table.insert(animation.quads, love.graphics.newQuad(x, y, width, height, image:getDimensions()))
end
end
return animation
end
function love.load()
assets.clear()
assets.load('assets')
2021-01-23 13:46:02 +00:00
fonts.pix = love.graphics.newFont('assets/fonts/pix.ttf', 6)
fonts.continuum = love.graphics.newFont('assets/fonts/cont.ttf', 14)
fonts.default = love.graphics.newFont(12)
2021-01-23 23:30:01 +00:00
if scene.load then scene.load() end
2021-01-22 22:33:08 +00:00
end
2021-01-23 23:30:01 +00:00
frame = 0
2021-01-22 22:33:08 +00:00
function love.update(dt)
frame = frame + 1
bench.update()
2021-01-23 16:37:37 +00:00
tick.update(dt)
2021-01-22 22:33:08 +00:00
bench.startBenchmark('update')
2021-01-23 23:30:01 +00:00
if scene.update then scene.update(dt) end
2021-01-22 22:33:08 +00:00
bench.stopBenchmark('update')
end
function love.draw()
2021-01-23 13:46:02 +00:00
love.graphics.setFont(fonts.default)
2021-01-22 22:33:08 +00:00
love.graphics.setColor(1, 1, 1)
local sw, sh = love.graphics.getDimensions()
2021-01-23 23:30:01 +00:00
bench.startBenchmark('render')
2021-01-23 19:42:56 +00:00
2021-01-23 23:30:01 +00:00
if scene.draw then scene.draw() end
2021-01-23 19:42:56 +00:00
2021-01-22 22:33:08 +00:00
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('FPS: ' .. 1 / love.timer.getDelta(), 0, sh - 16)
if debug then bench.renderBenchmark() end
bench.stopBenchmark('render')
end
function love.mousepressed(x, y, b)
2021-01-23 23:30:01 +00:00
if scene.mousepressed then scene.mousepressed(x, y, b) end
2021-01-23 13:46:02 +00:00
end
2021-01-23 16:37:37 +00:00
function love.mousereleased(x, y, b)
2021-01-23 23:30:01 +00:00
if scene.mousereleased then scene.mousereleased(x, y, b) end
2021-01-23 16:37:37 +00:00
end
2021-01-22 22:33:08 +00:00
function love.keypressed(key)
if key == 'f3' then
debug = not debug
end
end