Skip to navigation

Drawing objects: DrawCars

Name: DrawCars [Show more] Type: Subroutine Category: Drawing objects Summary: Draw all the car objects, with four objects for the closest car in front of us
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MoveAndDrawCars calls DrawCars
.DrawCars LDX currentPosition \ Set X to the current player's position, so we work our \ way backwards through the pack, starting with the car \ behind the current player, and wrapping round to the \ cars in front, working our way towards the player's \ car in the order in which they should be drawn (with \ distant cars first) BPL cars2 \ If X is positive, jump to cars2 to skip the following \ instruction .cars1 JSR DrawCarInPosition \ Draw the car in position X .cars2 JSR GetPositionBehind \ Set X to the number of the position behind position X, \ so we work our way back through the pack CPX positionAhead \ Loop back to cars1 until we have reached the position BNE cars1 \ ahead of the current player \ We now draw the car that's just in front of us, which \ is made up of four objects that can be skewed to make \ it look like the car is steering LDX #22 \ The four objects are the front tyres, body, rear tyres \ and rear wing, so set up a counter in X to work \ through the first three in the order 22, 21 and 20, to \ pass to DrawCarOrSign in turn so they get drawn in \ that order: front tyres, body/helmet and rear tyres .cars3 STX xStoreDraw \ Store X in xStoreDraw so it gets preserved through \ the call to DrawCarOrSign JSR DrawCarOrSign \ Draw the specified part of the four-object car just \ in front of us DEX \ Decrement the object counter CPX #20 \ Loop back until we have drawn all three objects BCS cars3 LDX positionAhead \ Set X to the position ahead of the current player JSR DrawCarInPosition \ Draw the car in position X, which draws the rear wing \ as the last (and closest) of the four objects RTS \ Return from the subroutine