Skip to navigation

Main game loop: MainGameLoop (Part 2 of 2)

Name: MainGameLoop (Part 2 of 2) [Show more] Type: Subroutine Category: Main game loop Summary: Progress gameplay as part of the main game loop Deep dive: Program flow of the main game loop Panning and hardware scrolling The crosshair sights
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.game7 \ If we get here then the game is still in progress, so \ we progress the gameplay JSR ProcessGameplay \ Run the gameplay loop that processes all game key \ presses, returning here when the player moves, quits, \ loses or pans BCC game8 \ The ProcessGameplay routine will return with the \ C flag clear if the player is holding down a pan key, \ in which case jump to game8 to process the pan JMP MainGameLoop \ Otherwise the ProcessGameplay routine returned because \ one of the following is true: \ \ * The Sentinel has won \ \ * The player has moved to a new tile \ \ * The player has performed a U-turn \ \ * The player has pressed the quit game key \ \ so jump to MainGameLoop to process these actions .game8 \ If we get here then the player is holding down a pan \ key and wants to pan the screen, so we need to process \ the pan LDA panKeyBeingPressed \ Update lastPanKeyPressed with the details of the pan STA lastPanKeyPressed \ key being pressed, so we can check later on whether it \ is still being held down LDA #0 \ Set numberOfScrolls = 0 to reset the scroll counter STA numberOfScrolls \ so the interrupt handler will not scroll the screen \ while we set up the new pan STA doNotDitherObject \ Clear bit 7 of doNotDitherObject to enable objects to \ be updated on the screen with a dithered effect BIT sightsAreVisible \ If bit 7 of sightsAreVisible is set then the sights BMI game9 \ are being shown, so jump to game9 to skip the \ following two instructions \ \ This ensures that when we pan the screen as a result \ of the sights moving off the edge of the screen, the \ panning process completes and doesn't get aborted if \ the player releases the pan key SEC \ The sights are not visible so we are panning the ROR keepCheckingPanKey \ screen because the player has pressed a pan key, so \ set bit 7 of keepCheckingPanKey so DrawLandscapeView \ will abort the drawing process if the player releases \ the pan key before the drawing process has finished .game9 JSR PanLandscapeView \ Draw the new part of the landscape view required for \ the screen pan, and if it completes (i.e. if the \ player keeps holding the pan key throughout the whole \ drawing process), then set up the following: \ \ * Set numberOfScrolls to the correct number of \ scrolls required for the pan (8 or 16) \ \ * Set screenBufferAddr(1 0) to the address where the \ interrupt handler should start fetching new \ content to scroll onto the screen \ \ The scrolling won't start yet, but it will be done in \ the background during the loop at game10 below, after \ being triggered by setting scrollCounter to the \ non-zero value in numberOfScrolls \ \ If the player releases the pan key before the drawing \ process has been finished, numberOfScrolls will be \ left at zero and the scrolling process will never be \ triggered LSR keepCheckingPanKey \ Clear bit 7 of keepCheckingPanKey so DrawLandscapeView \ will keep drawing the landscape irrespective of the \ pan keys being held down (so this takes the routine \ back to its default behaviour) 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 \ \ We call this to ensure that the icon screen buffer is \ updated with the correct content for the top row, so \ it can be refreshed after every scrolling step in the \ interrupt routine LDA numberOfScrolls \ Set scrollCounter to the number of scrolls required, STA scrollCounter \ so the interrupt handler will scroll the screen by \ this many steps in the background .game10 LDA scrollCounter \ Loop around until scrollCounter is zero, so this waits BNE game10 \ until the interrupt handler has finished scrolling the \ landscape view, thus implementing the pan on-screen BEQ game7 \ Jump back to the start of part 2 to continue with \ progressing the gameplay (this BEQ is effectively a \ JMP as we just passed through a BNE)