Game Development Reference
In-Depth Information
Now, we need to create some variables to represent the Blocks that the player will be clicking in
the game. The clickedBlocksArray array will be used to hold the set of Blocks that we calculate
are the same color as the Block the player has clicked and are somehow connected to it.
board
is
a multidimensional array that will hold all the Blocks logically in their relative screen positions
(row,col). This will make it much easier to calculate where one block is in reference to other
blocks.
tempBlock
is an instance variable that we will use many times in the Game class. We
create it to save the overhead of creating it every time we use it.
private var clickedBlocksArray:Array;
private var board:Array;
private var tempBlock:Block;
The next set of variables are used with the game states for the state machine.
gameState
is the
current game state in
Game
.
nextGameState
is used with the
GameStates.STATE_WAIT
state to
define the game state to revert to once
GameStates.STATE_WAIT
is finished.
GameStates.STATE_WAIT
is a special state that we will use to pause the game for a few frames to
make the action smoother. Both
framesToWait
and
framesWaited
are used in conjunction with
GameStates.STATE_WAIT
.
private var gameState:int = 0;
private var nextGameState:int = 0;
private var framesToWait:int = 0;
private var framesWaited:int = 0;
Next, we will define a couple difficulty settings. We only have two of these in Color Drop, as we
are using a DifficultyLevel class for most of the other settings. However, these settings are
universal. The first, POINTS_PER_BLOCK is the number if points we will award the player per
block that is clicked and matched. The second, BONUS_POINTS_PER_BLOCK is the amount of
points we award the player for every successive block in the group they have clicked beyond the
first. This essentially gives them a quarter-point bonus for every block beyond the first one.
private static var BONUS_PER_BLOCK:Number = .25;
private static var POINTS_PER_BLOCK:Number = 1;
Finally, we define the
tileSheet
variable we will be using for this game.
//***** Flex *****
//[Embed(source = 'assets/colordropassets.swf', symbol = 'ColorSheet')]
//private var ColorSheet:Class;
//***** End Flex *****
private var tileSheet:TileSheet;
The constructor for this game is very similar to the constructor of the previous games. We accept
the game's
gameWidth
and
gameHeight
. We then set the
gameState
to
GameStates.
STATE_INITIALIZING
and call
init
to set up the variables. We set the
gameState
to make sure that
in the event that
runGame
is called by
Main
while initialize is being called. Remember, it's called in
the game timer loop in
Main
so we don't have control over it from
Game
;
Game
will know what to do.
public function ColorDrop(gW:int,gH:int) {
gameWidth=gW;
gameHeight=gH
init();
gameState = GameStates.STATE_INITIALIZING;
}