Skip to navigation

Drawing the landscape: DrawLandscapeView (Part 3 of 3)

Name: DrawLandscapeView (Part 3 of 3) [Show more] Type: Subroutine Category: Drawing the landscape Summary: Draw a tile row in two parts, one on either side of the viewer
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.dlan18 \ If we get here then the tile row we are drawing \ contains the viewer \ \ The viewer can only see one half of the row, because \ they are standing on it, so we need to work out which \ half this is (if they can see any of the row at all) \ and then draw it \ \ We don't draw the viewer's tile yet, as we do that \ later LDY xTileViewLeftEdge \ Set Y to the tile number just inside the left edge of INY \ the visible portion of the row CPY xTileViewer \ If this isn't the viewer's tile, jump to dlan19 to BNE dlan19 \ perform the same check on the right side \ If we get here then the visible part of the viewer's \ tile row starts on the tile just to the left of their \ position, so we are looking left and should draw that \ part of the visible row STY xTileViewRightEdge \ Set the right edge to the viewer's tile, so we draw \ from the left edge up to (but not including) the \ viewer's tile JMP dlan20 \ Jump to dlan20 to draw the tile row containing the \ viewer .dlan19 \ If we get here then the left edge is not just to the \ left of the viewer, so now we check the right edge LDY xTileViewRightEdge \ Set Y to the tile number that's two to the left of the DEY \ right edge of the visible portion DEY CPY xTileViewer \ If this isn't the viewer's tile, jump to dlan21 to BNE dlan21 \ skip drawing the tile row altogether, as we can't see \ it to the left or the right (so instead we move on to \ drawing the player's tile) \ If we get here then the visible part of the viewer's \ tile row starts on the tile just to the right of their \ position, so we are looking right and should draw that \ part of the visible row INY \ Set the left edge to the tile just right of the STY xTileViewLeftEdge \ viewer's tile, so we draw from just right of the \ viewer's tile to the right edge .dlan20 \ We now draw the tile row containing the viewer, but \ first we need to ensure we have the data for the tiles \ at each end LDY xTileViewLeftEdge \ Set Y to the left edge of the viewer's tile row JSR GetTileViewAngles \ Calculate the pitch and yaw angles for the tile corner \ at (Y, zTile), from the perspective of the viewer, and \ store them in the following tables in the relevant \ entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) LDY xTileViewRightEdge \ Set Y to the right edge of the viewer's tile row JSR GetTileViewAngles \ Calculate the pitch and yaw angles for the tile corner \ at (Y, zTile), from the perspective of the viewer, and \ store them in the following tables in the relevant \ entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) JSR DrawLandscapeRow \ Draw the tile row at z-coordinate zTile, between tiles \ xTileViewLeftEdge and xTileViewRightEdge, including \ any objects on any of the tiles .dlan21 \ We now draw the tile row beneath the viewer, but first \ we need to ensure we have the data for the tile just \ in front of it LDA #0 \ Set drawingTableOffset = 0 so the following call to STA drawingTableOffset \ GetTileViewAngles (which we call to fetch the data for \ the tile corner row in front of viewer) will populate \ the tables at tileViewYaw+0 and tileViewPitch+0 INC zTile \ Increment the row number so it's the row in front of \ the viewer LDY xTileViewer \ Set Y to the tile column for the viewer's tile, so we \ can fetch the tile data for the tile directly in front \ of the viewer JSR GetTileViewAngles \ Calculate the pitch and yaw angles for the tile corner \ at (Y, zTile), from the perspective of the viewer, and \ store them in the following tables in the relevant \ entry for this tile corner: \ \ * drawViewYaw(Hi Lo) \ \ * drawViewPitch(Hi Lo) \ \ * tileViewData \ \ * tileIsOnScreen (also returned in A and the Z flag) \ By this point we have the following: \ \ * The tables at tileViewYaw+0 and tileViewPitch+0 \ contain data for the tile corner row in front of \ the viewer, i.e. for the front edge of the tile on \ which the viewer sits \ \ * The tables at tileViewYaw+32 and tileViewPitch+32 \ contain data for the tile corner row containing \ the viewer, i.e. for the rear edge of the tile on \ which the viewer sits \ \ Y is the offset of the viewer's tile within these \ tables, so, for example: \ \ * drawViewPitchHi,Y is the corner at the front \ left of the viewer's tile \ \ * drawViewPitchHi+1,Y is the corner at the front \ right of the viewer's tile \ \ * drawViewPitchHi+32,Y is the corner at the rear \ left of the viewer's tile \ \ * drawViewPitchHi+32+1,Y is the corner at the rear \ right of the viewer's tile \ \ We now set up the angles for the tile to ensure that \ it looks correct LDA drawViewPitchHi,Y \ If the high byte of the pitch angle of the front-left CMP #2 \ edge of the viewer's tile is 2 or more, then it is off BCS dlan22 \ the top of the screen, so jump to dlan22 to skip \ drawing it and instead return from the subroutine STA drawViewPitchHi+1,Y \ Set the pitch angle for the tile corner in the LDA drawViewPitchLo,Y \ front-right corner of the viewer's tile to be the STA drawViewPitchLo+1,Y \ same as the front-left corner, so this ensures \ that the two front corners of the tile containing \ the viewer are horizontally level LDA #32 \ Set drawingTableOffset = 0 so the following call to STA drawingTableOffset \ DrawFlatTile (for the tile row beneath the viewer) \ will fetch data from the tables at tileViewData+32, \ tileViewYaw+32 and tileViewPitch+32 DEC zTile \ Decrement the row number so it goes back to the row \ containing the viewer \ We now position the corners of the viewer's tile so \ it spreads to the left and right screen edges and \ appears to dip down behind the viewer (so it spreads \ down to the bottom of the screen as well) LDA #&FF \ Set the pitch angle for the two rear tile STA drawViewPitchHi+32,Y \ corners to be as low down as possible (as the STA drawViewPitchHi+32+1,Y \ high byte of &FF makes the angle negative) STA drawViewYawHi+32,Y \ Set the yaw angle for the two left tile corners to be STA drawViewYawHi,Y \ as far left as possible LDA #20 \ Set the yaw angle for the two right tile corners STA drawViewYawHi+32+1,Y \ to 20, which is a full screen width, so this puts STA drawViewYawHi+1,Y \ them on the right edge of the screen LDA xTileViewer \ Set xTileToDraw to the column of the viewer's tile, so STA xTileToDraw \ the call to DrawFlatTile draws this tile JSR DrawFlatTile \ Draw the flat tile under the viewer .dlan22 CLC \ Clear the C flag to indicate that we have drawn the \ whole landscape RTS \ Return from the subroutine