-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
82 lines (69 loc) · 1.87 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
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
display.setStatusBar(display.HiddenStatusBar)
system.activate("multitouch")
-- include the Corona "storyboard" module
local storyboard = require("storyboard")
local GameScene = require("src.game.GameScene")
local WindowManager = require("src.menu.WindowManager")
-- Jump 30 lines in the debug console
for i = 1, 30 do
print("")
end
-- Pauses the game
--
-- Parameters:
-- pauseStatus: True if the game has to be paused, false to resume
local pause = function(pauseStatus)
Runtime:dispatchEvent{
name = "pause",
system = true,
switch = false,
status = pauseStatus
}
end
local quit = function()
Runtime:dispatchEvent{
name = "gameQuit",
}
end
-- System event listener
local systemEventListener = function(event)
print("System event: "..event.type)
if event.type == "applicationStart" then
-- Seed randomizer
math.randomseed(os.time())
-- Start the multiplayer game
storyboard.gotoScene("src.scenes.Welcome")
elseif event.type == "applicationExit" then
-- quit()
return true
elseif event.type == "applicationSuspend" then
pause(true)
return true
elseif event.type == "applicationResume" then
pause(false)
return true
end
return false
end
-- Key listener
local keyListener = function(event)
if event.keyName == "back" and event.phase == "up" then
if WindowManager.getTopWindow() then
WindowManager.removeTopWindow()
else
quit()
end
-- We caught the event so we return true
return true
end
return false
end
-- Add the key callback
Runtime:addEventListener("key", keyListener)
-- Setup a system event listener
Runtime:addEventListener("system", systemEventListener)