Damage Indicators
Now we’ll add some HUD elements both for when you take damage and when you die.
Damage
In HUD
, add a class Texture*
member variable to store the damage indicator texture.
In the constructor, call GetTexture
on the renderer, passing in "Assets/Textures/UI/DamageIndicator.png"
, and save the result in the member variable.
Add two float member variables for the damage indicator angle and the damage indicator time.
Add a function called PlayerTakeDamage
that takes in the angle, and it should set the angle member variable to what’s passed in, and the time to 1.5f
.
Add an override of Update
that reduces the damage indicator every frame as appropriate.
In HUD::Draw
, if the damage indicator time is > 0, call DrawTexture
with the following parameters:
shader
- Damage indicator texture
Vector2::Zero
as the position1.0f
as the scale- The damage indicator angle member variable
Next, you need to add an OnDamage
callback for the Player
’s health component. In the callback:
- Get the vector from the player to the location (that you get in to the callback). Set the z component to 0 and normalize the vector.
- Get the forward vector of the player, set the z component to 0 and normalize the vector
- Calculate the angle between (2) and (1), using the cross product between them to figure out if it’s positive or negative
- Call the
PlayerTakeDamage
function on the HUD, passing in the angle
Try taking damage from a turret and rotate your camera while taking damage. You should see the damage indicator point towards the turret:
Death Taunt and Indicator
Rather than just instantly respawning the player when the player dies, we want to have GlaDOS taunt the player before respawning.
There are four sounds to choose from as well as corresponding subtitles:
Sound | Subtitle |
---|---|
"Glados-PlayerDead1.ogg" | "Congratulations! The test is now over." |
"Glados-PlayerDead2.ogg" | "Thank you for participating in this Aperture Science computer-aided enrichment activity." |
"Glados-PlayerDead3.ogg" | "Goodbye." |
"Glados-PlayerDead4.ogg" | "You're not a good person. You know that, right?" |
When the player dies, randomly select one of these four sounds (Hint: store them in a vector and use Random::GetIntRange
to pick one). Then play the sound you selected, saving the SoundHandle
. Also show the corresponding subtitle.
Then at the very start of PlayerMove::Update
, if the player’s health component says the player is dead, you should check if the mDeathSound
is stopped. If it is, you should reload the level. otherwise, just return (so PlayerMove::Update
won’t move the player anymore). Similarly, PlayerMove::ProcessInput
should not do anything if the player is dead.
Try dying and confirm that the player gets paused for the duration of the taunt, before reloading the level:
There’s one small bug with this, which is if there happens to be an active VO trigger when you die. You may have overlapping VO and also another VO may play overwriting the subtitle.
To fix this, make the existing logic in VOTrigger::OnUpdate
only if the player is alive. If the player is dead, you should check to see if a current VO sound is playing, and if it is, stop it.
Next, make it so when the player dies the HUD
shows the "Assets/Textures/UI/DamageOverlay.png"
texture on screen. You can just specify the first two parameters to DrawTexture
and leave the rest at their defaults.
You should now also see the damage overlay when dead:
Changing the Level Back and Input Replays
Finally, set the starting level back to "Assets/Level01.json"
, as we will want to play through your full game.
Please make sure to set it back to the first level!
We have included input replays for the final levels, though keep in mind you will have to start the replay for each level manually as it doesn’t persist through levels. Furthermore, we DO NOT require that you pass validation mode for this final lab in order to get an A. You can disable validation mode by changing the call to StartPlayback
in Game.cpp so that you pass in false
as the optional second parameter.
It was quite the journey, but if you got all of Labs 9 through 12 working, you should be able to successfully play through the game!
Once you’ve pushed your code, you should review the grading specifications to confirm you’ve satisfied them.