Skip to navigation

Revs on the BBC Micro

3D objects: BuildPlayerCar

Name: BuildPlayerCar [Show more] Type: Subroutine Category: 3D objects Summary: Build the objects for the player's car
Context: 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
.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 subroutine