Cleanup HandleTileDirections fn

This commit is contained in:
scawful
2024-03-30 10:12:03 -04:00
parent b0b3ca242b
commit 716a681d6d

View File

@@ -388,6 +388,11 @@ Sprite_Minecart_Main:
; Currently, depending on where the tile is placed the
; cart may make a turn too early and appear to be off center.
North = $00
East = $01
South = $02
West = $03
SetTileLookupPosBasedOnDirection:
{
; Based on the direction of the Minecart, adjust the
@@ -441,13 +446,11 @@ HandleTileDirections:
; Load the tile index
LDA $0FA5 : CLC : CMP.b #$01 : BNE .not_out_of_bounds
; If the tile is out of bounds, release the cart
LDA #$40 : STA SprTimerD, X
%GotoAction(6) ; Minecart_Release
RTS
.not_out_of_bounds
; Check if the tile is a stop tile
CLC : CMP.b #$B7 : BCS .check_stop ; If tile ID is >= $B8, check for stop tiles
@@ -469,6 +472,7 @@ HandleTileDirections:
LDA.b #North : STA SprSubtype, X : STZ.w !MinecartDirection
LDA #$00 : STA !SpriteDirection, X
; -----------------------------------------------
.go_vert
%SetTimerA($40)
%StopCart()
@@ -486,6 +490,8 @@ HandleTileDirections:
; Set the new direction to west and flip the cart's orientation
LDA.b #East : STA SprSubtype, X : STA.w !MinecartDirection
LDA #$02 : STA !SpriteDirection, X
; -----------------------------------------------
.go_horiz
%SetTimerA($40)
%StopCart()
@@ -495,7 +501,6 @@ HandleTileDirections:
; -------------------------------------------------------
.check_for_movement
; Check for movement tiles
CLC : CMP.b #$B2 : BEQ .check_direction
CLC : CMP.b #$B3 : BEQ .check_direction
CLC : CMP.b #$B4 : BEQ .check_direction
@@ -512,43 +517,17 @@ HandleTileDirections:
; Add the row and column offsets to index into the lookup table
CLC : ADC.w .DirectionTileLookup, Y : TAY
; Direction to move on tile collision
; 00 - stop or nothing
; 01 - north
; 02 - east
; 03 - south
; 04 - west
North = $00
East = $01
South = $02
West = $03
.DirectionTileLookup
{
; TL, BL, TR, BR, Stop
db $02, $00, $04, $00 ; North
db $00, $00, $03, $01 ; East
db $00, $02, $00, $04 ; South
db $03, $01, $00, $00 ; West
}
.check_direction
LDA SprSubtype, X : BNE .not_zero
.not_zero
LDA SprSubtype, X
ASL #2 ; Multiply by 4 (shifting left by 2 bits) to offset rows in the lookup table
STA $07 ; Store the action index in $07
LDA $0FA5 ; Load the tile type
SEC : SBC.b #$B2 ; Subtract $B2 to normalize the tile type to 0 to 3
CLC : ADC.w $07 ; Add the action index to the tile type offset to get the composite index
TAY
TAY ; Transfer to Y to use as an offset for the rows
LDA.w .DirectionTileLookup, Y : TAY
LDA.w .DirectionTileLookup, Y
TAY
.execute_action
; JSR ClampSpritePositionToGrid
CPY #$01 : BEQ .move_north
CPY #$02 : BEQ .move_east
@@ -578,17 +557,32 @@ HandleTileDirections:
.done
RTS
.tile_ids
; db $B0 ; - Horiz
; db $B1 ; | Vert
; Direction to move on tile collision
; 00 - stop or nothing
; 01 - north
; 02 - east
; 03 - south
; 04 - west
.DirectionTileLookup
{
; TL, BL, TR, BR, Stop
db $02, $00, $04, $00 ; North
db $00, $00, $03, $01 ; East
db $00, $02, $00, $04 ; South
db $03, $01, $00, $00 ; West
}
.unused_tile_ids
{
; TL, BL, TR, BR
db $B2, $B3, $B4, $B5
; db $B0 - Horiz
; db $B1 | Vert
; db $B8 Stop North
; db $B9 Stop South
; db $BA Stop East
; db $BB Stop West
; db $BE ; + any direction
; db $BE + any direction
}
}
; =========================================================