Game Development Reference
In-Depth Information
var item:Item = quadrant.onAddItem(ic);
if ( quadrant.isLoaded() ) {
addChild(item);
}
}
If the quadrant is not loaded in the client that receives the notification, we wait until it
is loaded and add all the items belonging to the quadrant are loaded at once onto the
screen. For the first two quadrants, all clients will attempt to add items to the server.
Even if more than one client gets into the add items loop, the unique game state key
will prevent the same two items from being added. For subsequent quadrants, the
client who is leading the race will succeed in adding the items for the new quadrants.
Ship prediction and interpolation
We will now see how we render other ships (remote) on our screen. At the beginning
of the race, we will see all other players' ships, and as the game progresses, some
may race ahead while others may slow down because they hit an asteroid. Other
players' ships will be visible only if they are close to the ship that is being driven by
the player. In this implementation, the ship's position is broadcast
to every other player at the rate of five times per second.
The following is code snippet that sends up the position update for the ship:
private const TIMER_LEN_MILLI:int = 10;
private const NET_UPDATE_FREQ:int = 200;
private function gameLoop(event:TimerEvent):void {
m_lastNetUpdate += TIMER_LEN_MILLI;
if ( m_lastNetUpdate > NET_UPDATE_FREQ ) {
m_lastNetUpdate = 0;
var u:ShipPosClient;
u = new ShipPosClient();
u.setSid(m_mask);
u.setPosX(m_ship.getCoord());
u.setPosY(m_ship.y);
u.setSpeed(m_ship.getSpeed());
m_pulse.sendGameStateAction(u);
}
// update remote ships
var remotes:Array;
remotes = m_ships.values();
var s:SpaceShip;
 
Search WWH ::




Custom Search