Game Development Reference
In-Depth Information
var jewel = new Jewel();
this.addAt(jewel, x, 0);
jewel.position.y = newYPosition;
};
In the update method, you call removeJewel three times to remove the three jewels that form a valid
combination:
this.removeJewel(middleCol, i, -this.cellHeight);
this.removeJewel(middleCol, i + 1, -this.cellHeight * 2);
this.removeJewel(middleCol, i + 2, -this.cellHeight * 3);
As the grid is updated, the position difference between the jewel objects and their target location on
the grid results in the desired falling effect. Finally, because introducing new jewels may mean there is
a new valid combination of three jewels, you reset the counter i to zero with the instruction i = 0; .
Updating Other Game Objects
Now that the grid has been updated, you can focus on the other game objects that need to be
updated. The first game object that needs to be updated is score , because the score should be
increased if you handle a valid combination. You use the find method to retrieve the score object,
and you add 10 points to the score, as follows:
var score = this.root.find(ID.score);
score.score += 10;
Also, because you found a valid combination, you push back the jewel cart:
var jewelCart = this.root.find(ID.jewel_cart);
jewelCart.pushCart();
For the complete program, see the JewelJam4 example belonging to this chapter.
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 jewels in the Jewel Jam game
 
Search WWH ::




Custom Search