Cleanup HandleTileDirections fn
This commit is contained in:
@@ -388,6 +388,11 @@ Sprite_Minecart_Main:
|
|||||||
; Currently, depending on where the tile is placed the
|
; Currently, depending on where the tile is placed the
|
||||||
; cart may make a turn too early and appear to be off center.
|
; cart may make a turn too early and appear to be off center.
|
||||||
|
|
||||||
|
North = $00
|
||||||
|
East = $01
|
||||||
|
South = $02
|
||||||
|
West = $03
|
||||||
|
|
||||||
SetTileLookupPosBasedOnDirection:
|
SetTileLookupPosBasedOnDirection:
|
||||||
{
|
{
|
||||||
; Based on the direction of the Minecart, adjust the
|
; Based on the direction of the Minecart, adjust the
|
||||||
@@ -441,13 +446,11 @@ HandleTileDirections:
|
|||||||
|
|
||||||
; Load the tile index
|
; Load the tile index
|
||||||
LDA $0FA5 : CLC : CMP.b #$01 : BNE .not_out_of_bounds
|
LDA $0FA5 : CLC : 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
|
.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
|
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.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()
|
||||||
@@ -486,6 +490,8 @@ HandleTileDirections:
|
|||||||
; 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()
|
||||||
@@ -495,7 +501,6 @@ HandleTileDirections:
|
|||||||
|
|
||||||
; -------------------------------------------------------
|
; -------------------------------------------------------
|
||||||
.check_for_movement
|
.check_for_movement
|
||||||
; Check for movement tiles
|
|
||||||
CLC : CMP.b #$B2 : BEQ .check_direction
|
CLC : CMP.b #$B2 : BEQ .check_direction
|
||||||
CLC : CMP.b #$B3 : BEQ .check_direction
|
CLC : CMP.b #$B3 : BEQ .check_direction
|
||||||
CLC : CMP.b #$B4 : 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
|
; Add the row and column offsets to index into the lookup table
|
||||||
CLC : ADC.w .DirectionTileLookup, Y : TAY
|
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
|
.check_direction
|
||||||
LDA SprSubtype, X : BNE .not_zero
|
LDA SprSubtype, X
|
||||||
|
|
||||||
.not_zero
|
|
||||||
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
|
||||||
|
|
||||||
LDA $0FA5 ; Load the tile type
|
LDA $0FA5 ; Load the tile type
|
||||||
SEC : SBC.b #$B2 ; Subtract $B2 to normalize the tile type to 0 to 3
|
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
|
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
|
; JSR ClampSpritePositionToGrid
|
||||||
CPY #$01 : BEQ .move_north
|
CPY #$01 : BEQ .move_north
|
||||||
CPY #$02 : BEQ .move_east
|
CPY #$02 : BEQ .move_east
|
||||||
@@ -578,17 +557,32 @@ HandleTileDirections:
|
|||||||
.done
|
.done
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
.tile_ids
|
; Direction to move on tile collision
|
||||||
; db $B0 ; - Horiz
|
; 00 - stop or nothing
|
||||||
; db $B1 ; | Vert
|
; 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
|
; TL, BL, TR, BR
|
||||||
db $B2, $B3, $B4, $B5
|
db $B2, $B3, $B4, $B5
|
||||||
|
; db $B0 - Horiz
|
||||||
|
; db $B1 | Vert
|
||||||
; db $B8 Stop North
|
; db $B8 Stop North
|
||||||
; db $B9 Stop South
|
; db $B9 Stop South
|
||||||
; db $BA Stop East
|
; db $BA Stop East
|
||||||
; db $BB Stop West
|
; db $BB Stop West
|
||||||
|
; db $BE + any direction
|
||||||
; db $BE ; + any direction
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
; =========================================================
|
; =========================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user