Game Development Reference
In-Depth Information
The
click
event will fire the function to explode the asteroid instance. This is done by calling on its
explode
function, which will play the explosion animation, play a sound, and dispatch the
EXPLOSION_COMPLETE
event, which
will remove it from the stage. Figure
9-4
shows an asteroid exploding during gameplay.
Figure 9-4.
Mid-game asteroid explosion
The Complete Exploding Asteroids Game Code
The complete game code for Exploding Asteroids is shown in Listing 9-21.
Listing 9-21.
Exploding Asteroids - explodingAsteroids.js
window.game = window.game || {};
var canvas, stage, assets, preloader, spritesheet;
var spawnDelay = 40;
var count = 0;
function init() {
canvas = document.getElementById('canvas');
stage = new createjs.Stage(canvas);
createjs.Ticker.setFPS(30);
game.assets = new game.AssetManager();
preloadAssets();
}