-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.lua
176 lines (133 loc) · 4.29 KB
/
start.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
-- requires
display.setStatusBar( display.HiddenStatusBar )
local storyboard = require ("storyboard")
local scene = storyboard.newScene()
system.activate( "multitouch" )
local physics = require "physics"
physics.start()
-------------------------------------------------------------------------------------
local backgroundsnd = audio.loadStream ( "m1.mp3")
-- Variables to Determine Center of Screen
_W = display.contentWidth / 2;
_H = display.contentHeight / 2;
-- play background music
function backgroundMusic()
back=audio.play (backgroundsnd, { loops = -1})
audio.setVolume(0.8, {backgroundsnd} )
end
local function muteMusic(event)
if ( "began" == event.phase ) then
if(mute1.alpha<=0.5) then
audio.rewind( backgroundsnd )
audio.play(backgroundsnd, { loops = -1})
print("inside 1")
mute1.alpha=1
else
audio.stop()
mute1.alpha=0.5
print("inside 0.5"..mute1.alpha)
end
end
end
function startGame(event)
if event.phase == "ended" then
storyboard.gotoScene("game", {effect = "fade", time = 800})
end
end
function titleTransitionDown()
downTransition = transition.to(titleGroup,{time=400, y=titleGroup.y+20,onComplete=titleTransitionUp})
end
function titleTransitionUp()
upTransition = transition.to(titleGroup,{time=400, y=titleGroup.y-20, onComplete=titleTransitionDown})
end
function titleAnimation()
titleTransitionDown()
end
function goto1(event)
if event.phase == "ended" then
storyboard.gotoScene("menupage", {effect = "fade", time = 800})
end
end
function startGame2(event)
if event.phase == "ended" then
storyboard.gotoScene("HighScore", {effect = "fade", time = 800})
end
end
-------------------------------------------------------------------------------------
function scene:createScene(event)
local screenGroup = self.view
background = display.newImage ("images/background.png"); -- Place background image
background.x = _W;
background.y = 150;
background.speed = 1;
screenGroup:insert(background);
background1 = display.newImage ("images/background.png");
background1.x = _W+480;
background1.y = 150;
background1.speed = 1;
screenGroup:insert(background1);
mute1 = display.newImageRect("mute1.png",45,45);
mute1.x = display.contentWidth;
mute1.y =_H-120;
screenGroup:insert(mute1);
title =display.newImage("t1.png")
title.x=_W
title.y=_H-100
screenGroup:insert(title)
-- Place ship image
ship = display.newImage ("images/spaceship.png");
ship.x = _W-250;
ship.y = _H+50;
physics.setGravity(0,0);
ship.myName="ship"
physics.addBody(ship, "static");
screenGroup:insert(ship);
start = display.newImageRect("s1.png",200,65)
start.x = _W+10;
start.y = _H+70
screenGroup:insert(start)
go=display.newImage("bac.png")
go.x=10
go.y=display.contentHeight-10
screenGroup:insert(go)
titleGroup = display.newGroup()
titleGroup.x = _W
titleGroup.y = _H- 250
titleGroup:insert(ship)
screenGroup:insert(titleGroup)
titleAnimation()
t4 =display.newImageRect("s2.png",200,65)
t4.x=_W
t4.y=_H+120
screenGroup:insert(t4)
--transition.to( t4, { time=1500, x=_W, onComplete=listener } )
end
function scene:enterScene(event)
local previous = storyboard.getPrevious()
if previous ~= "main" and previous then
storyboard.removeScene(previous)
end
local screenGroup = self.view
backgroundMusic()
mute1:addEventListener( "touch", muteMusic)
start:addEventListener("touch", startGame)
go:addEventListener( "touch", goto1 )
t4:addEventListener("touch", startGame2)
end
function scene:exitScene(event)
local screenGroup = self.view
mute1:removeEventListener( "touch", muteMusic)
start:removeEventListener("touch", startGame)
transition.cancel(downTransition)
transition.cancel(upTransition)
go:removeEventListener( "touch", goto1 )
t4:removeEventListener("touch", startGame2)
end
function scene:destroyScene(event)
local screenGroup = self.view
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene