Game Development Reference
In-Depth Information
Initializing the game
The init function is called from the Game constructor to set up the initial variable values for Color
Drop. We start by setting the value for tileSheet . As we discussed in the section about the Block
class, we need to pass the tileSheet to Block instances when they are created. The parameters
for TileSheet are the bitmap we are using for the tiles as set in the SWF library (in this case,
ColorSheet ) and the height and width of the tiles we are going to cut from the tile sheet. The Flex
version of this code has been commented out but left in so you can see the differences.
public function init():void {
//***** Flash IDE *****
tileSheet = new TileSheet(new ColorSheet(0,0), BLOCK_WIDTH,BLOCK_HEIGHT);
//***** End Flash IDE *****
//***** Flex *****
//tileSheet = new TileSheet(new ColorSheet().bitmapData, BLOCK_WIDTH,
BLOCK_HEIGHT); //***** End Flex *****
Now, we need to create the difficulty levels for the game. To do this, we first initialize our
difficultyLevelArray array. Then, we simply create each level one at a time by pushing a new
instance of DifficultyLevel into the array.
Since the object of the game Color Drop is to remove adjacent same-color blocks from the screen,
the difficulty ramps by adding more colors that will appear per level. We do this by passing an array
of Block.BLOCK_COLOR_XXX values as the first parameter for DifficultyLevel . The other parameters
are startPlays , the number of plays added for the player when the level starts; and
scoreThreshold , the score that must be reached on that level to advance to the next. We have left
both of these values the same for every level. This would be the first place to tinker with this game,
changing values to see if the difficulty for this game can be managed in a different way.
difficultyLevelArray = new Array();
difficultyLevelArray.push(new DifficultyLevel(
[Block.BLOCK_COLOR_RED,Block.BLOCK_COLOR_GREEN,Block.BLOCK_COLOR_BLUE],10,500));
difficultyLevelArray.push(new DifficultyLevel(
[Block.BLOCK_COLOR_RED,Block.BLOCK_COLOR_GREEN,Block.BLOCK_COLOR_BLUE,
Block.BLOCK_COLOR_VIOLET],10,500));
difficultyLevelArray.push(new DifficultyLevel(
[Block.BLOCK_COLOR_RED,Block.BLOCK_COLOR_GREEN,Block.BLOCK_COLOR_BLUE,
Block.BLOCK_COLOR_VIOLET,Block.BLOCK_COLOR_ORANGE],10,500));
difficultyLevelArray.push(new DifficultyLevel(
[Block.BLOCK_COLOR_RED,Block.BLOCK_COLOR_GREEN,Block.BLOCK_COLOR_BLUE,
Block.BLOCK_COLOR_VIOLET,Block.BLOCK_COLOR_ORANGE,Block.BLOCK_COLOR_YELLOW],
10,500));
difficultyLevelArray.push(new DifficultyLevel(
[Block.BLOCK_COLOR_RED,Block.BLOCK_COLOR_GREEN,Block.BLOCK_COLOR_BLUE,
Block.BLOCK_COLOR_VIOLET,Block.BLOCK_COLOR_ORANGE,Block.BLOCK_COLOR_YELLOW,
Block.BLOCK_COLOR_PURPLE],10,500));
}
The newGame function is called from Main . For new game, we set level , score , and plays to 0.
That is all we need to do for a new game.
Search WWH ::




Custom Search