.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' statusesName: 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 loopContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Subroutine CheckIfAlienIsHit (Part 1 of 2) (category: The Theme)
Extract the alien's feeding stage, ready for the hit calculations in part 2
[X]
Subroutine UpdateAliens (Part 1 of 5) (category: The Theme)
Update the aliens so they progress through their feeding or attack cycles
[X]
Variable alienStatus (category: The Theme)
Storage for the object status bytes for the four alien objects
[X]
Variable distanceFromHit (category: The Theme)
The distance from the alien we just hit, so we can work out whether we get hit by turbulence
[X]
Variable firingStatus in workspace Main variable workspace
Firing status
[X]
Variable hitTimer (category: The Theme)
The time since we hit an alien, so we can time its explosion
[X]
Label main10 is local to this routine
[X]
Label main11 is local to this routine
[X]
Label main12 in subroutine MainLoop (Part 7 of 15)
[X]
Label main8 is local to this routine
[X]
Label main9 is local to this routine
[X]
Variable objectId in workspace Main variable workspace
Temporary storage for an object ID (0 to 39)
[X]
Variable themeStatus in workspace Main variable workspace
Theme status