Skip to navigation

Aviator on the BBC Micro

Main loop: MainLoop (Part 6 of 15)

Name: MainLoop (Part 6 of 15) [Show more] Type: Subroutine Category: Main loop Summary: Check whether any aliens have been hit Deep dive: Program flow of the main game loop
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.main7 LDA themeStatus \ If themeStatus is non-zero then either the Theme is BNE main12 \ not enabled, or it is enabled but we haven't yet added \ all eight aliens to the current wave, so jump to \ main12 as we only move aliens when the whole wave has \ arrived LDA firingStatus \ If firingStatus is zero then there are no bullets in BEQ main11 \ the air, so jump to main11, as we only need to check \ whether an alien is hit when there are bullets around LDA #33 \ We now loop through objects 33 down to 30, which are STA objectId \ all the alien objects, so we can check whether any of \ them have been hit, so set a loop counter in objectId .main8 LDY objectId \ Set Y to the object ID of the alien to check LDA alienStatus-30,Y \ We copied the object status bytes for all four alien BPL main9 \ objects into alienStatus in part 1, so this checks \ whether bit 7 of the alien's object status byte is \ clear \ \ If it is clear, then this object is not visible, so \ we skip the following three instructions and move on \ to the next alien, as we can't hit an alien that we \ can't see JSR CheckIfAlienIsHit \ This alien is visible, so check to see whether it has \ been hit, and if so, initiate the explosion LDA hitTimer \ If hitTimer is non-zero, then we just hit an alien, so BNE main10 \ jump to main10 to skip checking the rest of the aliens .main9 DEC objectId \ Decrement the loop counter to the next alien LDA objectId \ Loop back to check the next alien, until we have CMP #30 \ done all of them (from object 33 down to object 30) BCS main8 BCC main11 \ Jump to main11 (this BCC is effectively a JMP as we \ just passed through a BCS) .main10 STA distanceFromHit \ Store the value of hitTimer (which will be 27 as we \ just hit an alien) in distanceFromHit, so we are far \ enough away to avoid any turbulence, for now (as \ turbulence only kicks in when distanceFromHit < 16) LDA #0 \ Set firingStatus = 0 to indicate that there are no STA firingStatus \ longer any bullets are in the air, as they are now \ embedded in an unfortunate alien .main11 JSR UpdateAliens \ Update the aliens' statuses