Game Development Reference
In-Depth Information
if
(a.IsEmptyBox())
{
this
.Visible =
false
;
a.sprite.SheetIndex =
this
.sprite.SheetIndex;
}
If the sheet index of animal
a
is the same as the sheet index of this animal, or
either one of the penguins is multicolored, and the animal is not a seal, we have a
valid pair of penguins and we make both penguins invisible:
else if
((a.sprite.SheetIndex == sprite.SheetIndex ||
this
.IsMultiColoredPenguin()
|| a.IsMultiColoredPenguin()) && !a.IsSeal())
{
a.Visible =
false
;
this
.Visible =
false
;
}
We also have to display an extra pair in the top left of the screen, but we will deal
with that in the next section.
Finally, in all other cases, we simply stop moving:
else
this
.StopMoving();
23.6 Maintaining the Number of Pairs
In order to maintain the number of pairs and draw it nicely on the screen, we will
add another class called
PairList
to the game. In the
Level
class, we add an instance
of this class to the game world, and position it near the top left of the screen:
PairList pairList =
new
PairList(nrpairs, 1, "pairList");
pairList.Position =
new
Vector2(20, 15);
this
.Add(pairList);
The
PairList
class inherits from the
SpriteGameObject
class. It consists of a frame, and
on top of it we draw a number of sprites indicating the number of required pairs.
Since we want to indicate the color of the pair that was made, we store these pairs
in an array of
int
values, which is a member variable of the
PairList
class:
protected int
[] pairs;
The reason that we use an array of
int
values is that we can define per pair which
color it is, and how many pairs we need in total. In the member variable
pairSprite
we
store the sprite representing a pair. The image we use for that sprite is a sprite strip,