Time for action – implementing score tracking
Add a property to the
Player
class to hold the player's score:Public Property Score As Integer
Replace the current
Update()
method in theLevelManager
class with the following new version of the method:Public Sub Update(gameTime As GameTime) If Not _player.Dead Then For x As Integer = _gemstones.Count - 1 To 0 Step - 1 _gemstones(x).Update(gameTime) If _player.CollisionRectangle.Intersects( _gemstones(x).CollisionRectangle) Then _gemstones.RemoveAt(x) _player.Score += 10 End IF Next End If End Sub
In the
Game1
class, add a declaration for aSpriteFont
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:Private pericles8 As SpriteFont Private scorePosition As Vector2 = New Vector2(20, 580)
In the
LoadContent()
method of theGame1
class, initialize thepericles8...