-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamewrapper.lua
65 lines (50 loc) · 1.23 KB
/
gamewrapper.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local actum = require('lib.actum')
local lovebind = require('lib.love_bind')
local sceneman = require('lib.sceneman')
require('scenes.menu')
require('scenes.game')
require('scenes.pause')
local gamewrapper = {}
function gamewrapper:load()
sceneman:loadall()
love.graphics.setBackgroundColor(1, 1, 1)
self.fpsFont = love.graphics.newFont(12)
lovebind.keypressed:bind(function(key)
if key == 'r' then
self:restart()
end
end)
end
function gamewrapper:start()
self.fps = 0
sceneman:start('menu')
end
function gamewrapper:restart()
-- Use it for debug purpose
sceneman:stopall()
sceneman:quitall()
self:start()
print('restart')
end
function gamewrapper:quit()
-- Unload stuff here
sceneman:quitall()
love.event.quit(0)
end
function gamewrapper:update(dt)
sceneman:update(dt)
-- Update fps
local rdt = love.timer.getDelta()
self.fps = math.floor(1 / rdt)
end
function gamewrapper:draw(dt)
sceneman:draw(dt)
self:drawFPS()
end
function gamewrapper:drawFPS()
love.graphics.setColor(0, 0, 0)
love.graphics.setFont(self.fpsFont)
love.graphics.print(self.fps, 15, 15)
love.graphics.setColor(1, 1, 1)
end
return gamewrapper