Game Development Reference
In-Depth Information
Fig. 14.1
Moving the playing field to another position
order to introduce some variety. Because we do not care about where these objects
are placed in the grid, a nested
for
-instruction is not necessary. We simply have to
create
grid.Rows
∗
grid.Columns
objects and add them to the grid:
Texture2D jewel1 = Content.Load<Texture2D>("spr_single_jewel1");
Texture2D jewel2 = Content.Load<Texture2D>("spr_single_jewel2");
Texture2D jewel3 = Content.Load<Texture2D>("spr_single_jewel3");
for
(
int
i=0;i<grid.Rows
∗
grid.Columns; i++)
{
int
val = random.Next(3);
Jewel obj;
if
(val == 0)
obj =
new
Jewel(jewel1);
else if
(val == 1)
obj =
new
Jewel(jewel2);
else
obj =
new
Jewel(jewel3);
grid.Add(obj);
}
Now, the only thing left to do is to call the game loop methods of the
gameWorld
ob-
ject at the right time. Because of the hierarchy of game objects, the game loop calls