.MoveAndDrawCars LDA qualifyingTime \ If bit 7 of qualifyingTime is set then this is a BMI Delay \ practice lap (i.e. qualifyingTime = 255), so there are \ no other cars to draw \ \ To maintain the same game speed as for races, we jump \ to Delay to pause for a while before returning from \ the subroutine using a tail call LDX positionBehind \ Set X to the position of the driver behind us LDY driversInOrder,X \ Set Y to the number of the driver in behind us LDA objectStatus,Y \ Clear bit 7 of the car object's status byte, to flag AND #%01111111 \ the car behind us as being visible STA objectStatus,Y JSR MoveCars \ Move the cars around the track JSR ProcessOvertaking \ Process overtaking manoeuvres for the non-player \ drivers JSR HideAllCars \ Set all the cars to be hidden JSR SetPlayerPositions \ Set the current player's position, plus the position \ ahead and the position behind LDX currentPosition \ Set X to the current player's position LDY #5 \ We now work our way through the five nearest cars in \ front of us, so set a loop counter in Y .dcar1 BIT directionFacing \ If bit 7 of directionFacing is clear, then we are BPL dcar2 \ facing forwards, so jump to dcar2 JSR GetPositionBehind \ We are facing backwards, so set X to the number of \ the position behind position X, to get the number of \ the car that we are looking at JMP dcar3 \ Jump to dcar3 to skip the following .dcar2 JSR GetPositionAhead \ We are facing forwards, so set X to the number of the \ position ahead of position X, to get the number of \ the car that we are looking at .dcar3 STY thisDriverNumber \ Store the loop counter in thisDriverNumber so we can \ retrieve it after the following call STX thisPosition \ Store the position of the car we are considering in \ thisPosition JSR BuildVisibleCar \ Build the car object if it is visible, so we can draw \ it below LDX thisPosition \ Retrieve the position of the car that we stored in \ thisPosition above LDY thisDriverNumber \ Retrieve the value of the loop counter that we stored \ in thisDriverNumber above DEY \ Decrement the loop counter BPL dcar1 \ Loop back until we have processed five cars in front JSR DrawCars \ Draw all the cars, with the closest car in front of us \ split into four objects LDX positionBehind \ Set X to the position of the driver behind us JSR BuildVisibleCar \ Build the car object if it is visible, so it can be \ shown in the mirror if close enough RTS \ Return from the subroutineName: MoveAndDrawCars [Show more] Type: Subroutine Category: Car geometry Summary: Move the cars around the track and draw any that are visible, up to a maximum of fiveContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls MoveAndDrawCars
[X]
Subroutine BuildVisibleCar (category: 3D objects)
Check the distance to the specified car and build the car object if it is close enough
[X]
Subroutine Delay (category: Main loop)
Delay for a specified number of loops
[X]
Subroutine DrawCars (category: Drawing objects)
Draw all the car objects, with four objects for the closest car in front of us
[X]
Subroutine GetPositionAhead (category: Drivers)
Decrement X to the previous position number (from 19 to 0 and round again), which gives the position ahead of X
[X]
Subroutine GetPositionBehind (category: Drivers)
Increment X to the next position number (from 0 to 19 and round again), which gives the position behind X
[X]
Subroutine HideAllCars (category: Car geometry)
Set all the cars to hidden
[X]
Subroutine MoveCars (Part 1 of 2) (category: Car geometry)
Move the cars around the track
[X]
Subroutine ProcessOvertaking (Part 1 of 3) (category: Tactics)
Process all cars for overtaking manoeuvres, checking first to see if the car has just finished overtaking the car in front
[X]
Subroutine SetPlayerPositions (category: Drivers)
Set the current player's position, plus the positions behind and in front
[X]
Variable currentPosition in workspace Zero page
The position of the current player
[X]
Label dcar1 is local to this routine
[X]
Label dcar2 is local to this routine
[X]
Label dcar3 is local to this routine
[X]
Variable directionFacing in workspace Zero page
The direction that our car is facing
[X]
Variable driversInOrder in workspace Stack variables
A list of driver numbers in order
[X]
Variable objectStatus in workspace Stack variables
Various status flags for each object
[X]
Variable positionBehind in workspace Zero page
The number of the position behind the current player's position
[X]
Variable qualifyingTime (category: Drivers)
The number of minutes of qualifying lap time
[X]
Variable thisDriverNumber (category: Drawing objects)
The number of the current driver when drawing cars
[X]
Variable thisPosition in workspace Zero page
The position of the car that we are analysing in the MoveAndDrawCars routine