.BuildPlayerCar LDX currentPlayer \ Set X to the driver number of the current player STX thisDriver \ Set thisDriver to the driver number of the current \ player STX objectNumber \ Set objectNumber to the driver number of the current \ player LDY playerSegmentIndex \ Build the car object for the current player using JSR BuildCarObjects \ the player's track segment from the track segment \ buffer, returning the car's 3D coordinates in xCoord2 LDX #2 \ We are about to copy the three axes of the resulting \ vectors, so set an axis counter in X .bpla1 LDA xCoord2Lo,X \ Copy the car's 3D coordinates from xCoord2 into STA xPlayerCoordHi,X \ xPlayerCoord LDA xCoord2Hi,X STA xPlayerCoordTop,X DEX \ Decrement the axis counter BPL bpla1 \ Loop back until we have copied all three axes LDA playerSegmentIndex \ Set A = playerSegmentIndex + 3 CLC \ ADC #3 \ to move on to the next track segment CMP #120 \ If A < 120, then we haven't reached the end of the BCC bpla2 \ track segment buffer, so jump to bpla2 to store the \ updated value LDA #0 \ We just reached the end of the track segment buffer, \ so set A = 0 to wrap round to the start .bpla2 TAY \ Set Y to the updated track segment index * 3 LDX thisDriver \ Set X to the driver number of the current player JSR BuildCarObjects \ Build the car object for the current player using the \ updated track segment, returning the object's yaw \ angle in objYawAngle LDA objYawAngleLo,X \ Copy the low byte of the yaw angle to playerYawAngleLo STA playerYawAngleLo LDA objYawAngleHi,X \ Copy the high byte of the yaw angle to EOR directionFacing \ playerYawAngleHi, flipping the sign of the STA playerYawAngleHi \ coordinate if we are facing backwards along the track RTS \ Return from the subroutineName: BuildPlayerCar [Show more] Type: Subroutine Category: 3D objects Summary: Build the objects for the player's carContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 1 of 5) calls BuildPlayerCar * PushCarOffTrack calls via BuildPlayerCar-1
Returns: xPlayerCoord The 3D coordinates of the player's car playerYawAngle The yaw angle of the player's car around the y-axis
Other entry points: BuildPlayerCar-1 Contains an RTS
[X]
Subroutine BuildCarObjects (Part 1 of 3) (category: 3D objects)
Calculate the 3D coordinate of the specified car
[X]
Label bpla1 is local to this routine
[X]
Label bpla2 is local to this routine
[X]
Variable currentPlayer in workspace Zero page
The number of the current player
[X]
Variable directionFacing in workspace Zero page
The direction that our car is facing
[X]
Variable objYawAngleHi in workspace Main variable workspace
High byte of each object's yaw angle
[X]
Variable objYawAngleLo in workspace Main variable workspace
Low byte of each object's yaw angle
[X]
Variable objectNumber in workspace Zero page
The object number of the four-part car we are drawing
[X]
Variable playerSegmentIndex in workspace Zero page
Used to store the index * 3 of the track segment containing the player's car in the track segment buffer
[X]
Variable playerYawAngleHi in workspace Zero page
High byte of the player's yaw angle
[X]
Variable playerYawAngleLo in workspace Zero page
Low byte of the player's yaw angle
[X]
Variable thisDriver in workspace Zero page
The number of the car we are currently drawing
[X]
Variable xCoord2Hi in workspace Main variable workspace
The high byte of the x-coordinate of the temporary coordinate variable (xCoord2, yCoord2, zCoord2)
[X]
Variable xCoord2Lo in workspace Main variable workspace
The low byte of the x-coordinate of the temporary coordinate variable (xCoord2, yCoord2, zCoord2)
[X]
Variable xPlayerCoordHi (category: Car geometry)
The high byte of the x-coordinate of the player's 3D coordinates
[X]
Variable xPlayerCoordTop (category: Car geometry)
The top byte of the x-coordinate of the player's 3D coordinates