Game Development Reference
In-Depth Information
The ShipMask class
We define the ShipMask game state to claim a mask for the ship. In this
implementation, the maskId could carry a value of 0 , 1 , or 2 . This game state is
added as a unique game state, so if a client is able to successfully add the state, then
it is said to have acquired the mask. The assignment of the mask is only done once
the race starts the first time.
The ShipPos class
The ship's position is broadcast by sending this game state as action to all the other
clients in the race. Each client will continually send the position of the ship from
within the main game loop once every 200 milliseconds, in other words, five times
a second. The property sid is the ship ID, which we set to the mask for the ship.
We will also send the current coordinates and the ship's current speed. The posX
property will carry the universe X coordinate of the ship and not the screen x.
The posY property will be the screen's y position.
The item class
The item class is used to synchronize the positions of all the asteroids. There are two
ways to lay out the asteroids. One way is to statically define the positions they will
be placed on the track in each quadrant, then every client simply loads them and
places them appropriately. This method does not need any synchronization among
clients. The second method is what the implementation does in which each asteroid
is placed in a random position. This presents two issues—first, the position of each
asteroid should be the same on each client, and this leads to the second issue that
only one client should succeed in announcing the initial position of an asteroid. More
than one client may succeed in announcing the initial positions, but for different
asteroids. So we will need to add this game state as a unique game state.
The ShipWin class
This game state is used to claim victory by a client finishing the race first. In a typical
server-based implementation, the server would be able to determine the winner. To
determine the winner without writing specific server programming, we will use the
unique game state technique to figure out the winner of the race.
Assigning ship color
We will use the ShipMask game state to manage the unique assignment of the ship's
mask. For a real game implementation, we would probably need to have the
players choose their ships' masks from a large selection.
 
Search WWH ::




Custom Search