Cleanup HandleTileDirections fn
This commit is contained in:
@@ -212,7 +212,7 @@ Sprite_Minecart_Main:
|
|||||||
|
|
||||||
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
|
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
|
||||||
JSR CheckIfPlayerIsOn : BCC .not_ready
|
JSR CheckIfPlayerIsOn : BCC .not_ready
|
||||||
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
|
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
|
||||||
|
|
||||||
JSL Player_HaltDashAttack ; Stop the player from dashing
|
JSL Player_HaltDashAttack ; Stop the player from dashing
|
||||||
LDA #$02 : STA $02F5 ; Somaria platform and moving
|
LDA #$02 : STA $02F5 ; Somaria platform and moving
|
||||||
@@ -246,7 +246,7 @@ Sprite_Minecart_Main:
|
|||||||
|
|
||||||
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
|
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
|
||||||
JSR CheckIfPlayerIsOn : BCC .not_ready
|
JSR CheckIfPlayerIsOn : BCC .not_ready
|
||||||
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
|
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
|
||||||
|
|
||||||
JSL Player_HaltDashAttack ; Stop the player from dashing
|
JSL Player_HaltDashAttack ; Stop the player from dashing
|
||||||
LDA #$02 : STA $02F5 ; Somaria platform and moving
|
LDA #$02 : STA $02F5 ; Somaria platform and moving
|
||||||
@@ -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,66 +446,66 @@ 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
|
||||||
|
|
||||||
.check_stop
|
.check_stop
|
||||||
CLC : CMP.b #$B7 : BEQ .stop_north
|
CLC : CMP.b #$B7 : BEQ .stop_north
|
||||||
CLC : CMP.b #$B8 : BEQ .stop_south
|
CLC : CMP.b #$B8 : BEQ .stop_south
|
||||||
CLC : CMP.b #$B9 : BEQ .stop_west
|
CLC : CMP.b #$B9 : BEQ .stop_west
|
||||||
CLC : CMP.b #$BA : BEQ .stop_east
|
CLC : CMP.b #$BA : BEQ .stop_east
|
||||||
JMP .check_for_movement ; if none of the above, continue with normal logic
|
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
|
; -----------------------------------------------
|
||||||
%SetTimerA($40)
|
.go_vert
|
||||||
%StopCart()
|
%SetTimerA($40)
|
||||||
%GotoAction(1) ; Minecart_WaitVert
|
%StopCart()
|
||||||
JSL Player_ResetState
|
%GotoAction(1) ; Minecart_WaitVert
|
||||||
RTS
|
JSL Player_ResetState
|
||||||
|
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
|
|
||||||
%SetTimerA($40)
|
; -----------------------------------------------
|
||||||
%StopCart()
|
.go_horiz
|
||||||
%GotoAction(0) ; Minecart_WaitHoriz
|
%SetTimerA($40)
|
||||||
JSL Player_ResetState
|
%StopCart()
|
||||||
RTS
|
%GotoAction(0) ; Minecart_WaitHoriz
|
||||||
|
JSL Player_ResetState
|
||||||
|
RTS
|
||||||
|
|
||||||
; -------------------------------------------------------
|
; -------------------------------------------------------
|
||||||
.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
|
||||||
CLC : CMP.b #$B5 : BEQ .check_direction
|
CLC : CMP.b #$B5 : BEQ .check_direction
|
||||||
JMP .done
|
JMP .done
|
||||||
|
|
||||||
; Create a composite index based on current direction and tile type
|
; Create a composite index based on current direction and tile type
|
||||||
LDA SprSubtype, X ; Load the current direction subtype (0 to 3)
|
LDA SprSubtype, X ; Load the current direction subtype (0 to 3)
|
||||||
@@ -512,83 +517,72 @@ 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
|
||||||
CPY #$03 : BEQ .move_south
|
CPY #$03 : BEQ .move_south
|
||||||
CPY #$04 : BEQ .move_west
|
CPY #$04 : BEQ .move_west
|
||||||
JMP .done
|
JMP .done
|
||||||
|
|
||||||
.move_north
|
.move_north
|
||||||
LDA #$00 : STA SprSubtype, X
|
LDA #$00 : STA SprSubtype, X
|
||||||
STA !SpriteDirection, X
|
STA !SpriteDirection, X
|
||||||
%GotoAction(2) ; Minecart_MoveNorth
|
%GotoAction(2) ; Minecart_MoveNorth
|
||||||
RTS
|
RTS
|
||||||
.move_east
|
.move_east
|
||||||
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
|
||||||
RTS
|
RTS
|
||||||
.move_south
|
.move_south
|
||||||
LDA #$02 : STA SprSubtype, X
|
LDA #$02 : STA SprSubtype, X
|
||||||
LDA #$01 : STA !SpriteDirection, X
|
LDA #$01 : STA !SpriteDirection, X
|
||||||
%GotoAction(4) ; Minecart_MoveSouth
|
%GotoAction(4) ; Minecart_MoveSouth
|
||||||
RTS
|
RTS
|
||||||
.move_west
|
.move_west
|
||||||
LDA #$03 : STA SprSubtype, X
|
LDA #$03 : STA SprSubtype, X
|
||||||
LDA #$02 : STA !SpriteDirection, X
|
LDA #$02 : STA !SpriteDirection, X
|
||||||
%GotoAction(5) ; Minecart_MoveWest
|
%GotoAction(5) ; Minecart_MoveWest
|
||||||
.done
|
.done
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
.tile_ids
|
; Direction to move on tile collision
|
||||||
; db $B0 ; - Horiz
|
; 00 - stop or nothing
|
||||||
; db $B1 ; | Vert
|
; 01 - north
|
||||||
; TL, BL, TR, BR
|
; 02 - east
|
||||||
db $B2, $B3, $B4, $B5
|
; 03 - south
|
||||||
; db $B8 Stop North
|
; 04 - west
|
||||||
; db $B9 Stop South
|
.DirectionTileLookup
|
||||||
; db $BA Stop East
|
{
|
||||||
; db $BB Stop West
|
; TL, BL, TR, BR, Stop
|
||||||
|
db $02, $00, $04, $00 ; North
|
||||||
; db $BE ; + any direction
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
; =========================================================
|
; =========================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user