Game Development Reference
In-Depth Information
In the current implementation, we will simply assign the mask in the order the
server receives the request and each client requests the mask starting from 0. The
implementation only has three masks defined, but it should be straightforward to
create more masks and have the player choose a mask of his or her choice rather
than having one assigned to them.
Let's now visit the familiar game ( Game.as ) screen class, which is subclassed from
the PulseUI framework. Let's see the parts of the code that get the ship's mask.
We make use of the following class properties to implement getting the mask for
the ship:
private var m_mask:int=0;
private var m_myMask:int;
private var m_maskCount:int=0;
The m_mask property is the current mask that the client will attempt to get assigned.
The m_myMask property is the successful mask value for the ship. Lastly, the
m_maskCount property is the number of assignments that have been currently made.
When the assignments are equal to the number of clients in the room, the game
host will start the race.
public override function startGame():void {
if ( m_firstTime ) {
super.startGame();
requestShip();
m_firstTime = false;
addChild(m_track);
}
else {
addChild(m_track);
m_track.startRace();
}
}
When the game host starts the game, before the actual race begins, we first assign the
mask. Note that we only make the mask assignment once; the same masked ship will
be used for all the races within the room.
The requestShip method is listed below:
private function requestShip() :void {
var mask:ShipMaskClient;
mask = new ShipMaskClient();
mask.setMaskId(m_mask);
mask.setStateKey("Mask-" + m_mask);
 
Search WWH ::




Custom Search