1
00:00:01,004 --> 00:00:04,003
- [Instructor] Hi, this
video is Playing Sounds.

2
00:00:04,003 --> 00:00:07,003
Previously we looked at
populating the sound emitters.

3
00:00:07,003 --> 00:00:09,003
In this video we're going to add the code

4
00:00:09,003 --> 00:00:11,008
for various sounds, that is, jump sound,

5
00:00:11,008 --> 00:00:16,002
success sound, fall in fire,
and fall in water sounds.

6
00:00:16,002 --> 00:00:20,000
To get started, open up
the LoadLevel.cpp file,

7
00:00:20,000 --> 00:00:21,002
and then we'll add the call

8
00:00:21,002 --> 00:00:24,000
to the new populate emitters function.

9
00:00:24,000 --> 00:00:25,009
We have to add the call between

10
00:00:25,009 --> 00:00:28,006
and repopulate the vertex array as well,

11
00:00:28,006 --> 00:00:31,005
and how long is the new time limit block.

12
00:00:31,005 --> 00:00:33,003
First, we'll add a comment,

13
00:00:33,003 --> 00:00:35,000
prepare the sound emitters,

14
00:00:35,000 --> 00:00:39,001
then populateEmitters m_FireEmitters,

15
00:00:39,001 --> 00:00:41,003
m_ArrayLevel.

16
00:00:41,003 --> 00:00:42,009
This is the call we've added

17
00:00:42,009 --> 00:00:45,003
to populate emitters function.

18
00:00:45,003 --> 00:00:47,009
The first sound to add is the jump sound.

19
00:00:47,009 --> 00:00:51,001
You'll have to open the input.cpp file.

20
00:00:51,001 --> 00:00:53,007
You might remember that
the keyboard handling code

21
00:00:53,007 --> 00:00:55,003
is in the pure virtual functions

22
00:00:55,003 --> 00:00:57,007
within both the Bob and Thomas classes,

23
00:00:57,007 --> 00:00:59,007
and that the handleInput function

24
00:00:59,007 --> 00:01:01,004
returns true when a jump

25
00:01:01,004 --> 00:01:03,007
has been successfully initiated.

26
00:01:03,007 --> 00:01:06,001
We'll now write the code
to play a jump sound

27
00:01:06,001 --> 00:01:09,005
when either Thomas or Bob
successfully begins a jump.

28
00:01:09,005 --> 00:01:12,006
So inside handle input specific to Thomas,

29
00:01:12,006 --> 00:01:15,000
block after a play jump sound,

30
00:01:15,000 --> 00:01:19,001
write m_SM.playJump function,

31
00:01:19,001 --> 00:01:21,005
and do the same for Bob as well,

32
00:01:21,005 --> 00:01:25,007
m_SM.playJump function.

33
00:01:25,007 --> 00:01:28,007
Now open up the update.cpp file,

34
00:01:28,007 --> 00:01:30,003
and we'll write a single line of code

35
00:01:30,003 --> 00:01:32,004
to play a success sound when both Thomas

36
00:01:32,004 --> 00:01:34,007
and Bob have simultaneously
reached the goal

37
00:01:34,007 --> 00:01:36,004
for the current level.

38
00:01:36,004 --> 00:01:37,004
We'll write the code

39
00:01:37,004 --> 00:01:40,004
after the play the reach goal sound block,

40
00:01:40,004 --> 00:01:44,009
m_SM.playReachGoal function.

41
00:01:44,009 --> 00:01:47,005
Also, within the update.cpp file

42
00:01:47,005 --> 00:01:49,002
I've added some more code.

43
00:01:49,002 --> 00:01:50,008
You have to add this highlighted code

44
00:01:50,008 --> 00:01:53,006
just after the end if playing comment.

45
00:01:53,006 --> 00:01:55,006
Make sure you add it here only.

46
00:01:55,006 --> 00:01:59,004
This code loops through
the m_FireEmitters vector

47
00:01:59,004 --> 00:02:00,009
and decides when we need to call

48
00:02:00,009 --> 00:02:04,003
the playFire function of
the sound manager class.

49
00:02:04,003 --> 00:02:07,006
The code is a bit like
collision detection for sound.

50
00:02:07,006 --> 00:02:10,008
Whenever Thomas stays
within a 500 by 500 pixel

51
00:02:10,008 --> 00:02:12,009
rectangle surrounding a fire emitter,

52
00:02:12,009 --> 00:02:15,002
the playFire function is called

53
00:02:15,002 --> 00:02:17,000
passing in the coordinates of the emitter

54
00:02:17,000 --> 00:02:18,004
and of Thomas.

55
00:02:18,004 --> 00:02:20,009
The playFire function
does the rest of the work

56
00:02:20,009 --> 00:02:24,002
and sets off a spacialized
looping sound effect.

57
00:02:24,002 --> 00:02:28,001
Next, open up the
DetectCollisions.cpp file

58
00:02:28,001 --> 00:02:31,000
and find the appropriate
place where we would,

59
00:02:31,000 --> 00:02:33,000
and add two lines of code.

60
00:02:33,000 --> 00:02:36,003
We have to add them after
the play a sound comment.

61
00:02:36,003 --> 00:02:42,002
Write m_SM.playFallInFire function,

62
00:02:42,002 --> 00:02:45,002
and write a line of code
inside the else block,

63
00:02:45,002 --> 00:02:51,000
m_SM.playFallInWater function.

64
00:02:51,000 --> 00:02:52,007
This line of code triggers the playing

65
00:02:52,007 --> 00:02:54,006
of a sound effect when the character falls

66
00:02:54,006 --> 00:02:57,007
into a fire tile, and this line

67
00:02:57,007 --> 00:02:59,005
will trigger the playing of a sound effect

68
00:02:59,005 --> 00:03:02,000
when the character falls into water tile.

69
00:03:02,000 --> 00:03:03,005
You can now run the game by clicking

70
00:03:03,005 --> 00:03:06,001
on local windows debugger button.

71
00:03:06,001 --> 00:03:07,006
You will hear all the sounds

72
00:03:07,006 --> 00:03:08,008
(electronic buzzing)

73
00:03:08,008 --> 00:03:10,008
including cool spacialization

74
00:03:10,008 --> 00:03:12,005
when near a fire tile.

75
00:03:12,005 --> 00:03:16,007
(rumbling)

76
00:03:16,007 --> 00:03:17,006
(electronic buzzing)

77
00:03:17,006 --> 00:03:19,008
Now, approaching the
fire, you'll get to listen

78
00:03:19,008 --> 00:03:21,007
cool specialization.

79
00:03:21,007 --> 00:03:23,008
Amazing, isn't it?

80
00:03:23,008 --> 00:03:26,009
In this video we've looked
at playing the sounds.

81
00:03:26,009 --> 00:03:27,007
Cool.

82
00:03:27,007 --> 00:03:30,006
In the next video we'll take
a look at the HUD class.

