Graphics Reference
In-Depth Information
}
public void ResetLapCount(int anID)
{
// if there's ever a need to restart the race and reset laps
// for this player, we reset its entry
// in the raceLaps hashtable here
raceLaps[anID]=0;
}
public int GetPosition ( int ofWhichID )
{
// first, let's make sure that we are ready to go (the
// hashtables may not have been set up yet, so it's
// best to be safe and check this first)
if(raceControllers==null)
{
Debug.Log ("GetPosition raceControllers is NULL!");
return -1;
}
if(raceControllers.ContainsKey(ofWhichID)==false)
{
Debug.Log ("GetPosition says no race controller
found for id "+ofWhichID);
return -1;
}
// first, we need to find the player that we're trying to
// calculate the position of
focusPlayerScript= (RaceController)
raceControllers[ofWhichID];
// start with the assumption that the player is in last
// place and work up
myPos = numberOfRacers;
// 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;
// grab a temporary reference to the 'other' player we want to
// check against
tempRC = (RaceController) raceControllers [b];
// 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;
if ( focusPlayerScript.GetID() != tempRC.GetID() )
{ // <-- make sure we're not trying to compare same objects!
// is the focussed player a lap ahead?
Search WWH ::




Custom Search