Graphics Reference
In-Depth Information
The first step is to grab the RaceController script instance for the player ID held by
of WhichID, from the Hashtable raceControllers. The resulting RaceController instance
will be held by focusPlayerScript. The waypoint and position of the vehicle belonging to
focusPlayerScript will be compared to the other racers to calculate race position:
// first, we need to find the player that we're trying to
// calculate the position of
focusPlayerScript= (RaceController)
raceControllers[ofWhichID];
myPos is an integer that starts out set to the value of the variable numberOfRacers
and will be decremented based on how close the race controller script reports the player
is along the track:
// start with the assumption that the player is in last
// place and work up
myPos = numberOfRacers;
A loop (b) goes from 1 to the value of numberOfRacers. The value of b will be used to
retrieve RaceController references from the raceController Hashtable. At the start of the
position calculations, we assume that the main player (focusPlayerScript) is not ahead of
any other car, so the Boolean isAhead is set to false:
// now we step through each racer and check their positions to
// determine whether or not our focussed player is in front of them
// or not
for ( int b = 1; b <= numberOfRacers; b++ )
{
// assume that we are behind this player
isAhead = false;
focusPlayerScript is the main player we are interested in (based on the ID passed
in as a parameter), and it is the vehicle that will be compared to all the other vehicles
in this main section of the function to find out whether the player is ahead of the other
players or not. Here tempRC is populated with a reference to a RaceController script
from another player that will be compared to the main player using the loop's variable b
as its ID:
// grab a temporary reference to the 'other' player we want to
// check against
tempRC = (RaceController) raceControllers [b];
To keep the function safe, tempRC is null checked just in case one of the players has
somehow been removed from the game. If it is null, the continue command will move
on to the next iteration of the loop without continuing to execute the rest of the code in
subsequent lines:
// if car 2 happens to be null (deleted for example)
// here's a little safety to skip this iteration in
// the loop
if(tempRC==null)
continue;
Search WWH ::




Custom Search