.ProcessGameplay LDA #0 \ Clear bit 7 of focusOnKeyAction to tell the game to STA focusOnKeyAction \ stop focusing effort on implementing any key actions \ such as landscape pans, as we are now looking at the \ gameplay STA uTurnStatus \ Clear bits 6 and 7 of uTurnStatus to clear any record \ of a U-turn being in progress, and to prevent the "U" \ key from performing a U-turn, so that the "U" key has \ to be released (if applicable) before a second U-turn \ can be performed .play1 LDA focusOnKeyAction \ If bit 7 of focusOnKeyAction is set then the game is BMI play5 \ focusing effort on a key action such as a landscape \ pan, so jump to play5 to go straight to processing any \ action key presses, skipping all the key press logic \ below \ We now check whether we have just finished processing \ a landscape pan, and if so whether the player is still \ holding down the same pan key LSR samePanKeyPress \ Clear bit 7 of samePanKeyPress to record that the same \ pan key is not being held down, which we will change \ below if this is not the case LDA previousFocus \ If bit 7 of previousFocus is clear then it matches BPL play2 \ the current value of focusOnKeyAction, so the value \ of focusOnKeyAction has not changed since the last \ time we were in the FocusOnKeyAction routine, and at \ that point we were not focusing effort on implementing \ a key action such as a landscape pan \ \ So jump to play2 to skip the following check for pan \ keys, as it isn't relevant \ If we get here then bit 7 of focusOnKeyAction is \ clear and bit 7 of previousFocus is set, so we must \ have called the ProcessGameplay routine just after \ implementing a key action such as a landscape pan \ \ So let's check to see whether the same pan key is \ still being held down from the pan we just finished JSR CheckForSamePanKey \ Check to see whether the same pan key is being held \ down compared to the last time we checked BNE play2 \ If the same pan key is not being held down, jump to \ play2 to skip the following SEC \ The same pan key is still being held down, so set bit ROR samePanKeyPress \ 7 of samePanKeyPress to record this fact for use in \ the CheckObjVisibility routine, so we can work out \ whether it is safe to update objects without \ corrupting any ongoing pans in the landscape view .play2 JSR ApplyEnemyTactics \ Apply tactics to the enemy object in enemyObject \ \ This call also moves enemyObject on to the next enemy \ object (in the range 0 to 7), so the next time we \ reach this point in the gameplay loop, this call will \ apply tactics to the next enemy number \ \ If there is no enemy object allocated to the object \ number (which may be the case if the landscape has \ fewer than eight enemies, or if an enemy has been \ absorbed), then no tactics are applied and the object \ number in enemyObject moves on by one, ready for the \ next time we reach this point in the gameplay loop \ \ So we process each enemy once every eight iterations \ of the gameplay loop, irrespective of the number of \ enemies in the landscape LDA sentinelHasWon \ If bit 7 of sentinelHasWon is clear then the player BEQ play4 \ has not been absorbed by the Sentinel, so jump to \ play4 to progress the game LDA #30 \ The Sentinel has won, so display the game over screen JSR ShowGameOverScreen \ with A = 30, so we decay the screen to black with a \ mass of 30 * 2400 = 72,000 randomly placed black dots .play3 JSR FocusOnKeyAction \ Tell the game to start focusing effort on the key \ action that has been initiated (be it a pan of the \ landscape view or an action like absorb or transfer) SEC \ Set the C flag to indicate that one of the following \ is true: \ \ * The Sentinel has won \ \ * The player has moved to a new tile \ \ * The player has pressed the quit game key \ \ so the main game loop can process this action RTS \ Return from the subroutine .play4 ASL playerHasMovedTile \ Shift bit 7 of playerHasMovedTile into the C flag so \ we can check it in the next instruction, and clear bit \ 7 to clear the flag as we are about to process any \ tile move that has occurred BCS play3 \ If the C flag is set then bit 7 of playerHasMovedTile \ was set before we cleared it, which indicates that the \ player has moved to a new tile, so jump to play3 to \ return from the subroutine with the C flag set BIT quitGame \ If bit 7 of quitGame is set then the player has BMI play3 \ pressed function key f1 to quit the game, so jump to \ play3 to return from the subroutine with the C flag \ set JSR GetPlayerDrain \ Calculate whether the player is being scanned by an \ enemy and whether the enemy can see the player's tile JSR ProcessPauseKeys \ Pause or unpause the game when COPY or DELETE are \ pressed JSR ProcessSound \ Process any sounds or music that are being made in the \ background JSR ProcessVolumeKeys \ Adjust the volume of the sound envelopes when the \ volume keys are pressed JMP play1 \ Jump back to play1 to repeat the main game loop .play5 LDA panKeyBeingPressed \ If no pan key is currently being pressed, jump to BMI play6 \ play6 to process any action key presses CLC \ Clear the C flag to indicate that we just finished a \ landscape pan and the player is still holding down a \ pan key, so the main game loop can process a new pan RTS \ Return from the subroutine .play6 LDA keyLogger+1 \ Set A to the key logger entry for "A", "Q", "R", "T", \ "B", "H", or "U" (absorb, transfer, create robot, \ create tree, create boulder, hyperspace, U-turn) BMI play9 \ If there is no key press in the key logger entry, jump \ back to the start of the routine via play9 to keep \ checking for key presses \ If we get here then the player is pressing "A", "Q", \ "R", "T", "B", "H" or "U" (absorb, transfer, create \ robot, create tree, create boulder, hyperspace, \ U-turn), so the possible values for A are: \ \ * 0 for key press "R" (Create robot) \ * 2 for key press "T" (Create tree) \ * 3 for key press "B" (Create boulder) \ * 32 for key press "A" (Absorb) \ * 33 for key press "Q" (Transfer) \ * 34 for key press "H" (Hyperspace) \ * 35 for key press "U" (U-turn) CMP #34 \ If A >= 34 then "H" (hyperspace) or "U" (U-turn) is BCS play7 \ being pressed, so jump to play7 to skip the following \ check, as we can hyperspace and U-turn at any point, \ irrespective of whether the sights are being shown BIT sightsAreVisible \ If bit 7 of sightsAreVisible is clear then the sights BPL play9 \ are not being shown, so jump back to the start of the \ routine via play9 to keep checking for key presses, as \ we can only create, absorb and transfer when the \ sights are visible \ If we get here then the sights are being shown, so we \ can process the key press .play7 STA keyPress \ Record the value from the key logger in keyPress, so \ we can refer to it in the call to ProcessActionKeys LSR activateSentinel \ The player has pressed a key that expends or absorbs \ energy, which activates the Sentinel at the very start \ of each level (the Sentinel and Sentries are inactive \ until this point, giving the player time to get their \ bearings when they first start a landscape) \ \ So clear bit 7 of activateSentinel to indicate that \ the Sentinel is activated and the game has started JSR ProcessActionKeys \ Process any key presses in key logger entry 1, which \ is where action key presses are stored (absorb, \ transfer, create, hyperspace, U-turn) BCS play8 \ If the call to ProcessActionKeys returned with the C \ flag set, then it didn't add or remove any objects, so \ jump to play8 to skip the following \ If we get here then the call to ProcessActionKeys \ added or removed an object, so we now need to make the \ appropriate sound and draw the updated object \ on-screen JSR FlushSoundBuffer0 \ Flush the sound channel 0 buffer LDA #2 \ Make sound #2 (create/absorb object white noise) JSR MakeSound LDA #%11000000 \ Set bits 6 and 7 of ditherObjectSights so we dither STA ditherObjectSights \ the updated object onto the screen (bit 6) and remove \ the sights before updating (bit 7) in the call to the \ DrawUpdatedObject routine LSR doNotDitherObject \ Clear bit 7 of doNotDitherObject to enable objects to \ be updated on the screen with a dithered effect JSR DrawUpdatedObject \ Draw the updated object (or the landscape where the \ object used to be) into the screen buffer and dither \ it onto the screen, pixel by pixel and randomly JSR FlushSoundBuffer0 \ Flush the sound channel 0 buffer JSR UpdateIconsScanner \ Update the icons in the top-left corner of the screen \ to show the player's current energy level and redraw \ the scanner box .play8 ASL playerHasMovedTile \ Shift bit 7 of playerHasMovedTile into the C flag so \ we can check it in the next instruction, and clear bit \ 7 to clear the flag as we are about to process any \ tile move that has occurred BCC play9 \ If bit 7 of playerHasMovedTile was clear before we \ cleared it, then the player has not moved to a new \ tile, so jump back to the start of the routine via \ play9 to continue processing the gameplay \ If we get here then bit 7 of playerHasMovedTile was \ set before we cleared it, which indicates that the \ player has moved to a new tile, so return from the \ subroutine with the C flag set RTS \ Return from the subroutine .play9 JMP ProcessGameplay \ Jump back to the start of the ProcessGameplay routine \ to keep processing the gameplayName: ProcessGameplay [Show more] Type: Subroutine Category: Gameplay Summary: A gameplay loop that processes all game key presses, returning to the main game loop when the player moves, quits, loses or pansContext: See this subroutine in context in the source code References: This subroutine is called as follows: * MainGameLoop calls ProcessGameplay
Returns: C flag Status flag on exit: * Clear if we have just finished processing a pan of the landscape view, and the player is still holding down a pan key * Set if any of the following are true: * The Sentinel has won * The player has moved to a new tile * The player has pressed the quit game key
[X]
Subroutine ApplyEnemyTactics (category: Gameplay)
Apply tactics to an enemy object, setting things up so the next call applies tactics to the next enemy object
[X]
Subroutine CheckForSamePanKey (category: Keyboard)
Check to see whether the same pan key is being held down compared to the last time we checked
[X]
Subroutine DrawUpdatedObject (category: Drawing objects)
Draw an updated object on-screen, optionally with a dithered effect, and with or without the surrounding landscape
[X]
Subroutine FlushSoundBuffer0 (category: Sound)
Flush the sound channel 0 buffer
[X]
Subroutine FocusOnKeyAction (category: Keyboard)
Tell the game to start focusing effort on the action that has been initiated, such as a pan of the landscape, absorb, transfer etc.
[X]
Subroutine GetPlayerDrain (category: Gameplay)
Calculate whether the player is being scanned by an enemy and whether the enemy can see the player's tile
[X]
Subroutine MakeSound (category: Sound)
Make a sound
[X]
Subroutine ProcessActionKeys (Part 1 of 2) (category: Keyboard)
Process an action key press from key logger entry 1 (absorb, transfer, create, hyperspace, U-turn)
[X]
Subroutine ProcessGameplay (category: Gameplay)
A gameplay loop that processes all game key presses, returning to the main game loop when the player moves, quits, loses or pans
[X]
Subroutine ProcessPauseKeys (category: Keyboard)
Pause or unpause the game when COPY or DELETE are pressed
[X]
Subroutine ProcessSound (category: Sound)
Process any sound effects that have been configured so they play in the background (this is called regularly throughout gameplay)
[X]
Subroutine ProcessVolumeKeys (category: Sound)
Adjust the volume of the sound envelopes when the volume keys are pressed
[X]
Subroutine ShowGameOverScreen (category: Title screen)
Display the game over screen
[X]
Subroutine UpdateIconsScanner (category: Scanner/energy row)
Update the icons in the top-left corner of the screen to show the player's current energy level and redraw the scanner box
[X]
Variable activateSentinel in workspace Main variable workspace
A flag to record when the Sentinel is activated at the start of the game (by the player pressing a key that expends or absorbs energy
[X]
Variable ditherObjectSights in workspace Main variable workspace
Configures how an updated object is drawn onto the screen in the DrawUpdatedObject routine
[X]
Variable doNotDitherObject in workspace Main variable workspace
Controls whether the DitherScreenBuffer routine can update an object on the screen using a dithered effect
[X]
Variable focusOnKeyAction in workspace Main variable workspace
A flag that determines whether the game should focus effort on implementing a key action, such as a pan of the landscape view
[X]
Variable keyLogger in workspace Main variable workspace
The four-byte key logger for logging game key presses
[X]
Variable keyPress in workspace Main variable workspace
The key logger value for a key press
[X]
Variable panKeyBeingPressed in workspace Zero page
The direction in which the player is currently panning
[X]
Label play1 is local to this routine
[X]
Label play2 is local to this routine
[X]
Label play3 is local to this routine
[X]
Label play4 is local to this routine
[X]
Label play5 is local to this routine
[X]
Label play6 is local to this routine
[X]
Label play7 is local to this routine
[X]
Label play8 is local to this routine
[X]
Label play9 is local to this routine
[X]
Variable playerHasMovedTile in workspace Main variable workspace
A flag to record whether the player has moved to a new tile by transferring or hyperspacing, so we can decide whether to regenerate the player's landscape view
[X]
Variable previousFocus in workspace Main variable workspace
The previous setting of focusOnKeyAction, so we can detect (in the ProcessGameplay routine) whether the player is still holding down a pan key after we finish scrolling the screen for the previous pan
[X]
Variable quitGame in workspace Main variable workspace
A flag to record whether the player has pressed function key f1 to quit the game
[X]
Variable samePanKeyPress in workspace Main variable workspace
Records whether the same pan key is being held down after we have just finished panning the landscape view
[X]
Variable sentinelHasWon in workspace Main variable workspace
A flag to record when the player runs out of energy (i.e. the energy level goes negative), at which point the Sentinel wins
[X]
Variable sightsAreVisible in workspace Main variable workspace
Controls whether the sights are being shown
[X]
Variable uTurnStatus in workspace Main variable workspace
A flag to record whether we are performing or have just performed a U-turn