Skip to navigation

Aviator on the BBC Micro

The Theme: UpdateBullets

Name: UpdateBullets [Show more] Type: Subroutine Category: The Theme Summary: Move the bullets through the air
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 3 of 15) calls UpdateBullets

This is called UBUL in the original source code.
.UpdateBullets LDY #15 \ The bullets are made up of objects 12 to 15, so set a STY objectId \ counter in objectId to count through all four LDA #98 \ Objects 12 to 15 are made up of points 95 to 98, so STA GG \ set a counter in GG to count through all four .ubul1 TYA \ Set X = Y + 216 CLC \ ADC #216 \ so X will be 228 to 231 for objects 12 to 15, which is TAX \ the ID of each bullet object's velocity vector, as set \ up in the FireGuns routine JSR AddPointToObject \ Add the vector in point X to the object coordinates \ for object Y (in other words, add the velocity vector \ to object Y's coordinates, which moves the bullet in \ space by the correct amount) LDA #0 \ Set showLine = 0 as a starting point for the line's STA showLine \ visibility (so we start out by assuming the line is \ visible, and change this in the following call to \ SetObjectCoords if we find that it isn't) JSR SetObjectCoords \ Calculate the object's coordinates and visibilty, \ updating the object's status byte with the results BPL ubul2 \ If bit 7 of the object's updated status byte is clear, \ then the bullets have hit the ground, so jump to ubul2 \ to remove the bullets LDY GG \ Set Y to the point ID that we're checking LDX #60 \ Set X to line ID 60 for the call to CheckLineDistance JSR CheckLineDistance \ Check whether point GG on line 60 is within the \ visible distance for the line BEQ ubul3 \ If the result is 0, then the point is visible, so \ jump to ubul3 to move onto the next bullet point .ubul2 \ If we get here then this bullet point has either hit \ the ground, or it is too far away to be seen any more, \ so it's time to remove the bullets LDA #0 \ Set firingStatus = 0 to indicate that there are no STA firingStatus \ bullets are in the air .ubul3 DEC GG \ Decrement the point counter to move on to the next \ point from 98 down to 95 DEC objectId \ Decrement the object counter to move on to the next \ object from 15 down to 12 LDY objectId \ Loop back until we have processed all four objects CPY #12 \ and points BCS ubul1 RTS \ Return from the subroutine