HTML and CSS Reference
In-Depth Information
this ._quad.retrieve ( list , tower ) ; // Get the check list
// cc.log("length:" + list.length);
for ( var j = 0 , jLen = list.length ; j < jLen ; j ++ ) {
towers [ i ].checkAttack ( list [ j ] ) ; // Check attackable
In this game, the collision range of monsters and bullets is a circle shape, so you use circle-to-circle collision
detection. It only needs to get the distance between monster and bullet, and check whether it is smaller than the sum
of the bullet radius and the monster radius.
Adding Music and Sound Effects
For music and sound effects, you need to preload them and play them when desired. Note that you need at least two
audio formats to support all browsers (mp3 and ogg, for instance). If you choose to play an mp3 or ogg file, the engine
will choose the file that is supported by the installed browser. The code defining sound effects is shown in Listing 24-19.
Listing 24-19. Defining Sound Effects in resource.js
var s_AttackEffect_mp3 = "res/Music/AttackEffect.mp3" ;
var s_AttackEffect_ogg = "res/Music/AttackEffect.ogg" ;
var g_resources = [
... ...
{ src : s_AttackEffect_mp3 } ,
{ src : s_AttackEffect_ogg }
] ;
After defining a sound effect in resource.js , you can play it when desired. The cc.AudioEngine is a singleton
object in Cocos2d, and you can call it to play sound effects directly. The code for playing sound effects is as follows:
// play mp3 or ogg--you don't need both.
You also should add a “Sound” menu item on ToolBar to control the on/off function for audio.
Creating the Game Over Scene
This is the final part of the game. The method for creating the game over scene is almost the same as that for creating
the main menu, as learned previously. It shows you whether you win or lose, your score, and a start button. The win
and lose game over screens are shown in Figure 24-19 .
Search WWH ::

Custom Search