Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
2
3
class JewelJamGameWorld : GameObjectList
{
4
public JewelJamGameWorld()
5
{
6
this .Add( new SpriteGameObject("spr_background"));
7
8
9
GameObjectList playingField = new GameObjectList(1);
playingField.Position = new Vector2(85, 150);
10
this .Add(playingField);
11
12
13
JewelGrid grid = new JewelGrid(10, 5, 0);
playingField.Add(grid);
14
15
16
playingField.Add( new RowSelectGameObject(grid, 1));
}
17
}
18
Listing 15.2
The class for representing the game world in the JewelJam game
15.3 Accessing the Game World
In the JewelJam game, we do not have a separate GameWorld class anymore. This
is because the GameObjectList class is now basically the basis for creating the game
world consisting of a hierarchy of game objects that are drawn in a certain order.
However, creating all the game objects is now done in the JewelJam class because
of that. This is not a very nice software design, because now the basic initialization
tasks are mingled with the game-specific object creation tasks. We can separate them
by creating a new class called JewelJamGameWorld which will be a subclass of the
GameObjectList class. In the constructor of this class, we write all the instructions for
filling the game world. Now we only have to make an instance of that class in the
JewelJam class, and call the game loop methods on the JewelJamGameWorld object.
The complete JewelJamGameWorld class can be found in Listing 15.2 . You can find
the new version of the JewelJam class in the JewelJam4 program belonging to this
chapter.
15.4 Game Objects Using the Asset Manager
15.4.1 The SpriteGameObject Class
Since we want our objects to retrieve their assets themselves, we do not want to
pass a Texture2D object anymore as a parameter. For example, the sprite game ob-
Search WWH ::




Custom Search