Game Development Reference
In-Depth Information
When the game becomes active, we initialize the two control-
lers with the current position of each paddle and set the distance
threshold to include a small amount of area outside the circum-
ference of each paddle. This
area will allow for the inher-
ent imprecision of touch displays and give a margin of error, so
the player doesn
t have to have their finger directly on the center
of a paddle in order to move it. In the update loop, we adjust
each paddle
s position to match that of the position stored in the
controller. We also update the player positions inside of the
engine and call two additional methods. We
ll explore these in
depth later in this chapter, but for now, all you need to really
know is that the update function of the engine advances the phy-
sics simulation and the checkForCollisions method sees if the
puck has come into contact with either player
callbacks we looked at earlier are called and the game changes
state to GAME_SCORE.
private function onGameScoreEnter():void
::Entering Score State :: Player 1 -
, mPlayer1Score,
, mPlayer2Score );
private function onGameScoreUpdate( _dt:Number ):void
mEngine.update( _dt );
if (mOverlayClip.currentFrame == mOverlayClip.totalFrames )
removeChild( mOverlayClip );
mOverlayClip = null;
if ( mPlayer1Score == MAX_SCORE || mPlayer2Score ==
mStateMachine.gotoState( STATE_POST_GAME );
mStateMachine.gotoState( STATE_GAME_ACTIVE );
t really have anything
to do since the score callbacks handled all of the immediate logic.
I included it for posterity and with a trace for debugging purposes
so that you can see when the game changes state. Like the
PRE_GAME state, the update loop here checks to see if the score
The entrance function to this state doesn
Search Nedrilad ::

Custom Search