notsanequarium/main.lua

123 lines
3.1 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-25 15:17:32 +00:00
cursors = {}
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-25 15:17:32 +00:00
cursors.default = love.mouse.newCursor('assets/sprites/cursor/pointer.png', sprites['cursor/pointer']:getWidth()/2, sprites['cursor/pointer']:getHeight()/2)
cursors.hover = love.mouse.newCursor('assets/sprites/cursor/hand.png', sprites['cursor/hand']:getWidth()/2, sprites['cursor/hand']:getHeight()/2)
cursors.drag = love.mouse.newCursor('assets/sprites/cursor/dragging.png', sprites['cursor/dragging']:getWidth()/2, sprites['cursor/dragging']:getHeight()/2)
love.mouse.setCursor(cursors.default)
2021-01-22 22:33:08 +00:00
end
2021-01-25 16:42:27 +00:00
local cursor
function setCursor(mouse)
cursor = mouse
end
2021-01-23 23:30:01 +00:00
frame = 0
2021-01-22 22:33:08 +00:00
function love.update(dt)
2021-01-25 16:42:27 +00:00
cursor = nil
2021-01-22 22:33:08 +00:00
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')
2021-01-25 16:42:27 +00:00
if cursor then
love.mouse.setCursor(cursor)
else
love.mouse.setCursor(cursors.default)
end
2021-01-22 22:33:08 +00:00
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)
2021-01-25 18:34:38 +00:00
if paused then
love.graphics.setBlendMode('subtract')
love.graphics.setColor(1, 1, 1, 0.1)
love.graphics.rectangle('fill', 0, 0, sw, sh)
love.graphics.setBlendMode('alpha')
love.graphics.setColor(0, 0, 0, 0.6)
love.graphics.rectangle('fill', 0, 0, sw, sh)
love.graphics.setColor(1, 1, 1)
love.graphics.print('paused, space to unpause', 20, 20)
end
2021-01-22 22:33:08 +00:00
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
2021-01-25 18:34:38 +00:00
elseif key == 'space' then
paused = false
2021-01-22 22:33:08 +00:00
end
end