Graphics Reference
In-Depth Information
The GlobalRaceManager race manager script instance gets a call to StartRace(), too,
so that its management of the race states can get started:
void StartRace ()
{
// the SetPlayerLocks function tells all players to unlock
SetPlayerLocks( false );
// tell the global race manager that we are now racing
GlobalRaceManager.Instance.StartRace();
}
Called a few times by the script already in this section, the SetPlayerLocks() func-
tion tells players whether or not they should be locked in place. As discussed in Chapter
5, when the vehicle controller is outlined, locking the vehicles will constrain them along
their x - and z -axes but not on the y -axis. This is so that the vehicle will still be affected by
gravity; it can use its own suspension code, and the car will look natural at the beginning
of the game. If the vehicle's y -axis were locked too, the car would sit exactly at its start
position in the game world (which may be slightly above ground or perhaps too low) and
not in its natural resting spot against the ground.
In SetPlayerLocks(), all of the play scripts held in the playerList array are called on
with the SetLock() function to pass on the required lock state:
void SetPlayerLocks ( bool aState )
{
// tell all of the players to set their locks
for ( int i = 0; i < numberOfRacers; i++ )
{
thePlayerScript = ( CarController_MVD ) playerList
[i];
thePlayerScript.SetLock( aState );
}
}
UpdatePositions() asks the global race manager for the position of the first player
(since we know that the main player was added to the game before any of the others as it
was the top of the list). The focusPlayerRacePosition variable takes the return value of the
call:
void UpdatePositions()
{
// here we need to talk to the race controller to get what
// we need to display on screen
focusPlayerRacePosition=
GlobalRaceManager.Instance.GetPosition(1);
theLap is an integer. Here it is set to the return value from a call to the race manager
asking for how many laps player number 1 has completed. We also add an extra lap to this
return value, since we are looking to find out which lap the player is currently at, not how
many laps the player has completed:
theLap= GlobalRaceManager.Instance.GetLapsDone(1) +1;
Search WWH ::




Custom Search