Tuesday 21 August 2007

Player and bots .. cont..


To give more exciting feeling to the game play, more bots are rendered. For this purpose, the track matrix data is taken from replay.cs which contains the position and rotation of the bot at the specific time. The following code (Source code 3‑2) shows how to extract the data.

Matrix bestReplayCarMatrix =

RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime(

RacingGameManager.Player.GameTimeMilliseconds / 1300.0f);

Source code 32: Matrix data used from best replay

Before rendering the car, the rotation of the car is created to make sure the car stay correctly on the road. (Refer Source code 3‑3):

bestReplayCarMatrix =

Matrix.CreateRotationX(MathHelper.Pi / 2.0f) *

Matrix.CreateRotationZ(MathHelper.Pi) *

bestReplayCarMatrix;

Source code 33: Rotate the car to stay correctly on the road.

Finally, the car is rendered with a specific texture, colour and matrix to the world. (Refer Source code 3‑4). Please noted that false in the code indicate the car is not a ghost car, therefore, it can be rendered with a texture and colours.

RacingGameManager.CarModel.RenderCar(

1, RacingGameManager.CarColors[5],

false, bestReplayCarMatrix);

Source code 34: Rendering the bot

To have more bots, the process is repeated but with unique matrix. This can be done by dividing each matrix with different variable, so that the bots is rendered at a point at different time.

each bot is given unique matrix:

Matrix bestReplayCarMatrix =

RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime(

RacingGameManager.Player.GameTimeMilliseconds / 1300.0f);

Matrix bestReplayCarMatrix2 =

RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime(

RacingGameManager.Player.GameTimeMilliseconds / 1200.0f);

Matrix bestReplayCarMatrix3 =

RacingGameManager.Landscape.BestReplay.GetCarMatrixAtTime(

RacingGameManager.Player.GameTimeMilliseconds / 1500.0f);

No comments: