Time for action – scoring
To implement the scoring system for Mars Runner, perform the following steps:
1. Add two fields to the
MarsRunnerPlayScreen
class as follows:float score = 0; SpriteFont font;
2. In the
LoadContent()
method of theMarsRunnerPlayScreen
class, initialize the font field as follows:font = content.Load<SpriteFont>("gamefont");
3. In the
Update()
method of theMarsRunnerPlayScreen
class, inside theif
statement that checksplayerPosition
, increment the player's score, and add anelse
condition that ends the game if the player has reached the end of the track. The newif
statement should read as follows:if (playerPosition < 2880) { playerPosition += 15 * elapsed; skybox.Rotation += 0.1f * elapsed; score += elapsed; } else { EndGame(); }
4. Still in the
Update()
method, inside theif
statement checking for player hits on enemies, increase the player's score just after the call toenemy.CrashSaucer()
as follows:score += 100;
5. In the
Draw()
method of...