Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5 Sounds & Sound Effects

Similar presentations


Presentation on theme: "Lecture 5 Sounds & Sound Effects"— Presentation transcript:

1 Lecture 5 Sounds & Sound Effects
King Pong

2 Splash Screen While splash screen is being displayed King Pong plays "Lets get Ready to Rumble...with You ready for this?..."

3 Splash Screen Audio Play Option
The "rumble.wav" file is played automatically and only upon program launch. It is not replayed at the beginning of a new game... Since audio files must be loaded before they are played and we only want to play "rumble.wav" once we can place the call to Play the file at the end of the LoadContent( ) method. protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); crowd[0] = Content.Load<SoundEffect>("crowd1"); crowd[1] = Content.Load<SoundEffect>("crowd2"); crowd[2] = Content.Load<SoundEffect>("crowd3"); crowd[3] = Content.Load<SoundEffect>("crowd4"); crowd[4] = Content.Load<SoundEffect>("crowd5"); cheer[0] = Content.Load<SoundEffect>("cheer1"); cheer[1] = Content.Load<SoundEffect>("cheer2"); cheer[2] = Content.Load<SoundEffect>("cheer3"); rumble = Content.Load<SoundEffect>("rumble"); rockyou = Content.Load<SoundEffect>("rockyou"); buzzer = Content.Load<SoundEffect>("buzzer"); gogame = Content.Load<SoundEffect>("goball"); ping = Content.Load<SoundEffect>("ping"); pong = Content.Load<SoundEffect>("pong"); laugh = Content.Load<SoundEffect>("laugh"); : rumble.Play(); gamestart(); }

4 Crowd Sounds based on VollyCount & Score
public void crowdsounds() { if (oldvolleycount != volleycount) if (volleycount == 0) crowd[0].Play(); if ((p1.Score == 10 || p2.Score == 10) && volleycount == 1) rockyou.Play(); if (volleycount == 2) crowd[1].Play(); if (volleycount == 4) crowd[2].Play(); if (volleycount == 6) crowd[3].Play(); if (volleycount == 10) crowd[4].Play(); if (volleycount > 11 && rnd.Next() > 0.98) crowd[rnd.Next(0, 4)].Play(); if (oldvolleycount > 8 && volleycount == 0) cheer[0].Play(); if (oldvolleycount > 12 && volleycount == 0) cheer[1].Play(); if (oldvolleycount > 16 && volleycount == 0) cheer[2].Play(); oldvolleycount = volleycount; } As the vollycount goes up the crowd sounds increase. When the score is 10 on either side the crowd begins to chant "We will, we will...rock you!"...

5 Sounds Associated with the Ball
public void ballstuff() { if (b.Pos.Y <= 0 || b.Pos.Y >= bkg.Height - ball.Height) b.moveBall(false, true, 0); } else if ((Math.Abs(b.Pos.X - p1.Pos.X + ball.Width / 2) < ball.Height) && (b.Pos.Y + ball.Height > p1.Pos.Y) && (b.Pos.Y < p1.Pos.Y + p1.Leng)) b.moveBall(true, false, p1.spin()); ping.Play(); volleycount += 1; else if ((Math.Abs(b.Pos.X - p2.Pos.X) < ball.Height) && (b.Pos.Y + ball.Height > p2.Pos.Y) && (b.Pos.Y < p2.Pos.Y + p2.Leng)) b.moveBall(true, false, p2.spin()); pong.Play(); else b.moveBall(false, false, 0); if (b.Pos.X < 0) if (b.vY == 0 && volleycount == 0) laugh.Play(); b.Pos.X = bkg.Width / 2; b.vX = -ballspeed; curballspeed = -ballspeed; b.vY = 0; b.Pos = StartPos; buzzer.Play(); vollystart(); p2.Score += 1; if (b.Pos.X > bkg.Width) b.vX = ballspeed; curballspeed = ballspeed; p1.Score += 1; Play "ping" or "pong" sound when ball hits a paddle Play "laugh" if ball passes paddle when volley count ==0 Play "buzzer" when ball passes a paddle

6 Sound Stuff happening in the Update( ) Method
if (keybrd.IsKeyDown(Keys.Space)) { if (gameover && start) gamestart(); else start = true; rumble.Dispose(); } if (!start) if (sb.Pos.X < 0 || sb.Pos.X > bkg.Width) sb.moveBall(true, false, 0); else if (sb.Pos.Y < 0 || sb.Pos.Y > bkg.Height) sb.moveBall(false, true, 0); sb.moveBall(false, false, 0); particleEngine.EmitterLocation = new Vector2(sb.Pos.X, sb.Pos.Y); particleEngine.Update(); if (countdown <= 0) ballstuff(); crowdsounds(); countdown -= 1; if (countdown == 0) gogame.Play(); When game is loaded both gameover and start are false so pressing the spacebar (Keys.Space) disposes of the "Let's get ready to Rumble..." audio and calls gamestart( ). At the end of a game, gameover is set to true so the next time the spacebar is pressed gamestart( ) is called. If game has started then the value of countdown is checked...if countdown<=0 then ballstuff( ) and crowdsounds( ) are called...otherwise countdown is decremented. The purpose of countdown is to give players a little time to get ready for the next volly. countdown starts at 50 and when it reaches 0 a beep called "gogame" is played and the volly starts. Note that while the volly is active countdown remains <= 0.


Download ppt "Lecture 5 Sounds & Sound Effects"

Similar presentations


Ads by Google