Game Development Reference
In-Depth Information
Figure 8-4.
Clicking a colored block and selecting all similarly colored blocks touching it
The first thing we do in
blockClickListener
is test to see if we actually are in the
GameStates.STATE_WAITING_FOR_INPUT
game state. If so, we drop into the main part of the
function and dispatch
CustomEventSound.PLAY_SOUND
event to play
Main.SOUND_CLICK
. This will to
give the user audio feedback for each click of the mouse.
Next, we retrieve the reference to the
Block
that was clicked (
e.block
) and put it into
tempBlock
.
We then fill
clickedBlockArray
by calling
findLikeColoredBlocks
and passing
tempBlock
as the
lone parameter. We will discuss this function in moment, but first, we'll finish the last few lines of
this function.
We then set all the necessary variables to create a
GameStates.STATE_WAIT
state (
framesToWait
= 15
,
framesWaited = 0
, and
nextGameState = GameStates.
STATE_REMOVE_CLICKED_BLOCKS
), decrement the
plays
variable (because the player just made a
play by clicking on a block) and set the
gameState
to
GameStates.STATE_WAIT
. This wait time of 15
frames will give the game a dramatic pause between when the user clicks a
Block
, the blocks that
match lighting up with a glow filter, and all the
Block
objects being removed from the screen in
GameStates.STATE_REMOVE_CLICKED_BLOCKS
.
public function blockClickListener(e:CustomEventClickBlock):void {
if (gameState==GameStates.STATE_WAITING_FOR_INPUT) {
dispatchEvent( new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_CLICK,false,1,0,1));
tempBlock = e.block;
clickedBlocksArray =
findLikeColoredBlocks(tempBlock);