-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
86 lines (77 loc) · 2 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---@param module_name string
---@param args table
function load_module(module_name, args)
assert(module_name)
log.debug('load module', module_name)
if game_exit then
game_exit()
end
local m = require('src/' .. module_name)
---@type fun(dt:number)
game_update = m.update
game_draw = m.draw
game_exit = nil
if m.exit then
game_exit = m.exit
end
game_keypressed = nil
if m.keypressed then
game_keypressed = m.keypressed
end
love.keyreleased = nil
if m.keyreleased then
love.keyreleased = m.keyreleased
end
m.init(args)
love.timer.step()
end
---@param k string
function love.keypressed(k)
if k == 'f12' then
is_debug_gui = not is_debug_gui
return
end
if k == 'escape' then
love.event.quit()
end
if game_keypressed then
game_keypressed(k)
end
end
function love.run()
require('src/debug')
require('src/common')
const = require('src/const')
love.graphics.setFont(love.graphics.newFont('resources/fonts/Robotomedium.ttf', 14))
love.graphics.setLineStyle('rough')
love.graphics.setColor(1.0, 1.0, 1.0, 1.0)
--messages_bus = {}
load_module('00loading')
local dt = 0
-- Main loop
return function()
love.event.pump()
for name, a, b, c, d, e, f in love.event.poll() do
if name == 'quit' then
log.debug('event quit')
if game_exit then
game_exit()
end
return 0
end
love.handlers[name](a, b, c, d, e, f)
end
dt = love.timer.step()
game_update(dt)
if love.graphics.isActive() then
love.graphics.origin()
love.graphics.clear(love.graphics.getBackgroundColor())
game_draw()
if is_debug_gui then
debug_print_fps()
end
love.graphics.present()
end
love.timer.sleep(0.001)
end
end