- [Instructor] Hi, this is the last video
of this section the HUD class.
In the previous video we looked at coding
the HUD.h and HUD.cpp file.
In this video, we will add some code
to the engine file and the update function,
and we'll draw the HUD.
To start off, open the engine.h file
from the solution explorer window.
We'll add some code to it.
First, we add an include directive
for our new class,
#include "HUD.h".
this is the required include directive.
Now we write a code after create a soundmanager.
Write a comment first, the Hud.
Then Hud m_Hud,
int m_FramesSinceLastHUDUpdate
equals zero,
int m_TargetFramesPerHUDUpdate
equals 500.
First, we declare an instance
of the new HUD class that is m_Hud.
Then, we declare and initialize
two new member variables that will keep track
of how often we update the HUD.
Next, we need to add some code
to the update function of the engine class,
so open the update.cpp file
and add a code at the end of update function.
This is the highlighted code to be added.
It updates the HUD once every 500 frames.
Let's go through it.
In this line, m_FramesSinceLastUpdate
is incremented each frame.
When m_FrameSinceLastUpdate
exceeds m_TargetFramesPerHUDUpdate,
execution enters the if block.
Inside the if block we use stringstream objects
to update our text, that is ssTime
and ssLevel.
As you probably expected, however,
in this project we are using the HUD class,
so we'll call the setTime functions
and setLevel functions passing in
the current values that the text objects need
to be set to.
The final step in the if block
is to set m_FramesSinceLastUpdate
back to zero so it can start counting
toward the next update.
Finally, open the draw.cpp file.
Now, we'll add few lines of code
to draw the HUD each frame.
Add this highlighted code inside,
draw the HUD after m_Window.setView.
In this code we draw the HUD
by using the getter functions
from the HUD class, that is getLevel
and getTime function.
Notice that the call to draw the message
to that prompts the player to start
is only used when the game is not currently playing,
that is not m_Playing.
You can now run the game
by clicking on local windows debugger button.
Press enter, see the time tick down.
You can also play a few levels.
See how time ticks down, level ticks up.
Now we're in level two.
I'll play around a bit.
See, now we're in level three,
and this is level four.
When a player dies, you have to start
from the beginning, and,
when you get back to level one again,
notice that you have 10% less time than before.
That marks the end of this video.
Great, we've learned using the HUD class.
Now, to conclude this section,
let's recall what we did.
In this section we first looked at
what is spacialization
and how SFML handles spacialization.
We then moved on to building a SoundManager class
and deploying emitters.
Later we learned using the SoundManager class.
Lastly, we saw building a HUD class and using it.
Splendid.
In the next section we'll be learning
extending SFML classes, particle systems,
and shaders.