-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchicagoSound.lua
executable file
·178 lines (154 loc) · 4.33 KB
/
chicagoSound.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
----------------------------------
-- THE BIG 3 VIDEO GAME ---
-- [email protected] ---
----------------------------------
-- Script handles all sound playback
-- for the Chicago endless runner level
-- We use different methods to play sounds on Android and iOS to address delay issues
local soundTime = nil
local kEnemyImpactChannel = 1
local kWeaponChannel = 2
local kVoiceChannel = 3
local kBonusSound = 4
local kDamageSound = 5
local bVoicePlaying = false
local mainScene = nil
local sound = {
--
}
function sound:load(sound, bForceLoadSound )
if ( system.getInfo("platformName") == "Android" and not bForceLoadSound ) then
return media.newEventSound( "sounds/" .. sound )
else
return audio.loadSound( "sounds/" .. sound )
end
end
function sound:killSounds()
if ( system.getInfo("platformName") == "Android" ) then
media.stopSound()
else
audio.stop()
end
end
function sound:play(sound, bAllowOverlap, bForceLoadSound, delay )
if( not bAllowOverlap ) then
if( system.getTimer() - soundTime < 100 ) then
return
else
soundTime = system.getTimer()
end
end
local delayFunction = nil
if( delay ) then
delayFunction = function()
local channel = audio.play( sound )
end
timer.performWithDelay( delay*1000, delayFunction, 1 )
else
if ( system.getInfo("platformName") == "Android" and not bForceLoadSound ) then
local channel = media.playEventSound( sound )
else
local channel = audio.play( sound )
end
end
end
function sound:loadEnemyImpactSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
return media.newEventSound( "sounds/" .. sound )
else
return audio.loadSound( "sounds/" .. sound )
end
end
function sound:playEnemyImpactSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
media.playEventSound( sound )
else
audio.play( sound, kEnemyImpactChannel )
end
end
function sound:loadWeaponSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
return media.newEventSound( "sounds/" .. sound )
else
return audio.loadSound( "sounds/" .. sound )
end
end
function sound:playWeaponSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
media.playEventSound( sound )
else
audio.play( sound, kWeaponChannel)
end
end
function sound:playEnemyImpactSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
media.playEventSound( sound )
else
audio.play( sound, kEnemyImpactChannel )
end
end
function sound:loadBonusSound( sound )
if ( system.getInfo("platformName") == "Android" ) then
return media.newEventSound( "sounds/" .. sound )
else
return audio.loadSound( "sounds/" .. sound )
end
end
function sound:playBonusSound( sound, bKillVoice )
if ( system.getInfo("platformName") == "Android" ) then
media.playEventSound( sound )
else
audio.play( sound, kBonusSound )
end
end
function sound:loadDamageSound( sound )
return audio.loadSound( "sounds/" .. sound )
end
function sound:playDamageSound( sound )
audio.play( sound, kDamageSound )
end
function sound:loadVoice( voiceFile )
return audio.loadSound( "sounds/" .. voiceFile )
end
function sound:playVoice( voice, delay, bForce, bDisableGameOver )
if( audio.isChannelPlaying( kVoiceChannel ) ) then
return false
end
if( mainScene.bSmoggy and not bForce ) then
return
end
if( not delay ) then
delay = 0
end
local finished = function( event )
if event.completed then
bVoicePlaying = false
end
end
local goVoice = function()
if( bVoicePlaying and not bForce ) then
return false
end
bVoicePlaying = true
if( not audio.isChannelPlaying( kVoiceChannel ) and ( not mainScene.bGameOver or bDisableGameOver ) ) then
audio.play( voice, { kVoiceChannel, onComplete=finished } )
end
end
timer.performWithDelay( delay*1000, goVoice, 1 )
return true
end
function sound:init(scene)
mainScene = scene
bVoicePlaying = false
soundTime = system.getTimer()
audio.reserveChannels(kWeaponChannel)
audio.reserveChannels(kEnemyImpactChannel)
audio.reserveChannels(kVoiceChannel)
audio.reserveChannels(kBonusSound)
audio.reserveChannels(kDamageSound)
end
function sound:destroy()
mainScene = nil
soundTime = nil
end
return sound