Game Development Reference
In-Depth Information
m_pulse.addGameState(mask);
m_mask++;
}
In this method, we create a
ShipMaskClient
game state with a game state key
m_mask
and with a "Mask" prefix. The add operation may either succeed or fail
if another client has already successfully added it. The PulseClient callback
is implemented in the main class of the project; the
onNewGameState
and
onGameStateError
are simply redirected to this game screen class.
In either case, we call the following
assignShip
method:
private function assignShip(mask:ShipMaskClient,
error:Boolean):void {
if ( error ) {
requestShip();
}
else {
m_maskCount++;
if ( mask.getSenderId() == m_myId ) {
m_myMask = mask.getMaskId();
m_track.setShipMask(m_myMask,
m_pulse.getMyAvatar());
}
}
if ( m_maskCount == m_players.getPlayers().length ) {
m_track.startRace();
}
}
The error parameter will be
true
. In the case of an error, we will make another
request with the next mask value. If it was successful, there are two cases to handle.
First, if it was one's own add operation that succeeded, we assign the
m_myMask
property to the value and initialize the ship. The second case is that another player's
add operation succeeded. In either case, we increment the
m_maskCount
property.
Finally, start the race if the condition to start was satisfied, which is when
m_maskCount
is equal to the number of players in the room.