-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.lua
More file actions
206 lines (170 loc) · 6.81 KB
/
menu.lua
File metadata and controls
206 lines (170 loc) · 6.81 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
-----------------------------------------------------------------------------------------
--
-- menu.lua
--
-- Authors: Daniel Burris and Jairo Arreola
-----------------------------------------------------------------------------------------
local composer = require("composer")
-- Scene Creation / Manipulation
local scene = composer.newScene()
-- Widget Creation / Manipulation
-- Used for buttons, sliders, radio buttons
local widget = require("widget")
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- startButtonEvent()
-- input: none
-- output: none
--
-- This function just switches from the menu scene to the game scene
local function startButtonEvent(event)
if ("ended" == event.phase) then
composer.gotoScene("game")
end
end
-- settingsButtonEvent()
-- input: none
-- output: none
--
-- This function just switches from the menu scene to the settings scene
local function settingsButtonEvent(event)
if ("ended" == event.phase) then
composer.gotoScene("settings")
end
end
-- helpButtonEvent()
-- input: none
-- output: none
--
-- This function just switches from the menu scene to the help scene
local function helpButtonEvent(event)
if ("ended" == event.phase) then
composer.gotoScene("help")
end
end
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
-- input: none
-- output: none
--
-- This function creates all the objects that will be used in the scene and adds
-- them to the scene group.
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
-- Game Title / Image
local menuTitle = display.newImage("images/menuTitle.png")
menuTitle.width = 300
menuTitle.height = 100
-- Game Background
local menuBG = display.newImage("images/menuBG.jpg")
menuBG.width = display.contentWidth
menuBG.height = display.pixelWidth
menuBG:setFillColor(1,1,1,0.5) -- adding transparency
-- Text to display developers of the game
authors = display.newText("by Daniel Burris and Jairo Arreola", display.contentCenterX, display.contentCenterY+(display.contentCenterY/1.2))
-- Creating the start button, sends us from the menu scene to the game scene
local startButton = widget.newButton({
id = "startButton",
label = "Start",
width = 100,
height = 20,
fontSize = 10,
defaultFile = "images/button.png",
onEvent = startButtonEvent
} )
-- Creating the settings button, sends us from the menu scene to the settings scene
local settingsButton = widget.newButton({
id = "settingsButton",
label = "Settings",
width = 100,
height = 20,
fontSize = 10,
defaultFile = "images/button.png",
onEvent = settingsButtonEvent
} )
-- Creating the help button, sends us from the menu scene to the help scene
local helpButton = widget.newButton({
id = "helpButton",
label = "Help",
width = 100,
height = 20,
fontSize = 10,
defaultFile = "images/button.png",
onEvent = helpButtonEvent
} )
-- Positioning all objects on the screen
menuTitle.x = display.contentCenterX
menuTitle.y = display.contentCenterY-(display.contentCenterY*0.75)
menuBG.x = display.contentCenterX
menuBG.y = display.contentCenterY
authors.x = display.contentCenterX
authors.y = display.contentCenterY+(display.contentCenterY/1.2)
startButton.x = display.contentCenterX
startButton.y = display.contentCenterY+(display.contentCenterY/1.9)
helpButton.x = display.contentCenterX-70.0
helpButton.y = display.contentCenterY+(display.contentCenterY/1.5)
settingsButton.x = display.contentCenterX+70.0
settingsButton.y = display.contentCenterY+(display.contentCenterY/1.5)
-- Adding all objects to the scene group, this will bind these object to the scene
-- and they will be removed / replaced when switching to and from scenes
sceneGroup:insert( menuBG )
sceneGroup:insert( menuTitle )
sceneGroup:insert( authors )
sceneGroup:insert( startButton )
sceneGroup:insert( helpButton )
sceneGroup:insert( settingsButton )
end
-- show()
-- input: none
-- output: none
--
-- This function destroys the game scenes when its swapped to the menu scene
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is still off screen (but is about to come on screen)
composer.removeScene("game")
composer.removeScene("correctTapScene")
composer.removeScene("incorrectTapScene")
elseif ( phase == "did" ) then
-- Code here runs when the scene is entirely on screen
end
end
-- hide()
-- input: none
-- output: none
--
-- This function does nothing for us, but is still part of Corona SDK scene creation requirements
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == "did" ) then
-- Code here runs immediately after the scene goes entirely off screen
end
end
-- destroy()
-- input: none
-- output: none
--
-- This function does nothing for us, but is still part of Corona SDK scene creation requirements
function scene:destroy( event )
local sceneGroup = self.view
-- Code here runs prior to the removal of scene's view
end
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------
return scene