Time for action – implementing score tracking
Add a declaration to the Player class to store the player's score:
private int score = 0;
Add a property to the Player class to allow access to the score variable:
public int Score { get { return score; } set { score = value; } }
Replace the current
Update()
method in the LevelManager class with the following new version of the method:public static void Update(GameTime gameTime) { if (!player.Dead) { for (int x = gemstones.Count - 1; x >= 0; x--) { gemstones[x].Update(gameTime); if (player.CollisionRectangle.Intersects( gemstones[x].CollisionRectangle)) { gemstones.RemoveAt(x); player.Score += 10; } } } }
In the Game1 class, add a declaration for a
SpriteFont
instance that we can use to draw the player's score and a vector pointing to the location on the screen where the score will be displayed:SpriteFont pericles8...