You have levels and end-game logic now, but what’s the fun
when your score is always zero? In this section, you’ll flesh out
scoring for the game. You’re already displaying the score at the end of
the game, but you’ll want to let players see their scores as they play.
To do that, add a class-level
SpriteFont variable to your
Game1 class, with which you’ll draw the
And yes, that’s right: the next thing that you’ll need to do is add a new spritefont to your project. Right-click the 3D GameContent\Fonts folder in Solution Explorer and select Add→New Item…. Select the Sprite Font template on the right and name the file ScoreFont.spritefont.
To make your scoring font stand out a bit more, open the
ScoreFont.spritefont file and find the
<Style> element. This element lets you
tweak properties such as setting the text in bold, italics, etc. Change
the spritefont to use a bold font by changing the
<Style> tag as follows:
<Style> tag entries
are case-sensitive, as it says in the actual spritefont file. Make
sure you use the text
Next, in the
Game1 class, add the
following code to load the font:
scoreFont = Content.Load<SpriteFont>(@"Fonts\ScoreFont");
Now you’ll want to use that spritefont to draw the score on the screen. In addition to just drawing the score, though, it would be helpful for players to see how many more ships they can miss in each level.
To do that, you’ll ...