Skip to content

Commit f623910

Browse files
committed
Sound added
1 parent 1e69a51 commit f623910

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

templates/cocos2d iOS demo.xctemplate/Classes/gameScene.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ - (instancetype)init
7676

7777
[self serveFromSide:PaddleSideInvalid];
7878

79+
// set effects volume
80+
NSUserDefaults *setup = [NSUserDefaults standardUserDefaults];
81+
[OALSimpleAudio sharedInstance].effectsVolume = [setup floatForKey:kGameKeySoundVolume];
82+
7983
return self;
8084
}
8185

@@ -176,6 +180,8 @@ - (void)update:(CCTime)delta
176180
// check for paddle-ball collisions
177181
if (CGRectIntersectsRect(_paddleA.rect, _ball.rect))
178182
{
183+
// da beep
184+
[[OALSimpleAudio sharedInstance] playEffect:@"beep.wav"];
179185
// adjust ball position
180186
_ball.position = (CGPoint){_paddleA.position.x + ((_paddleA.contentSize.width + _ball.contentSize.width) * 0.5), _ball.position.y};
181187
// change direction
@@ -191,6 +197,8 @@ - (void)update:(CCTime)delta
191197
}
192198
else if (CGRectIntersectsRect(_paddleB.rect, _ball.rect))
193199
{
200+
// da beep
201+
[[OALSimpleAudio sharedInstance] playEffect:@"beep.wav"];
194202
// adjust ball position
195203
_ball.position = (CGPoint){_paddleB.position.x -((_paddleB.contentSize.width + _ball.contentSize.width) * 0.5), _ball.position.y};
196204
// change direction
@@ -204,13 +212,17 @@ - (void)update:(CCTime)delta
204212
// check for paddle top and bottom collision
205213
if (_ball.position.y < (_ball.contentSize.height * 0.5))
206214
{
215+
// da beep
216+
[[OALSimpleAudio sharedInstance] playEffect:@"beep.wav"];
207217
// adjust ball position
208218
_ball.position = (CGPoint){_ball.position.x, _ball.contentSize.height * 0.5};
209219
// change direction
210220
_ballVector.y = -_ballVector.y;
211221
}
212222
else if (_ball.position.y > (_gameSize.height - (_ball.contentSize.height * 0.5)))
213223
{
224+
// da beep
225+
[[OALSimpleAudio sharedInstance] playEffect:@"beep.wav"];
214226
// adjust ball position
215227
_ball.position = (CGPoint){_ball.position.x, _gameSize.height - (_ball.contentSize.height * 0.5)};
216228
// change direction
@@ -220,6 +232,8 @@ - (void)update:(CCTime)delta
220232
// check for score
221233
if (_ball.position.x < -(_ball.contentSize.width * 0.5))
222234
{
235+
// da beep
236+
[[OALSimpleAudio sharedInstance] playEffect:@"game.wav"];
223237
// paddle B scored
224238

225239

@@ -229,6 +243,8 @@ - (void)update:(CCTime)delta
229243
}
230244
else if (_ball.position.x > (_gameSize.width + (_ball.contentSize.width * 0.5)))
231245
{
246+
// da beep
247+
[[OALSimpleAudio sharedInstance] playEffect:@"game.wav"];
232248
// paddle A scored
233249

234250

Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)