Drawing the HUD, and the home and level up screens

All the code from the next three code blocks goes in the drawing phase of our game loop. All we need to do is to 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); 
 
   // 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 previous block of code is that ...

Get Beginning C++ Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.