Game Development Reference
In-Depth Information
CustomEventClickBlock
: This is a custom event we will use to tell
ColorDrop
when a
Block
has been clicked.
GameStates
: This class holds all the static const values that we will use for our in-game
state machine for Color Drop.
Updating the Main class for Color Drop
Now, we will look at the
Main
class for
ColorDrop
. This class should look very familiar to you at
this point. It extends
GameFramework
and has the same specific code for
ColorDrop
as the other
games we have created thus far. The
major
changes in the code have to do with the
ScoreBoard
items and the sounds we will use in the game. The
ScoreBoard
will display the following items:
Main.SCORE_BOARD_SCORE
: The player's total game score
Main.SCORE_BOARD_LEVEL
: The current game level
Main.SCORE_BOARD_PLAYS
: The number of clicks the player has left.
Main.SCORE_BOARD_THRESHOLD
: The score the player must reach to finish the level
Main.SCORE_BOARD_LEVEL_SCORE
: The current accumulated score for this level
We already talked a bit about the sounds we will use in the game, but again, they are
SoundWin
,
SoundLose
,
SoundClick
, and
SoundBonus
, and they will be referenced as
Main.SOUND_WIN
,
Main.SOUND_LOSE
,
Main.SOUND_CLICK
,
Main.SOUND_BONUS
respectively from
ColorDrop
.
Here is the full code for
Main.as
; other changes (such as screens and title text) for
ColorDrop
are
highlighted in bold:
package com.efg.games.colordrop
{
import com.efg.framework.FrameWorkStates;
import com.efg.framework.GameFrameWork;
import com.efg.framework.BasicScreen;
import com.efg.framework.ScoreBoard;
import com.efg.framework.Game;
import com.efg.framework.SideBySideScoreElement;
import com.efg.framework.SoundManager;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextFormat;
public class Main extends GameFrameWork {
public static const SCORE_BOARD_SCORE:String = "score";
public static const SCORE_BOARD_LEVEL:String = "level";
public static const SCORE_BOARD_PLAYS:String = "plays";
public static const SCORE_BOARD_THRESHOLD:String = "threshold";
public static const SCORE_BOARD_LEVEL_SCORE:String = "levelScore";