Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
2
3
class ScoreGameObject : TextGameObject
{
4
protected int score;
5
6
7
public ScoreGameObject( int layer = 0, string id = "")
: base ("ScoreFont", layer, id)
8
{
9
}
10
11
12
public override void Update(GameTime gameTime)
{
13
this .Text = score.ToString();
14
this .Origin = this .TextSize;
15
}
16
17
18
public override void Reset()
{
19
base .Reset();
20
score = 0;
21
}
22
23
24
public int Score
{
25
get { return score; }
26
set { score = value ;}
27
}
28
}
29
Listing 16.2
A game object for maintaining and displaying the current score
We assign the score game object to layer 2, so that it is drawn on top of the back-
ground and the score frame. We also choose appropriate positions for the frame and
the score. Finally, we have assigned an ID “score” to the score game object, so that
other objects can retrieve it when needed.
16.3.2 A Moving Jewel Cart
In order to make the game a bit more exciting, we want to add a feeling of pressure
for the player. In the Jewel Jam game, this is done by drawing a jewel cart that slowly
moves out of the screen. Once the jewel cart is outside of the screen, the game is
over. Every time the player finds a correct combination of jewels, the jewel cart is
moved backed a little bit.
Search WWH ::




Custom Search