-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain menu.lua
194 lines (145 loc) · 6.6 KB
/
main menu.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
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
local composer = require( "composer" )
local scene = composer.newScene()
local score = require( "Scripts.score" )
local backgroundSheetInfo = require("Scripts.beachBackground")
display.setStatusBar(display.HiddenStatusBar) --Hide status bar in ios
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------
local function Story()
local options = {
effect = "crossFade",
time = 1000,
params = { level="Level 1", score=0 }
}
composer.gotoScene( "Scripts.story", options )
end
local function Survival()
local options = {
effect = "crossFade",
time = 1000,
params = { round= 1, score=0 }
}
composer.gotoScene( "Scripts.survival", options )
end
-- local forward references should go here
-- -------------------------------------------------------------------------------
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
---background animation--
local myImageSheet = graphics.newImageSheet( "Art/Background/spriteSheet.png", backgroundSheetInfo:getSheet() )
local sequenceData = {
{
name="tide", -- name of the animation
sheet=myImageSheet, -- the image sheet
start=backgroundSheetInfo:getFrameIndex("0"), -- first frame
count=14, -- number of frames
time=2000, -- speed
loopCount=0 -- repeat
}
}
-- create sprite, set animation, play
background = display.newSprite( myImageSheet, sequenceData )
background.x = display.contentCenterX
background.y = display.contentCenterY
background:setSequence("tide")
-- 6. Resize to match screen size based on a ratio with the actual background pixel dimensions
background:scale( display.actualContentWidth/640, display.actualContentHeight/480 )
background:play()
sceneGroup:insert(background)
--main menu buttons---
--Menu Button Images
local menuGroup = display.newGroup()
local story = display.newImage(menuGroup, "Art/Main Menu/Main Buttons/Story Text 1.png", display.contentCenterX, display.contentCenterY - 200)
local storySoon = display.newImage(menuGroup, "Art/Main Menu/Other Buttons/comingsoon.png", display.contentCenterX, display.contentCenterY - 200)
local survival = display.newImage(menuGroup, "Art/Main Menu/Main Buttons/Survival Text 1.png", display.contentCenterX, display.contentCenterY)
local curHighscore = display.newImage(menuGroup, "Art/Main Menu/Main Buttons/highscore.png", display.contentCenterX - 20, display.contentCenterY + 40)
local scoreText = score.init({
fontSize = 32,
font = "octin.ttf",
x = display.contentCenterX + 180,
y = display.contentCenterY + 40,
maxDigits = 5,
leadingZeros = true,
filename = "scorefile.txt",
})
scoreText:setTextColor(0, 0, 0)
if(score.load() ~= nil) then
score.set(score.load())
end
menuGroup:insert(scoreText)
local controls = display.newImage(menuGroup, "Art/Main Menu/Main Buttons/Controls Text 1.png", display.contentCenterX, display.contentCenterY + 200)
local controlsSoon = display.newImage(menuGroup,"Art/Main Menu/Other Buttons/comingsoon.png", display.contentCenterX, display.contentCenterY + 200)
--Menu Listeners
--story:addEventListener("tap", Story)
survival:addEventListener("tap", Survival)
--controls:addEventListener("tap", Story)
sceneGroup:insert(menuGroup)
--[[
local function onOrientationChange(e)
if(e.type ~= "faceUp" or e.type ~= "faceDown") then
if(e.type == "landscapeLeft" or e.type == "landscapeRight") then
for i=1, sceneGroup.numChildren do
if(sceneGroup[i].numChildren ~= nil) then
for x=1, sceneGroup[i].numChildren do
local newAngle = sceneGroup[i][x].rotation - e.delta*2
local newY = sceneGroup[i][x].y - display.contentCenterY
transition.to (sceneGroup[i][x], {time=150, rotation = newAngle, x = sceneGroup[i][x].x - (sceneGroup[i][x].x - display.contentCenterX)*2 ,y = sceneGroup[i][x].y - (sceneGroup[i][x].y - display.contentCenterY) * 2})
--sceneGroup[i][x].rotation = sceneGroup[i][x].rotation - (e.delta*2)
end
else
local newAngle = sceneGroup[i].rotation - e.delta*2
transition.to (sceneGroup[i], {time=150, rotation = newAngle, x = sceneGroup[i].x - (sceneGroup[i].x - display.contentCenterX)*2 ,y = sceneGroup[i].y - (sceneGroup[i].y - display.contentCenterY) * 2})
end
end
end
end
end
Runtime:addEventListener("orientation", onOrientationChange)]]--
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen).
--Audio
local mainBackgroundMusic = audio.loadStream( "Audio/main menu.mp3" )
local mainBackgroundMusicChannel = audio.play(mainBackgroundMusic, {channel=1, loops=-1, fadein=725} )
elseif ( phase == "did" ) then
-- Called when the scene is now on screen.
-- Insert code here to make the scene come alive.
-- Example: start timers, begin animation, play audio, etc.
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen).
-- Insert code here to "pause" the scene.
-- Example: stop timers, stop animation, stop audio, etc.
audio.stop()
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen.
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's view ("sceneGroup").
-- Insert code here to clean up the scene.
-- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "destroy", scene )
scene:addEventListener( "hide", scene )
-- -------------------------------------------------------------------------------
return scene