Game Development Reference
In-Depth Information
As you see, this is rather straightforward. Inside the HandleInput method, we call
ReplaceJewel three times to remove the three symbols that formed a valid combina-
tion:
ReplaceJewel(middleCol, i,
cellHeight);
ReplaceJewel(middleCol, i + 1,
cellHeight
2);
cellHeight 3);
ReplaceJewel(middleCol, i + 2,
Now, the grid is updated again. The position difference between the jewel objects
and their target location on the grid results in a nice 'falling down' effect. Finally,
since introducing new jewels could mean that there now is a new valid combination
of three jewels, we reset the counter i to zero with the instruction i=0; .
16.4.4 Updating Other Game Objects
Now that the grid has been updated, we can focus on the other game objects that
need to be updated. The first game object that needs to be updated is the score game
object, since the score should be increased if we handle a valid combination. We use
the Find method again to retrieve the score object, and we add 10 points to the score,
as follows:
ScoreGameObject score = GameWorld.Find("score") as ScoreGameObject;
score.Score += 10;
Also, because we found a valid combination, we push back the jewel cart:
JewelCart jewelCart = GameWorld.Find("jewelcart") as JewelCart;
jewelCart.Push();
For the complete program, have a look at the JewelJam5 example belonging to this
chapter.
16.5 What You Have Learned
In this chapter, you have learned:
how to organize game objects and assign IDs to them;
how to program gameplay aspects and interaction between game objects;
how to detect valid combinations of symbols in the Jewel Jam game.
Search WWH ::




Custom Search