Drawing the HUD, home, and level-up screens
All the code in the following three code blocks goes in the drawing phase of our game loop. All we need to do is draw the appropriate Text
objects during the appropriate states, in the draw section of the main game loop.
In the PLAYING
state, add the following highlighted code:
//Draw the crosshair
window.draw(spriteCrosshair);
// Draw the player
window.draw(player.getSprite());
// Switch to the HUD view
window.setView(hudView);
// Draw all the HUD elements
window.draw(spriteAmmoIcon);
window.draw(ammoText);
window.draw(scoreText);
window.draw(hiScoreText);
window.draw(healthBar);
window.draw(waveNumberText);
window.draw(zombiesRemainingText);
}
if (state == State::LEVELING_UP)
{
}
The vital thing to notice in the preceding block of code is that we switch views to the HUD view. This causes everything to be drawn at the precise screen positions we gave each of the elements...