-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.lua
More file actions
67 lines (59 loc) · 1.66 KB
/
Copy pathcode.lua
File metadata and controls
67 lines (59 loc) · 1.66 KB
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
LoadScript("scene-over")
LoadScript("scene-welcome")
LoadScript("scene-game")
LoadScript("scene-intro")
LoadScript("scene-rule")
local scenes = nil
local activeScene = nil
local activeSceneId = 0
-- define scenes
WELCOME, INTRO, RULE, GAME, OVER = 1, 2, 3, 4, 5
-- define canvas size
CANVASX_MIN = 0
CANVASX_MAX = Display().X
CANVASY_MIN = 0
CANVASY_MAX = Display().Y
function Init()
scenes = {
WelcomeScene:Init(),
IntroScene:Init(),
RuleScene:Init(),
GameScene:Init(),
OverScene:Init(),
}
activeScene = scenes[ 1 ]
SwitchScene( WELCOME )
end
-- We use this function to prepare a new scene and run through all of the steps required to make sure the new scene is correctly reset and ready to go.
function SwitchScene(id)
activeSceneId = id
activeScene = scenes[activeSceneId]
activeScene:Reset()
if ( activeSceneId == OVER ) then
scenes[OVER]:SetTotalScore(scenes[GAME]:GetTotalScore())
StopSong()
PlaySong(1, false, 0)
end
end
--[[
The Update() method is part of the game's life cycle. The engine calls
Update() on every frame before the Draw() method. It accepts one argument,
timeDelta, which is the difference in milliseconds since the last frame.
]]--
function Update(timeDelta)
if(activeScene ~= nil) then
-- Call the active scene's `Update()` function.
activeScene:Update(timeDelta)
end
end
--[[
The Draw() method is part of the game's life cycle. It is called after
Update() and is where all of our draw calls should go. We'll be using this
to render sprites to the display.
]]--
function Draw()
if(activeScene ~= nil) then
-- Call the active scene's `Draw()` function.
activeScene:Draw()
end
end