1
00:00:01,007 --> 00:00:03,008
- [Instructor] Hi, this is the last video

2
00:00:03,008 --> 00:00:06,005
of this section the HUD class.

3
00:00:06,005 --> 00:00:08,005
In the previous video we looked at coding

4
00:00:08,005 --> 00:00:12,002
the HUD.h and HUD.cpp file.

5
00:00:12,002 --> 00:00:14,004
In this video, we will add some code

6
00:00:14,004 --> 00:00:17,000
to the engine file and
the update function,

7
00:00:17,000 --> 00:00:18,009
and we'll draw the HUD.

8
00:00:18,009 --> 00:00:21,007
To start off, open the engine.h file

9
00:00:21,007 --> 00:00:23,009
from the solution explorer window.

10
00:00:23,009 --> 00:00:25,008
We'll add some code to it.

11
00:00:25,008 --> 00:00:28,004
First, we add an include directive

12
00:00:28,004 --> 00:00:30,001
for our new class,

13
00:00:30,001 --> 00:00:34,000
#include "HUD.h".

14
00:00:34,000 --> 00:00:36,008
this is the required include directive.

15
00:00:36,008 --> 00:00:40,009
Now we write a code after
create a soundmanager.

16
00:00:40,009 --> 00:00:43,007
Write a comment first, the Hud.

17
00:00:43,007 --> 00:00:47,007
Then Hud m_Hud,

18
00:00:47,007 --> 00:00:52,002
int m_FramesSinceLastHUDUpdate

19
00:00:52,002 --> 00:00:53,006
equals zero,

20
00:00:53,006 --> 00:00:57,009
int m_TargetFramesPerHUDUpdate

21
00:00:57,009 --> 00:01:00,001
equals 500.

22
00:01:00,001 --> 00:01:01,009
First, we declare an instance

23
00:01:01,009 --> 00:01:06,002
of the new HUD class that is m_Hud.

24
00:01:06,002 --> 00:01:08,000
Then, we declare and initialize

25
00:01:08,000 --> 00:01:10,004
two new member variables
that will keep track

26
00:01:10,004 --> 00:01:12,006
of how often we update the HUD.

27
00:01:12,006 --> 00:01:14,007
Next, we need to add some code

28
00:01:14,007 --> 00:01:17,003
to the update function
of the engine class,

29
00:01:17,003 --> 00:01:20,000
so open the update.cpp file

30
00:01:20,000 --> 00:01:24,003
and add a code at the
end of update function.

31
00:01:24,003 --> 00:01:27,000
This is the highlighted code to be added.

32
00:01:27,000 --> 00:01:30,004
It updates the HUD once every 500 frames.

33
00:01:30,004 --> 00:01:32,000
Let's go through it.

34
00:01:32,000 --> 00:01:35,005
In this line, m_FramesSinceLastUpdate

35
00:01:35,005 --> 00:01:37,008
is incremented each frame.

36
00:01:37,008 --> 00:01:40,005
When m_FrameSinceLastUpdate

37
00:01:40,005 --> 00:01:44,004
exceeds m_TargetFramesPerHUDUpdate,

38
00:01:44,004 --> 00:01:46,009
execution enters the if block.

39
00:01:46,009 --> 00:01:50,007
Inside the if block we
use stringstream objects

40
00:01:50,007 --> 00:01:53,007
to update our text, that is ssTime

41
00:01:53,007 --> 00:01:55,006
and ssLevel.

42
00:01:55,006 --> 00:01:57,005
As you probably expected, however,

43
00:01:57,005 --> 00:02:00,004
in this project we are
using the HUD class,

44
00:02:00,004 --> 00:02:02,005
so we'll call the setTime functions

45
00:02:02,005 --> 00:02:04,008
and setLevel functions passing in

46
00:02:04,008 --> 00:02:07,001
the current values that
the text objects need

47
00:02:07,001 --> 00:02:08,008
to be set to.

48
00:02:08,008 --> 00:02:10,007
The final step in the if block

49
00:02:10,007 --> 00:02:14,004
is to set m_FramesSinceLastUpdate

50
00:02:14,004 --> 00:02:16,004
back to zero so it can start counting

51
00:02:16,004 --> 00:02:18,003
toward the next update.

52
00:02:18,003 --> 00:02:22,003
Finally, open the draw.cpp file.

53
00:02:22,003 --> 00:02:24,003
Now, we'll add few lines of code

54
00:02:24,003 --> 00:02:26,006
to draw the HUD each frame.

55
00:02:26,006 --> 00:02:29,000
Add this highlighted code inside,

56
00:02:29,000 --> 00:02:33,003
draw the HUD after m_Window.setView.

57
00:02:33,003 --> 00:02:35,003
In this code we draw the HUD

58
00:02:35,003 --> 00:02:36,007
by using the getter functions

59
00:02:36,007 --> 00:02:39,006
from the HUD class, that is getLevel

60
00:02:39,006 --> 00:02:41,006
and getTime function.

61
00:02:41,006 --> 00:02:43,007
Notice that the call to draw the message

62
00:02:43,007 --> 00:02:45,008
to that prompts the player to start

63
00:02:45,008 --> 00:02:48,009
is only used when the game
is not currently playing,

64
00:02:48,009 --> 00:02:52,006
that is not m_Playing.

65
00:02:52,006 --> 00:02:53,006
You can now run the game

66
00:02:53,006 --> 00:02:56,004
by clicking on local
windows debugger button.

67
00:02:56,004 --> 00:02:59,002
Press enter, see the time tick down.

68
00:02:59,002 --> 00:03:01,006
You can also play a few levels.

69
00:03:01,006 --> 00:03:05,003
See how time ticks down, level ticks up.

70
00:03:05,003 --> 00:03:07,003
Now we're in level two.

71
00:03:07,003 --> 00:03:08,008
I'll play around a bit.

72
00:03:08,008 --> 00:03:10,008
See, now we're in level three,

73
00:03:10,008 --> 00:03:15,002
and this is level four.

74
00:03:15,002 --> 00:03:17,001
When a player dies, you have to start

75
00:03:17,001 --> 00:03:18,008
from the beginning, and,

76
00:03:18,008 --> 00:03:20,005
when you get back to level one again,

77
00:03:20,005 --> 00:03:23,009
notice that you have 10%
less time than before.

78
00:03:23,009 --> 00:03:26,003
That marks the end of this video.

79
00:03:26,003 --> 00:03:29,009
Great, we've learned using the HUD class.

80
00:03:29,009 --> 00:03:31,006
Now, to conclude this section,

81
00:03:31,006 --> 00:03:33,007
let's recall what we did.

82
00:03:33,007 --> 00:03:35,004
In this section we first looked at

83
00:03:35,004 --> 00:03:36,009
what is spacialization

84
00:03:36,009 --> 00:03:40,002
and how SFML handles spacialization.

85
00:03:40,002 --> 00:03:42,006
We then moved on to building
a SoundManager class

86
00:03:42,006 --> 00:03:44,003
and deploying emitters.

87
00:03:44,003 --> 00:03:47,006
Later we learned using
the SoundManager class.

88
00:03:47,006 --> 00:03:51,000
Lastly, we saw building
a HUD class and using it.

89
00:03:51,000 --> 00:03:52,004
Splendid.

90
00:03:52,004 --> 00:03:54,004
In the next section we'll be learning

91
00:03:54,004 --> 00:03:57,005
extending SFML classes, particle systems,

92
00:03:57,005 --> 00:03:58,005
and shaders.

