HUD, Barrel Roll, and Sounds
To make the game more challenging over time, we want to increase the speed of the player’s movement over time.
To do this, add a speed multiplier that starts out at 1.0
. Every 10
seconds, the multiplier should increase by 0.15
. Then when the player moves, rather than using the fixed 400
for forward and 300
for lateral, you should use the initial speed multiplied by the multiplier.
For example, after 20 seconds the multiplier would be 1.3, so the forward speed should be 400 * 1.3 = 520
.
To make sure the bullet always moves faster than the ship, rather than keeping the bullet speed at a constant 900, also multiply 900 by the speed multiplier.
Verify your game speeds up over time. How far can you get?
HUD
The template code includes an almost fully-implemented HUD (heads-up display), you just have to hook it up and implement one small function.
Create an instance of HUD
in the Player
constructor (HUD
is a subclass of UIComponent
).
You now see a shield gauge, though it doesn’t decrease with your shield level yet.
To get the bar to update based on the player’s current shield level, you need to implement the GetPlayerHitPoints()
function in HUD.cpp so that it gets the shield level value from Player
.
Your shield gauge should now change as you take damage.
Barrel Roll
It wouldn’t be a faithful Star Fox 64 adaptation without the classic barrel roll!
To add support for an actor to roll, you need to add a new float
variable to Actor
to track the roll angle (since the existing mRotation
variable is used for rotation about the up/z-axis).
Then, in Actor::Update
when you calculate the world transform matrix, you need to an additional matrix for the roll using Matrix4::CreateRotationX
. The order of matrix multiplication should be:
World = Scale * RotationZ * RotationX * Translation
Then in PlayerMove
, make it so that on the leading edge of the Q
you do a barrel roll:
- When the barrel roll starts, regenerate 1 shield level, but do not allow the shield level to go higher than 3
- The barrel roll should update the roll angle at a speed of
8.0f * Math::Pi
per second - The duration of the barrel roll is
0.5
seconds - You cannot start another barrel roll while one is in progress
- After a barrel roll finishes, make sure you set the roll angle back to 0 so that you don’t end up with a partially rotated ship
Confirm that you can do a barrel roll by pressing Q
, and that it regenerates the shields:
“Do a barrel roll!”
The code that causes Peppy (one of your squad mates) to say “Do a barrel roll!” is already implemented in the HUD
class for you. Peppy will remind you to do a barrel roll when not at full shields. Since we don’t want Peppy to say it over and over, there’ll be a cooldown timer:
- Initially, when the game starts the cooldown should be 0
- On every frame, decrement the cooldown by delta time
- On each frame, check if both the cooldown is <= 0 and the player is not at full shields, in which case you:
- Call
DoABarrelRoll()
(on theHUD
instance that thePlayer
already has) - Set the cooldown to a random float between 15 and 25 seconds, inclusive
- Call
This means that the very first time you take damage, you’ll immediately be told to “Do a barrel roll!” but if you don’t do one, it won’t tell you again for some amount of time.
Verify that Peppy pops up and says “Do a barrel roll!” the first time you take damage, and that if you stay at reduced shields, he pops up again after 15-25 seconds. (You can look at the final game video to see what it should look like).
Sound Effects
Finally, we’ll add some sound effects.
Add these non-looping sound effects:
- When the player takes damage (but doesn’t die), play
"ShipHit.wav"
- When the player dies, play
"ShipDie.wav"
- When the player shoots a bullet, play
"Shoot.wav"
- When the player does a barrel roll, play
"Boost.wav"
- When a block is destroyed by a bullet, play
"BlockExplode.wav"
(make sure this only plays once even if there’s a chain reaction, or it’ll sound bad)
Next, add these looping sounds:
- The music
"Music.ogg"
should just always play - Play the
"ShipLoop.ogg"
for as long as the player is alive. Once the player dies, stop the sound - For the looping
"DamageAlert.ogg"
:- It should start playing when the player’s shield level hits 1
- Stop the sound if the shield level goes back up (but it should still start playing again the next time the shield level hits 1)
- Stop the sound if the player dies
Your game should now behave like the final video:
Once you’ve pushed your code, you should review the grading specifications to confirm you’ve satisfied them.