Game Development Reference
In-Depth Information
Creating the Bullets and Explosions
Bullets are shot from both the enemy and hero ship, and travel at a velocity that is faster and in the opposite direction
of the ship that fired it. When a bullet hits a ship, an explosion animation will take the ship's place. Figure 11-5
demonstrates the frames used for both the bullet and explosion sprites.
Figure 11-5. The sprite frames for the explosion and bullets
There are two bullet frames, one green and one red. The red bullets are fired from the hero and the green from
the enemies. The Bullet class renders the appropriate frame (see Listing 11-6).
Listing 11-6. The Bullet Class, Declared in Bullet.js
(function (window) {
window.game = window.game || {}
function Bullet() {
this.initialize();
}
var p = Bullet.prototype = new createjs.Sprite();
p.Sprite_initialize = p.initialize;
p.speed = 500;
p.nextY = null;
p.shouldDie = false;
p.initialize = function () {
this.Sprite_initialize(spritesheet, "bullet");
this.paused = true;
}
 
Search WWH ::




Custom Search