Game Development Reference
In-Depth Information
//find a random roation value for the mine.
tempMine.dx=Math.cos(6.28*((Math.random()*360)-90)/360.0);
tempMine.dy = Math.sin(6.28 * ((Math.random() * 360) - 90) / 360.0);
if (level % 2 == 0) {
tempMine.y = 700
}else {
tempMine.y = 100
}
tempMine.x = 100;
tempMine.nextX = tempMine.x;
tempMine.nextY = tempMine.y;
tempMine.frame = int((Math.random() * 359)) ;
tempMine.animationList = mineAnimationFrames;
tempMine.bitmapData = tempMine.animationList[tempMine.frame];
tempMine.speed = (Math.random()*1)+2+level;
mines.push(tempMine);
}
}
Based on the level value, a set of Mine instances is created for the level. Mine instances for the
level are created starting at 30 and increasing by 20*level. This makes for a very difficult game at
higher levels.
The mines will be created inside a loop before each level is created. The number of mines is
based on a starting amount of 30, plus 20 multiplied by the level number:
for (var ctr:int=0;ctr<30+20*level;ctr++) {
… // interior loop code to create all mines for the level
}
The mine speed will be calculated as follows to allow it to be increased per level:
tempMine.speed = (Math.random()*1)+2+level;
This function also creates the look of our enemy mines (see Figure 11-5) based on a 32
32-pixel
symbol. This symbol was created in a similar manner to the player object in Fireworks. It is also
drawn to a drawCanvas Shape instance, placed into a BitmapData instance (mineBitmapData), and
rotated with an instance of the BlitArrayAsset class. The 360 rotated BitmapData instances from the
BlitArrayAsset.createRotationArray call are placed into the global mineAnimation Array.
Each new Mine instance is also given random dx and dy values. If the level value is an odd
number, we start all of the mines in the upper left-hand corner ( y=100 ). If the level is an even
number, we start the mines in the lower left-hand corner ( y=700 ).
Also, each mine is given a random frame to start in the animationList array (0-359). The speed
of each mine is also random with a maximum based on the level value. All of these calculations
make for a set of mines that will not be completely predictable to the game player.
Next, we will examine the particleManager.createParticlePool function. Here is the complete
code for the function; you have seen much of this code previously in the section called
“Optimizing with object pooling”:
Search WWH ::




Custom Search