Game Development Reference
In-Depth Information
m_trackPosX = m_rc+(m_speed*totalLag);
}
The interpolation of points between the network updates is taken care of by the main
loop calling the following method on all the remote ship object instances:
public function updateRemote(myShipX:Number,
myShipCoord:Number):void {
m_trackPosX += m_speed;
if ( Math.abs(m_ry-y) > 1 ) {
if ( m_ry < y )
y -= m_vt;
else
y += m_vt;
}
x = myShipX + (m_trackPosX-myShipCoord);
}
We will observe some jerkiness even when all the clients and the server are in the
same LAN. Because the lag information is only an approximation, when the update
is received, we update it to the new predicted point, which could be off by a factor.
Moreover, if the ship makes sudden changes in speed, this will also add to the
jerkiness of the remote ship rendering.
Winning the race
Winning the race is determined in the main game loop when we find that there are
no more quadrants to load. At this point, we will attempt to add a unique game state,
ShipWin . It could be that more than one client sent this message at the same instant;
however, the server will only process the first game state and rejects any subsequent
game state add operation. This ensures there is only one clear winner of the race.
Once the race is won by a player, we display the win or lose sprite on all players'
screens, and after a brief period, we resume the race again.
The following are the steps that will take players to the next race:
1.
When a client receives the ShipWin game state, depending on the sender,
we display either the win sprite or the lose sprite. Calling finishGame API
is important as it cleans up all the game states accumulated from the race,
including the unique game states.
public function onWin(win:ShipWinClient):void {
if ( win.getSenderId() == m_myId ) {
displayResult(true);
}
 
Search WWH ::




Custom Search