Game Development Reference
In-Depth Information
When the game is started, you begin playing the background music as soon as the assets are
loaded, as follows:
sounds.music.volume = 0.3;
sounds.music.play();
And when you get a valid combination of jewels (single, double, or triple), you play different sound
effects (see the JewelGrid class):
if (nrCombis === 1) {
sounds.combi.play();
}
else if (nrCombis === 2) {
score.score += 50;
var doubleTimer = this.root.find(ID.double_timer);
doubleTimer.startVisible();
sounds.double.play();
}
else if (nrCombis >=3) {
score.score += 100;
var tripleTimer = this.root.find(ID.triple_timer);
tripleTimer.startVisible();
sounds.triple.play();
}
Finally, you play a sound when the game is over (see the JewelJamGameWorld class):
var gameOver = this.root.find(ID.game_over);
if (this.gameOver() && !gameOver.visible) {
gameOver.visible = true;
sounds.gameover.play();
return;
}
This completes the Jewel Jam game. You can play the game by running the JewelJamFinal
application belonging to this chapter. As an exercise, see if you're able to extend the game yourself
with new features. For example, you could add extra animation effects when a combination of jewels
is made. Or how about adding a leaderboard/high-score list? In any case, happy jewel hunting!
Search WWH ::




Custom Search