HTML and CSS Reference
In-Depth Information
var sourceX = Math.floor(tile % 4) * tempParticle.width;
var sourceY = Math.floor(tile / 4) * tempParticle.height;
context.drawImage(particleTiles, sourceX, sourceY,
tempParticle.width, tempParticle.height, tempParticle.x,
context.restore(); //pop old state on to screen
In checkCollisions() , we will need to pass the type parameter to the createExplode()
function so the type can be assigned to the particles in the explosion. Here is an example
of a createExplode() function call used for a rock instance:
We pass the tempRock.scale as the final parameter because we are using the rock's scale
as the type .
For a saucer:
For the saucers and the player, we will pass a number literal into the createExplode()
function. In the saucer's case, we pass in a 1 . For the player ship, we pass in a 4 :
createExplode(player.x+player.halfWidth, player.y+player.halfWidth,50,4);
Note that the createExplode() function call for the player is in the playerDie() function,
which is called from checkCollisions() .
After we discuss adding sound and a particle pool to this game, we will
present the entire set of code ( Example 9-1 ), replacing the Geo Blaster
Basic code. There will be no need to make the changes to the individual
Adding Sound
In Chapter 7 , we covered everything we need to know to add robust sound management
to our canvas applications. If you are unfamiliar with the concepts presented in Chap-
ter 7 , please review that chapter first. In this chapter, we will cover only the code nec-
essary to include sound in our game.
Arcade games need to play many sounds simultaneously, and sometimes those sounds
play very rapidly in succession. In Chapter 7 , we used the HTML5 <audio> tag to create
a pool of sounds, solving the problems associated with playing the same sound instance
multiple times.
Search WWH ::

Custom Search