Game Development Reference
In-Depth Information
public function Game()
{
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage,
false, 0, true );
}
private function onAddedToStage( _evt:Event ):void
{
// Create engine configuration and link it to stage display
objects
var config:AirHockeyEngineConfig = new AirHockeyEngineConfig();
config.mClipReference = this;
config.mPlayer1 = clipPaddle1;
config.mPlayer2 = clipPaddle2;
config.mPlayer1Goal = clipGoal1;
config.mPlayer2Goal = clipGoal2;
config.mPuck = clipPuck;
config.mPlayer1ScoreCallback = onPlayer1Score;
config.mPlayer2ScoreCallback = onPlayer2Score;
var boundaries:Vector. < DisplayObject > = new Vector.
< DisplayObject > ();
boundaries.push( clipWall1, clipWall2, clipWall3,
clipWall4, clipWall5, clipWall6 );
config.mBoundaryList = boundaries;
mEngine = new AirHockeyEngine( config );
// Set up state manager
mStateMachine = new FSMManager();
mStateMachine.addState( STATE_PRE_GAME, " AirHockeyState::
PreGame " , onPreGameEnter, onPreGameUpdate, null );
mStateMachine.addState( STATE_GAME_ACTIVE, " AirHockeyState::
GameActive " , onGameActiveEnter, onGameActiveUpdate, null );
mStateMachine.addState( STATE_GAME_SCORE, " AirHockeyState::
GameScore " , onGameScoreEnter, onGameScoreUpdate, null );
mStateMachine.addState( STATE_POST_GAME, " AirHockeyState::
PostGame " , onPostGameEnter, onPostGameUpdate, null );
mStateMachine.gotoState( STATE_PRE_GAME );
// Start the game loop
clipScoreDisplay1.gotoAndStop(1);
clipScoreDisplay2.gotoAndStop(1);
addEventListener( Event.ENTER_FRAME, onEnterFrame, false,
0, true );
}
private function onEnterFrame( _evt:Event ):void
{
mStateMachine.update( Time.deltaTime );
Search Nedrilad ::




Custom Search