Game Development Reference
In-Depth Information
ject should get the name of the asset that it represents as a parameter, and then
retrieve the sprite itself from the resource manager. The resource manager is a static
member variable that is available from the JewelJam class. As a result, the new
SpriteGameObject constructor is given as follows:
public SpriteGameObject( string assetname, int layer = 0)
: base (layer)
{
sprite = JewelJam.AssetManager.GetSprite(assetname);
}
15.4.2 The RowSelectGameObject Class
The game object responsible for selecting different rows also needs to be changed
slightly so that it retrieves the sprites that it needs on its own. For this, we need to
modify the constructor, just like for the SpriteGameObject class:
public RowSelectGameObject(JewelGrid grid, int layer = 0)
: base ("spr_selector_frame", layer)
{
selectedRow = 0;
this .grid = grid;
}
Since RowSelectGameObject is a subclass of SpriteGameObject , the only thing we need
to do here is passing the image name as a parameter to the base constructor, so that
the sprite is properly loaded.
15.4.3 The Jewel Class
In order to prepare the Jewel class a bit more for the game that it is going to be used
for, we are going to change a couple of things in this class. The biggest change is
that we want to introduce more variety in the sorts of jewels that this object can
represent. Basically, there will be three variations: the jewel's shape can vary, the
color of the jewel can vary, and the number of jewels can vary (one, two or three
jewels). So, we have three kinds of properties that a jewel can have (shape, color and
number). Also, for each property there are three variations: there are three different
shapes, three different colors and three different numbers. In total, that means there
are 3
27 possible jewel configurations (see also Fig. 15.1 ).
Instead of creating 27 different image files, we will store all the different varieties
in a single image file which is loaded when we create the first Jewel object (again, see
×
3
×
3
=
Search WWH ::




Custom Search