- [Instructor] Hi, this video is Playing Sounds.
Previously we looked at populating the sound emitters.
In this video we're going to add the code
for various sounds, that is, jump sound,
success sound, fall in fire, and fall in water sounds.
To get started, open up the LoadLevel.cpp file,
and then we'll add the call
to the new populate emitters function.
We have to add the call between
and repopulate the vertex array as well,
and how long is the new time limit block.
First, we'll add a comment,
prepare the sound emitters,
then populateEmitters m_FireEmitters,
m_ArrayLevel.
This is the call we've added
to populate emitters function.
The first sound to add is the jump sound.
You'll have to open the input.cpp file.
You might remember that the keyboard handling code
is in the pure virtual functions
within both the Bob and Thomas classes,
and that the handleInput function
returns true when a jump
has been successfully initiated.
We'll now write the code to play a jump sound
when either Thomas or Bob successfully begins a jump.
So inside handle input specific to Thomas,
block after a play jump sound,
write m_SM.playJump function,
and do the same for Bob as well,
m_SM.playJump function.
Now open up the update.cpp file,
and we'll write a single line of code
to play a success sound when both Thomas
and Bob have simultaneously reached the goal
for the current level.
We'll write the code
after the play the reach goal sound block,
m_SM.playReachGoal function.
Also, within the update.cpp file
I've added some more code.
You have to add this highlighted code
just after the end if playing comment.
Make sure you add it here only.
This code loops through the m_FireEmitters vector
and decides when we need to call
the playFire function of the sound manager class.
The code is a bit like collision detection for sound.
Whenever Thomas stays within a 500 by 500 pixel
rectangle surrounding a fire emitter,
the playFire function is called
passing in the coordinates of the emitter
and of Thomas.
The playFire function does the rest of the work
and sets off a spacialized looping sound effect.
Next, open up the DetectCollisions.cpp file
and find the appropriate place where we would,
and add two lines of code.
We have to add them after the play a sound comment.
Write m_SM.playFallInFire function,
and write a line of code inside the else block,
m_SM.playFallInWater function.
This line of code triggers the playing
of a sound effect when the character falls
into a fire tile, and this line
will trigger the playing of a sound effect
when the character falls into water tile.
You can now run the game by clicking
on local windows debugger button.
You will hear all the sounds
(electronic buzzing)
including cool spacialization
when near a fire tile.
(rumbling)
(electronic buzzing)
Now, approaching the fire, you'll get to listen
cool specialization.
Amazing, isn't it?
In this video we've looked at playing the sounds.
Cool.
In the next video we'll take a look at the HUD class.