Update cart tile directions function

This commit is contained in:
scawful
2024-05-19 23:34:23 -04:00
parent 6d12a4356b
commit 465bea502d

View File

@@ -496,20 +496,26 @@ HandleTileDirections:
LDA.b #$00 : JSL Sprite_GetTileAttr
; Load the tile index
LDA $0FA5 : CLC : CMP.b #$01 : BNE .not_out_of_bounds
LDA $0FA5 : 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
.out_of_bounds
JSR ClampSpritePositionToGrid
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
CMP.b #$B7 : BCS .check_stop ; If tile ID is >= $B8, check for stop tiles
.check_stop
CLC : CMP.b #$B7 : BEQ .stop_north
CLC : CMP.b #$B8 : BEQ .stop_south
CLC : CMP.b #$B9 : BEQ .stop_west
CLC : CMP.b #$BA : BEQ .stop_east
CMP.b #$B7 : BEQ .stop_north
CMP.b #$B8 : BEQ .stop_south
CMP.b #$B9 : BEQ .stop_west
CMP.b #$BA : BEQ .stop_east
CMP.b #$20 : BEQ .out_of_bounds
JMP .check_for_movement ; if none of the above, continue with normal logic
.stop_north
@@ -552,22 +558,12 @@ HandleTileDirections:
; -------------------------------------------------------
.check_for_movement
CLC : CMP.b #$B2 : BEQ .check_direction
CLC : CMP.b #$B3 : BEQ .check_direction
CLC : CMP.b #$B4 : BEQ .check_direction
CLC : CMP.b #$B5 : BEQ .check_direction
CMP.b #$B2 : BEQ .check_direction
CMP.b #$B3 : BEQ .check_direction
CMP.b #$B4 : BEQ .check_direction
CMP.b #$B5 : BEQ .check_direction
JMP .done
; Create a composite index based on current direction and tile type
LDA SprSubtype, X ; Load the current direction subtype (0 to 3)
ASL A ; Multiply by 4 to offset rows in the lookup table
TAY ; Transfer to Y to use as an offset for the rows
; Load the tile type and subtract $B2 to normalize the tile type to 0 to 3
LDA $0FA5 : SEC : SBC.b #$B3
; Add the row and column offsets to index into the lookup table
CLC : ADC.w .DirectionTileLookup, Y : TAY
.check_direction
LDA SprSubtype, X
ASL #2 ; Multiply by 4 (shifting left by 2 bits) to offset rows in the lookup table
@@ -594,6 +590,7 @@ HandleTileDirections:
.move_east
LDA #$01 : STA SprSubtype, X
LDA #$03 : STA !SpriteDirection, X
LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X
%GotoAction(3) ; Minecart_MoveEast
RTS
.move_south
@@ -604,6 +601,7 @@ HandleTileDirections:
.move_west
LDA #$03 : STA SprSubtype, X
LDA #$02 : STA !SpriteDirection, X
LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X
%GotoAction(5) ; Minecart_MoveWest
.done
RTS
@@ -675,7 +673,7 @@ HandleDynamicSwitchTileDirections:
CMP.b #$02 : BEQ .north_or_south
.east_or_west
LDA SwitchRam : BNE .go_west
LDA SwitchRam : BEQ .go_west
LDA #$01 : STA SprSubtype, X
LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast