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

@@ -485,7 +485,7 @@ HandleTileDirections:
{ {
LDA SprTimerA, X : BEQ + LDA SprTimerA, X : BEQ +
RTS RTS
+ +
; Setup Minecart position to look for tile IDs ; Setup Minecart position to look for tile IDs
; We use AND #$F8 to clamp to a 16x16 grid, however this needs work. ; We use AND #$F8 to clamp to a 16x16 grid, however this needs work.
@@ -496,79 +496,75 @@ HandleTileDirections:
LDA.b #$00 : JSL Sprite_GetTileAttr LDA.b #$00 : JSL Sprite_GetTileAttr
; Load the tile index ; 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 ; If the tile is out of bounds, release the cart
LDA #$40 : STA SprTimerD, X LDA #$40 : STA SprTimerD, X
%GotoAction(6) ; Minecart_Release %GotoAction(6) ; Minecart_Release
RTS RTS
.not_out_of_bounds .out_of_bounds
JSR ClampSpritePositionToGrid
RTS
.not_out_of_bounds
; Check if the tile is a stop tile ; 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 .check_stop
CLC : CMP.b #$B7 : BEQ .stop_north CMP.b #$B7 : BEQ .stop_north
CLC : CMP.b #$B8 : BEQ .stop_south CMP.b #$B8 : BEQ .stop_south
CLC : CMP.b #$B9 : BEQ .stop_west CMP.b #$B9 : BEQ .stop_west
CLC : CMP.b #$BA : BEQ .stop_east CMP.b #$BA : BEQ .stop_east
JMP .check_for_movement ; if none of the above, continue with normal logic CMP.b #$20 : BEQ .out_of_bounds
JMP .check_for_movement ; if none of the above, continue with normal logic
.stop_north .stop_north
; Set the new direction to north and flip the cart's orientation ; Set the new direction to north and flip the cart's orientation
LDA.b #South : STA SprSubtype, X : STA.w !MinecartDirection LDA.b #South : STA SprSubtype, X : STA.w !MinecartDirection
LDA #$01 : STA !SpriteDirection, X LDA #$01 : STA !SpriteDirection, X
JMP .go_vert JMP .go_vert
.stop_south .stop_south
; Set the new direction to south and flip the cart's orientation ; Set the new direction to south and flip the cart's orientation
LDA.b #North : STA SprSubtype, X : STZ.w !MinecartDirection LDA.b #North : STA SprSubtype, X : STZ.w !MinecartDirection
LDA #$00 : STA !SpriteDirection, X LDA #$00 : STA !SpriteDirection, X
; ----------------------------------------------- ; -----------------------------------------------
.go_vert .go_vert
%SetTimerA($40) %SetTimerA($40)
%StopCart() %StopCart()
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
JSL Player_ResetState JSL Player_ResetState
RTS RTS
.stop_east .stop_east
; Set the new direction to east and flip the cart's orientation ; Set the new direction to east and flip the cart's orientation
LDA.b #West : STA SprSubtype, X : STA.w !MinecartDirection LDA.b #West : STA SprSubtype, X : STA.w !MinecartDirection
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
JMP .go_horiz JMP .go_horiz
.stop_west .stop_west
; Set the new direction to west and flip the cart's orientation ; Set the new direction to west and flip the cart's orientation
LDA.b #East : STA SprSubtype, X : STA.w !MinecartDirection LDA.b #East : STA SprSubtype, X : STA.w !MinecartDirection
LDA #$02 : STA !SpriteDirection, X LDA #$02 : STA !SpriteDirection, X
; ----------------------------------------------- ; -----------------------------------------------
.go_horiz .go_horiz
%SetTimerA($40) %SetTimerA($40)
%StopCart() %StopCart()
%GotoAction(0) ; Minecart_WaitHoriz %GotoAction(0) ; Minecart_WaitHoriz
JSL Player_ResetState JSL Player_ResetState
RTS RTS
; ------------------------------------------------------- ; -------------------------------------------------------
.check_for_movement .check_for_movement
CLC : CMP.b #$B2 : BEQ .check_direction CMP.b #$B2 : BEQ .check_direction
CLC : CMP.b #$B3 : BEQ .check_direction CMP.b #$B3 : BEQ .check_direction
CLC : CMP.b #$B4 : BEQ .check_direction CMP.b #$B4 : BEQ .check_direction
CLC : CMP.b #$B5 : BEQ .check_direction CMP.b #$B5 : BEQ .check_direction
JMP .done JMP .done
; Create a composite index based on current direction and tile type .check_direction
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 LDA SprSubtype, X
ASL #2 ; Multiply by 4 (shifting left by 2 bits) to offset rows in the lookup table 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 STA $07 ; Store the action index in $07
@@ -594,6 +590,7 @@ HandleTileDirections:
.move_east .move_east
LDA #$01 : STA SprSubtype, X LDA #$01 : STA SprSubtype, X
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
RTS RTS
.move_south .move_south
@@ -604,6 +601,7 @@ HandleTileDirections:
.move_west .move_west
LDA #$03 : STA SprSubtype, X LDA #$03 : STA SprSubtype, X
LDA #$02 : STA !SpriteDirection, X LDA #$02 : STA !SpriteDirection, X
LDA SprY, X : SEC : SBC.b #$04 : STA SprY, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
.done .done
RTS RTS
@@ -675,7 +673,7 @@ HandleDynamicSwitchTileDirections:
CMP.b #$02 : BEQ .north_or_south CMP.b #$02 : BEQ .north_or_south
.east_or_west .east_or_west
LDA SwitchRam : BNE .go_west LDA SwitchRam : BEQ .go_west
LDA #$01 : STA SprSubtype, X LDA #$01 : STA SprSubtype, X
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast