Game Development Reference
In-Depth Information
We
'
ll now look at the methods we
'
ve defined for each state of the
game, breaking them into pairs.
private function onPreGameEnter():void
{
var overlayClass:Class = Class( getDefinitionByName(
OVERLAY_PRE_GAME_COUNTDOWN ) );
mOverlayClip = new overlayClass() as MovieClip;
addChild(mOverlayClip);
}
private function onPreGameUpdate( _dt:Number ):void
{
if (mOverlayClip.currentFrame == mOverlayClip.totalFrames)
{
removeChild( mOverlayClip );
mOverlayClip = null;
mStateMachine.gotoState( STATE_GAME_ACTIVE );
}
}
When the PRE_GAME state is entered, it creates an overlay for
the countdown clip, which has a simple animation play to its com-
pletion. In the update loop for this state, we simply check to see if
the animation is done playing. If it is, we remove the animation
and then head directly into the GAME_ACTIVE state.
private function onGameActiveEnter():void
{
clipTouchController1.init( this, new Point( clipPaddle1.x,
clipPaddle1.y ), clipPaddle1.height * 0.75 );
clipTouchController2.init( this, new Point( clipPaddle2.x,
clipPaddle2.y ), clipPaddle2.height * 0.75 );
}
private function onGameActiveUpdate( _dt:Number ):void
{
clipPaddle1.x = clipTouchController1.position.x;
clipPaddle1.y = clipTouchController1.position.y;
clipPaddle2.x = clipTouchController2.position.x;
clipPaddle2.y = clipTouchController2.position.y;
mEngine.setPlayer1Position( clipTouchController1.position.
x, clipTouchController1.position.y );
mEngine.setPlayer2Position( clipTouchController2.position.
x, clipTouchController2.position.y );
mEngine.update( _dt );
mEngine.checkForCollisions();
}
Search Nedrilad ::




Custom Search