Game Development Reference
In-Depth Information
var scoreBoardTextFormat1:TextFormat = new TextFormat("_sans", "11", "0xffffff", "true");
var scoreBoardTextFormat2:TextFormat = new TextFormat("_sans", "11", "0xff0000", "true");
var scoreBoardTextFormat3:TextFormat = new TextFormat("_sans", "14", "0xffffff", "true");
var scoreBoardTextFormat4:TextFormat = new TextFormat("_sans", "14", "0xff0000", "true");
var scoreBoardTextFormat5:TextFormat = new TextFormat("_sans", "10", "0xffffff", "true");
var scoreBoardTextFormat6:TextFormat = new TextFormat("_sans", "25", "0x00ff00", "true");
var scoreBoardTextFormat7:TextFormat = new TextFormat("_sans", "25", "0xff0000", "true");
scoreBoard.createTextElement(SCORE_BOARD_SCORE, new SideBySideScoreElement(
75, 5, 15, "Score:",scoreBoardTextFormat1, 25, "0", scoreBoardTextFormat2));
scoreBoard.createTextElement(SCORE_BOARD_LEVEL,new SideBySideScoreElement(
325, 5, 10, "Level:", scoreBoardTextFormat1, 50, "0",scoreBoardTextFormat2));
scoreBoard.createTextElement(SCORE_BOARD_TURN, new SideBySideScoreElement(
250, 380, 10, "Turn:", scoreBoardTextFormat3, 50, "0", scoreBoardTextFormat4));
scoreBoard.createTextElement(SCORE_BOARD_PLAYER_LIFE, new SideBySideScoreElement(
25, 150, 10, "Life:",scoreBoardTextFormat5, 20, "0",scoreBoardTextFormat6));
scoreBoard.createTextElement(SCORE_BOARD_COMPUTER_LIFE, new SideBySideScoreElement(
480, 150, 10, "Life:",scoreBoardTextFormat5, 20, "0", scoreBoardTextFormat7));
Playing SoundTracks
Recall that, back in Chapter 4, we created the SoundManager class with the ability to play a
soundtrack (background music). Many games in the battle puzzle genre like Dice Battle contain
elaborate soundtracks that change to set the mood of the current state of the game. However,
managing the play back of these different soundtracks can be quite a trick when you are using a
state machine to run your game.
We have two different soundtracks represented by the static constants of SOUND_SOUND_TRACK_1
and SOUND_SOUND_TRACK_2 in Main :
public static const SOUND_SOUND_TRACK_1:String = "soundTrack1";
public static const SOUND_SOUND_TRACK_2:String = "soundTrack2";
...
soundManager.addSound(SOUND_SOUND_TRACK_1,new SoundTrack1());
soundManager.addSound(SOUND_SOUND_TRACK_2,new SoundTrack2());
We are going to play these soundtracks in different states of the game; see Table 9-2.
Table 9-2. Soundtracks for Main.as
State Function
State Description
Soundtrack to Play
systemTitle
SoundTrack1
Title screen shows
systemNewGame
SoundTrack2
New game starts
systemGameOver
SoundTrack2
Game over
systemTitle
SoundTrack1
Title screen shows
Search WWH ::




Custom Search