Game Development Reference
In-Depth Information
Fig. 9.1 Balloons in a
triangle shape
by braces. For example:
int x, y;
for (y=0; y<7; y++)
for (x=0; x<y; x++)
spriteBatch.Draw(livesSprite,
new Vector2(livesSprite.Width
x, livesSprite.Height y),
Color.White);
In this fragment, the variable y counts from 0 to 7. For each of these values of
y , the body is executed, which itself consists of a for -instruction. This second for -
instruction uses the counter x , which has as a upper limit the value of y . Therefore,
in each progression of the outer for -instruction, the inner for -instruction will go on
longer. The instruction that is repeatedly repeated is drawing a yellow balloon sprite
at the position calculated by using the values of the x and y counters. The result of
this loop is a number of balloon placed in the shape of a triangle (see Fig. 9.1 ).
The first line in this shape contains zero balloons. The reason for this is that the
value of y is still zero at that point, which means that the inner for -instruction is
executed zero times.
9.6 Restarting the Game After the Game Is Over
When the player has lost all of his/her lives, the game is over. How do we deal with
this? In the case of the Painter game, we would like to show a 'game over' screen.
The player can press the space bar which would restart the game. In order to add
this to the game, we load an extra sprite in the GameWorld class that represents the
game over screen:
gameover = Content.Load<Texture2D>("spr_gameover");
 
Search WWH ::




Custom Search