Skip to navigation

Drawing the landscape: PanLandscapeView

Name: PanLandscapeView [Show more] Type: Subroutine Category: Drawing the landscape Summary: Pan the landscape and update the landscape view
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainGameLoop calls PanLandscapeView

Arguments: viewingObject The number of the object that is viewing the landscape (this is always the player object for this routine)
.PanLandscapeView LDY lastPanKeyPressed \ Set Y to the direction of the last pan key that was \ pressed (which may not still be held down) \ \ So this contains the direction of any scrolling that \ we need to apply to the landscape, as follows: \ \ * 0 = pan right \ \ * 1 = pan left \ \ * 2 = pan up \ \ * 3 = pan down \ \ We use this as an index into various tables, to look \ up the correct values for the direction in which we \ want to scroll LDX viewingObject \ Set X to the object number of the viewer, which we set \ to the player object in MainGameLoop CPY #2 \ If the panning direction in Y is up or down, jump to BCS lpan3 \ lpan3 to pan vertically \ If we get here then Y is 0 or 1 and the panning \ direction is right or left LDA objectYawAngle,X \ Rotate the player's gaze so that when we draw the CLC \ updated view, the new part of the landscape that we ADC panAngleToUpdate,Y \ need to scroll in from the side goes into the screen STA objectYawAngle,X \ buffer (as the screen buffer is mapped to the left \ portion of the view that we are drawing) LDA #25 \ Set A = 25 to pass to FillScreen, so we fill the \ screen buffer (as opposed to screen memory) LDY #24 \ Set Y = 24 to pass to FillScreen, so we fill 24 \ character rows of the screen buffer LDX #16 \ Set X = 16 to pass to FillScreen, so we fill 16 \ character columns in the screen buffer STX bufferColumns \ Set bufferColumns to 16 so we can refer to the buffer \ width during the drawing process JSR FillScreen \ Call FillScreen to fill the screen buffer with the \ background specified in screenBackground \ \ screenBackground variable is zeroed in DrawTitleView \ before the gameplay starts, so all calls to the \ FillScreen routine during gameplay fill the buffer \ with alternating colour 0/1 (blue/black) pixel rows, \ for the sky JSR UseColumnBuffer \ Configure the column buffer for use so we draw the \ updated part of the landscape view into the correct \ buffer type for a left or right pan JSR DrawLandscapeView \ Draw the landscape view into the screen buffer \ \ If the player held down the panning key throughout the \ drawing process and the whole landscape was drawn, \ then the C flag will be clear, otherwise the C flag \ will be set LDX viewingObject \ Set X to the object number of the viewer, which we set \ to the player object in MainGameLoop LDY lastPanKeyPressed \ Set Y to the direction of the last pan key that was \ pressed (which may not still be held down) BCS lpan2 \ If the call to DrawLandscapeView set the C flag then \ the landscape drawing process was aborted, so jump to \ lpan2 to revert the change to the player's yaw angle \ and return from the subroutine without updating the \ on-screen landscape view BNE lpan1 \ If Y <> 0 then Y must be 1, in which case the pan \ angle we fetched from the panAngleToUpdate table \ doesn't need correcting, so jump to lpan1 to skip the \ following \ If we get here then Y = 0, so we added 20 to the \ player's yaw angle so it would draw the new part of \ the view into the screen buffer, so we now need to \ subtract 12 from the player's yaw angle so they end up \ looking in the correct direction, i.e. a net rotation \ of +8 rather than +20 yaw angles LDA objectYawAngle,X \ Subtract 12 from the player's yaw angle SEC SBC #12 STA objectYawAngle,X .lpan1 LDA #16 \ We now need to scroll the contents of the screen JSR StartScrollingView \ buffer into the side of the on-screen landscape view, \ so call StartScrollingView to configure a background \ task to scroll 16 character columns from the screen \ buffer onto the screen, using the interrupt handler \ to do it in the background RTS \ Return from the subroutine .lpan2 \ If we get here then the panning process was aborted \ before the landscape was drawn LDA objectYawAngle,X \ Reverse the rotation that we applied to the player's SEC \ yaw angle for the pan, so this puts it back to the SBC panAngleToUpdate,Y \ value it had before we started the panning process STA objectYawAngle,X RTS \ Return from the subroutine .lpan3 \ If we get here then Y is 2 or 3 and the panning \ direction is up or down LDA objectPitchAngle,X \ If the player's pitch angle is equal to either CMP highestPitchAngle-2,Y \ highestPitchAngle (if we are panning up) or BEQ lpan6 \ lowestPitchAngle (if we are panning down) then the \ player is already pitched as far back or down as \ possible, so jump to lpan6 to return from the \ subroutine without panning the landscape view, as \ we can't pan any further CLC \ Rotate the player's gaze so that when we draw the ADC panAngleToUpdate,Y \ updated view, the new part of the landscape that we STA objectPitchAngle,X \ need to scroll in from above or below goes into the \ screen buffer (as the screen buffer is mapped to the \ top portion of the view that we are drawing) LDA #25 \ Set A = 25 to pass to FillScreen, so we fill the \ screen buffer (as opposed to screen memory) LDY #8 \ Set Y = 8 to pass to FillScreen, so we fill 8 \ character rows of the screen buffer LDX #40 \ Set X = 40 to pass to FillScreen, so we fill 40 \ character columns in the screen buffer STX bufferColumns \ Set bufferColumns to 40 so we can refer to the buffer \ width during the drawing process JSR FillScreen \ Call FillScreen to fill the screen buffer with the \ background specified in screenBackground \ \ screenBackground variable is zeroed in DrawTitleView \ before the gameplay starts, so all calls to the \ FillScreen routine during gameplay fill the buffer \ with alternating colour 0/1 (blue/black) pixel rows, \ for the sky JSR UseRowBuffer \ Configure the row buffer for use so we draw the \ updated part of the landscape view into the correct \ buffer type for an up or down pan JSR DrawLandscapeView \ Draw the landscape view into the screen buffer \ \ If the player held down the panning key throughout the \ drawing process and the whole landscape was drawn, \ then the C flag will be clear, otherwise the C flag \ will be set LDX playerObject \ Set X to the object number of the player \ \ This should really be an LDX viewingObject instruction \ to be consistent with the rest of the routine, but it \ doesn't make any difference as they are the same at \ this point \ \ Perhaps at some point this routine allowed panning of \ the view from viewing objects other than the player, \ which would have been interesting... LDY lastPanKeyPressed \ Set Y to the direction of the last pan key that was \ pressed (which may not still be held down) BCS lpan7 \ If the call to DrawLandscapeView set the C flag then \ the landscape drawing process was aborted, so jump to \ lpan7 to revert the change to the player's pitch angle \ and return from the subroutine without updating the \ on-screen landscape view CPY #3 \ If Y <> 3 then Y must be 2, in which case the pan BNE lpan4 \ angle we fetched from the panAngleToUpdate table \ doesn't need correcting, so jump to lpan4 to skip the \ following \ If we get here then Y = 3, so we subtracted 12 from \ the player's pitch angle so it would draw the new part \ of the view into the screen buffer, so we now need to \ add 8 to the player's pitch angle so they end up \ looking in the correct direction, i.e. a net rotation \ of -4 rather than -12 pitch angles LDA objectPitchAngle,X \ Add 8 to the player's pitch angle CLC ADC #8 STA objectPitchAngle,X .lpan4 LDA #8 \ We now need to scroll the contents of the screen JSR StartScrollingView \ buffer into the top or bottom of the on-screen \ landscape view, so call StartScrollingView to \ configure a background task to scroll 8 character rows \ from the screen buffer onto the screen, using the \ interrupt handler to do it in the background .lpan5 JSR SetColumnBufferMax \ Call SetColumnBufferMax to set the maximum and minimum \ pitch angles for the column buffer .lpan6 RTS \ Return from the subroutine .lpan7 \ If we get here then the panning process was aborted \ before the landscape was drawn LDA objectPitchAngle,X \ Reverse the rotation that we applied to the player's SEC \ pitch angle for the pan, so this puts it back to the SBC panAngleToUpdate,Y \ value it had before we started the panning process STA objectPitchAngle,X JMP lpan5 \ Jump to SetColumnBufferMax via lpan5 to set the \ maximum and minimum pitch angles for the column buffer \ and return from the subroutine via a tail call