tiny-ecs/main.lua

102 lines
2.4 KiB
Lua
Raw Normal View History

2015-04-27 06:12:11 +00:00
class = require "lib.30log"
tiny = require "lib.tiny"
2015-07-08 00:58:25 +00:00
gamestate = require "lib.gamestate" -- slightly modified to play nice;y with 30log
2015-04-27 06:12:11 +00:00
local Intro = require "src.states.Intro"
local Level = require "src.states.Level"
local assets = nil
local beholder = require "lib.beholder"
local paused = false
local pauseNextFrame = false
local pauseCanvas = nil
function love.keypressed(k)
beholder.trigger("keypress", k)
end
function love.keyreleased(k)
beholder.trigger("keyrelease", k)
end
function love.load()
love.mouse.setVisible(false)
assets = require "src.assets" -- load assets
gamestate.registerEvents()
gamestate.switch(Intro())
assets.snd_music:play()
assets.snd_music:setLooping(true)
love.resize(love.graphics.getWidth(), love.graphics.getHeight())
end
function love.draw()
if paused then
love.graphics.setColor(90, 90, 90, 255)
2015-05-20 02:01:38 +00:00
love.graphics.draw(pauseCanvas, 0, 0)
2015-04-27 06:12:11 +00:00
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setFont(assets.fnt_hud)
love.graphics.printf("Paused - P to Resume", love.graphics.getWidth() * 0.5 - 125, love.graphics.getHeight() * 0.4, 250, "center")
else
local dt = love.timer.getDelta()
if world then
world:update(dt)
end
end
end
function love.update(dt)
local s = gamestate.current()
2016-03-12 01:39:15 +00:00
if s and s.restartOnSpace and love.keyboard.isDown("space") then
2015-04-27 06:12:11 +00:00
local TransitionScreen = require "src.entities.TransitionScreen"
world:add(TransitionScreen(true, Intro()))
end
end
function love.resize(w, h)
pauseCanvas = love.graphics.newCanvas(w, h)
if camera then
camera:setWindow(0, 0, w, h)
end
if paused then
love.graphics.setCanvas(pauseCanvas)
world:update(0)
love.graphics.setCanvas()
end
end
-- quitting
beholder.observe("keypress", "escape", love.event.quit)
-- pausing
beholder.observe("keypress", "p", function()
paused = not paused
if paused then
love.graphics.setCanvas(pauseCanvas)
world:update(0)
love.graphics.setCanvas()
end
end)
-- toggle music
beholder.observe("keypress", "m", function()
local vol = assets.snd_music:getVolume()
if vol == 0 then
assets.snd_music:setVolume(1)
else
assets.snd_music:setVolume(0)
end
end)
-- toggle fullscreen
beholder.observe("keypress", "\\", function()
local fs = love.window.getFullscreen()
if fs then
love.window.setMode(900, 600, {resizable = true})
2015-05-20 02:01:38 +00:00
else
2015-04-27 06:12:11 +00:00
local w, h = love.window.getDesktopDimensions()
love.window.setMode(w, h, {fullscreen = true, })
end
love.resize(love.graphics.getWidth(), love.graphics.getHeight())
2015-07-08 00:55:25 +00:00
end)