Game Development Reference
In-Depth Information
Figure 8-7. Blocks fading out to end a level
The makeBlocksFall function is very similar to fadeBlocks . It iterates through all of the Block
objects in the board 2D array. Instead of calling startFade , it calls startFalling , passing the
bottom of the screen plus the height of a Block ( gameHeight + BLOCK_HEIGHT ) as the first
parameter ( fallEndY ). We pass this value so that the entire object will leave the screen before it
is removed from the screen. The second parameter is a random value that will be used for the
speed of the Block (to make the falling not look completely uniform).
public function makeBlocksFall():void {
for (var r:int = 0; r < board.length; r++) {
for (var c:int = 0; c < board[r].length; c++) {
tempBlock = board[r][c];
tempBlock.startFalling(gameHeight + BLOCK_HEIGHT, (Math.random()*15)+10);
}
}
}
Finally, we have come to endGame and endLevel function. Both functions call cleanUpevel before
they dispatch the proper event to Main . The cleanUpLevel function iterates through all the Block
objects in the board 2D array by calling removeBlock .
public function endGame():void {
cleanUpLevel();
dispatchEvent(new Event(GAME_OVER));
Search WWH ::




Custom Search