Add comments and cleanup Minecart, Mineswitch, switch_track

This commit is contained in:
scawful
2024-11-17 13:48:51 -05:00
parent a2af6a176a
commit 5aa9e97375
3 changed files with 141 additions and 137 deletions

View File

@@ -1,6 +1,25 @@
; ========================================================= ; =========================================================
; Minecart Sprite Properties ; Minecart Sprite
; ========================================================= ;
; Used in Goron Mines along with the SwitchTrack and
; Mineswitch sprite. Makes use of custom collision with
; somaria track corner tiles.
;
; The cart begins in an inactive state, horizontal or vertical
; and is activated by the player when they stand on the hitbox
; and press the B button. Based on the subtype of the cart,
; it will move in that direction until it encounters one of the
; following scenarions:
;
; Somaria Stop Tile - Halt the cart and set its next direction
; Somaria Corner Track - Switch directions based on cart direction
; and corner tiletype.
; Somaria Any Track - Switch direction based on player input
; Dungeon Transition - Switch to Minecart follower and transition
; to the next room in a dungeon, spawning
; a new minecart sprite in the room at Link's
; location and configuring the direction to move
; in automatically (no B button to activate)
!SPRID = Sprite_Minecart !SPRID = Sprite_Minecart
!NbrTiles = 08 ; Number of tiles used in a frame !NbrTiles = 08 ; Number of tiles used in a frame
@@ -39,27 +58,28 @@
!MinecartSpeed = 20 !MinecartSpeed = 20
!DoubleSpeed = 30 !DoubleSpeed = 30
North = $00 ; SprSubtype and Minecart movement direction
East = $01
South = $02
West = $03
; nesw ; nesw
; 0 - north ; 0 - north
; 1 - east ; 1 - east
; 2 - south ; 2 - south
; 3 - west ; 3 - west
North = $00
East = $01
South = $02
West = $03
!MinecartDirection = $012B !MinecartDirection = $012B
Up = $00 ; Sprite Facing Direction
Down = $01
Left = $02
Right = $03
; $0DE0[0x10] - (Sprite) ;functions
; udlr ; udlr
; 0 - up ; 0 - up
; 1 - down ; 1 - down
; 2 - left ; 2 - left
; 3 - right ; 3 - right
Up = $00
Down = $01
Left = $02
Right = $03
!SpriteDirection = $0DE0 !SpriteDirection = $0DE0
; ========================================================= ; =========================================================
@@ -67,8 +87,8 @@ Right = $03
Sprite_Minecart_Long: Sprite_Minecart_Long:
{ {
PHB : PHK : PLB PHB : PHK : PLB
JSR Sprite_Minecart_DrawTop ; Draws the top half behind Link JSR Sprite_Minecart_DrawTop ; Draw behind Link
JSR Sprite_Minecart_DrawBottom ; Draw the bottom half in front of Link JSR Sprite_Minecart_DrawBottom ; Draw in front of Link
JSL Sprite_CheckActive : BCC .SpriteIsNotActive JSL Sprite_CheckActive : BCC .SpriteIsNotActive
JSR Sprite_Minecart_Main JSR Sprite_Minecart_Main
.SpriteIsNotActive .SpriteIsNotActive
@@ -77,6 +97,9 @@ Sprite_Minecart_Long:
} }
; ========================================================= ; =========================================================
; The subtype of the minecart determines the direction it
; will move in, so if the subtype is 0 the cart will move
; north and start in WaitVert mode.
Sprite_Minecart_Prep: Sprite_Minecart_Prep:
{ {
@@ -86,24 +109,23 @@ Sprite_Minecart_Prep:
STZ.w SprMiscG, X ; Clear the active tossing flag STZ.w SprMiscG, X ; Clear the active tossing flag
; If the subtype is > 4, then it's an active cart ; If the subtype is > 4, then it's an active cart
LDA.w SprSubtype, X : CMP.b #$04 : BCC .continue LDA.w SprSubtype, X : CMP.b #$04 : BCC +
LDA.w SprSubtype, X : SEC : SBC.b #$03 : STA.w SprSubtype, X LDA.w SprSubtype, X : SEC : SBC.b #$03 : STA.w SprSubtype, X
LDA.b #$01 : STA.w SprMiscF, X ; Set the auto-move flag LDA.b #$01 : STA.w SprMiscF, X ; Set the auto-move flag
.continue +
LDA #$00 : STA $0CAA, X ; Sprite persist in dungeon
LDA #$04 : STA $0E40, X ; Nbr Oam Entries
LDA #$40 : STA $0E60, x ; Impervious props
LDA #$E0 : STA $0F60, X ; Persist
LDA #$00 : STA.w SprBump, X ; No bump damage
LDA #$00 : STA $0B6B, X ; Set interactive hitbox?
LDA #$04 : STA.w SprNbrOAM, X ; Nbr Oam Entries
LDA #$40 : STA.w SprGfxProps, X ; Impervious props
LDA #$E0 : STA.w SprHitbox, X ; Persist outside camera
STZ.w SprDefl, X ; Sprite persist in dungeon
STZ.w SprBump, X ; No bump damage
STZ.w SprTileDie, X ; Set interactive hitbox
STZ.w !MinecartDirection STZ.w !MinecartDirection
LDA.w SprSubtype, X : CMP.b #$00 : BEQ .north LDA.w SprSubtype, X : CMP.b #$00 : BEQ .north
CMP.b #$01 : BEQ .east CMP.b #$01 : BEQ .east
CMP.b #$02 : BEQ .south CMP.b #$02 : BEQ .south
CMP.b #$03 : BEQ .west CMP.b #$03 : BEQ .west
.north .north
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
JMP .done JMP .done
@@ -113,8 +135,8 @@ Sprite_Minecart_Prep:
%GotoAction(0) ; Minecart_WaitHoriz %GotoAction(0) ; Minecart_WaitHoriz
JMP .done JMP .done
.south .south
LDA #$02 : STA !MinecartDirection LDA.b #South : STA !MinecartDirection
LDA #$01 : STA !SpriteDirection, X LDA.b #Down : STA !SpriteDirection, X
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
JMP .done JMP .done
.west .west
@@ -132,10 +154,8 @@ macro HandlePlayerCamera()
LDA $22 : SEC : SBC $3F : STA $31 LDA $22 : SEC : SBC $3F : STA $31
LDA $20 : SEC : SBC $3E : STA $30 LDA $20 : SEC : SBC $3E : STA $30
PHX PHX
JSL Link_HandleMovingAnimation_FullLongEntry JSL Link_HandleMovingAnimation_FullLongEntry
JSL HandleIndoorCameraAndDoors JSL HandleIndoorCameraAndDoors
JSL Link_CancelDash JSL Link_CancelDash
PLX PLX
endmacro endmacro
@@ -202,18 +222,6 @@ Minecart_HandleToss:
RTS RTS
} }
Minecart_HandleLiftAndToss:
{
JSR CheckIfPlayerIsOn : BCC .not_tossing
LDA.w LinkCarryOrToss : CMP.b #$02 : BNE .not_tossing
JSR Minecart_HandleToss
.not_tossing
JSL Sprite_CheckIfLifted
JSL Sprite_Move
JSR Minecart_HandleTossedCart
RTS
}
Minecart_HandleTossedCart: Minecart_HandleTossedCart:
{ {
LDA.w SprMiscG, X : BEQ .not_tossed LDA.w SprMiscG, X : BEQ .not_tossed
@@ -233,6 +241,19 @@ Minecart_HandleTossedCart:
RTS RTS
} }
Minecart_HandleLiftAndToss:
{
JSR CheckIfPlayerIsOn : BCC .not_tossing
LDA.w LinkCarryOrToss : CMP.b #$02 : BNE .not_tossing
JSR Minecart_HandleToss
.not_tossing
JSL Sprite_CheckIfLifted
JSL Sprite_Move
JSR Minecart_HandleTossedCart
JSL ThrownSprite_TileAndSpriteInteraction_long
RTS
}
; ========================================================= ; =========================================================
Sprite_Minecart_Main: Sprite_Minecart_Main:
@@ -270,17 +291,14 @@ Sprite_Minecart_Main:
LDA #$02 : STA !SpriteDirection, X LDA #$02 : STA !SpriteDirection, X
%GotoAction(5) ; Minecart_MoveWest %GotoAction(5) ; Minecart_MoveWest
RTS RTS
.opposite_direction .opposite_direction
STA.w !MinecartDirection STA.w !MinecartDirection
LDA #$03 : STA !SpriteDirection, X LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast %GotoAction(3) ; Minecart_MoveEast
RTS RTS
.not_ready .not_ready
.lifting .lifting
JSR Minecart_HandleLiftAndToss JSR Minecart_HandleLiftAndToss
JSL ThrownSprite_TileAndSpriteInteraction_long
RTS RTS
} }
@@ -311,11 +329,9 @@ Sprite_Minecart_Main:
LDA #$00 : STA !SpriteDirection, X LDA #$00 : STA !SpriteDirection, X
%GotoAction(2) ; Minecart_MoveNorth %GotoAction(2) ; Minecart_MoveNorth
RTS RTS
.not_ready .not_ready
.lifting .lifting
JSR Minecart_HandleLiftAndToss JSR Minecart_HandleLiftAndToss
JSL ThrownSprite_TileAndSpriteInteraction_long
RTS RTS
} }
@@ -327,10 +343,10 @@ Sprite_Minecart_Main:
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA.w SprYSpeed, X LDA.b #-!MinecartSpeed : STA.w SprYSpeed, X
JMP .continue JMP +
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA.w SprYSpeed, X LDA.b #-!DoubleSpeed : STA.w SprYSpeed, X
.continue +
JSL Sprite_MoveVert JSL Sprite_MoveVert
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
@@ -350,10 +366,10 @@ Sprite_Minecart_Main:
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA $0D50, X LDA.b #!MinecartSpeed : STA $0D50, X
JMP .continue JMP +
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA.w SprXSpeed, X LDA.b #!DoubleSpeed : STA.w SprXSpeed, X
.continue +
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
@@ -373,10 +389,10 @@ Sprite_Minecart_Main:
%InitMovement() %InitMovement()
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #!MinecartSpeed : STA.w SprYSpeed, X LDA.b #!MinecartSpeed : STA.w SprYSpeed, X
JMP .continue JMP +
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA.w SprYSpeed, X LDA.b #!DoubleSpeed : STA.w SprYSpeed, X
.continue +
JSL Sprite_MoveVert JSL Sprite_MoveVert
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
@@ -397,10 +413,10 @@ Sprite_Minecart_Main:
LDA $36 : BNE .fast_speed LDA $36 : BNE .fast_speed
LDA.b #-!MinecartSpeed : STA.w SprXSpeed, X LDA.b #-!MinecartSpeed : STA.w SprXSpeed, X
JMP .continue JMP +
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA.w SprXSpeed, X LDA.b #-!DoubleSpeed : STA.w SprXSpeed, X
.continue +
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
@@ -471,12 +487,12 @@ HandleTileDirections:
.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.w SprSubtype, X : STA.w !MinecartDirection LDA.b #South : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA #$01 : STA !SpriteDirection, X LDA.b #Down : 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.w SprSubtype, X : STZ.w !MinecartDirection LDA.b #North : STA.w SprSubtype, X : STZ.w !MinecartDirection
LDA #$00 : STA !SpriteDirection, X LDA.b #Up : STA !SpriteDirection, X
; ----------------------------------------------- ; -----------------------------------------------
.go_vert .go_vert
%SetTimerA($40) %SetTimerA($40)
@@ -487,12 +503,12 @@ HandleTileDirections:
.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.w SprSubtype, X : STA.w !MinecartDirection LDA.b #West : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA #$02 : STA !SpriteDirection, X LDA.b #Left : 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.w SprSubtype, X : STA.w !MinecartDirection LDA.b #East : STA.w SprSubtype, X : STA.w !MinecartDirection
LDA #$03 : STA !SpriteDirection, X LDA.b #Right : STA !SpriteDirection, X
; ----------------------------------------------- ; -----------------------------------------------
.go_horiz .go_horiz
%SetTimerA($40) %SetTimerA($40)

View File

@@ -37,16 +37,12 @@
Sprite_LeverSwitch_Long: Sprite_LeverSwitch_Long:
{ {
PHB : PHK : PLB PHB : PHK : PLB
JSR Sprite_LeverSwitch_Draw
JSR Sprite_LeverSwitch_Draw ; Call the draw code JSL Sprite_CheckActive : BCC .SpriteIsNotActive
JSL Sprite_CheckActive ; Check if game is not paused JSR Sprite_LeverSwitch_Main
BCC .SpriteIsNotActive ; Skip Main code is sprite is innactive
JSR Sprite_LeverSwitch_Main ; Call the main sprite code
.SpriteIsNotActive .SpriteIsNotActive
PLB ; Get back the databank we stored previously PLB
RTL ; Go back to original code RTL
} }
; ========================================================= ; =========================================================

View File

@@ -1,6 +1,5 @@
; ========================================================= ; =========================================================
; Sprite Properties ; Switch Track sprite
; =========================================================
!SPRID = Sprite_SwitchTrack !SPRID = Sprite_SwitchTrack
!NbrTiles = 02 ; Number of tiles used in a frame !NbrTiles = 02 ; Number of tiles used in a frame
@@ -37,16 +36,12 @@
Sprite_RotatingTrack_Long: Sprite_RotatingTrack_Long:
{ {
PHB : PHK : PLB PHB : PHK : PLB
JSR Sprite_RotatingTrack_Draw
JSR Sprite_RotatingTrack_Draw ; Call the draw code JSL Sprite_CheckActive : BCC .SpriteIsNotActive
JSL Sprite_CheckActive ; Check if game is not paused JSR Sprite_RotatingTrack_Main
BCC .SpriteIsNotActive ; Skip Main code is sprite is innactive
JSR Sprite_RotatingTrack_Main ; Call the main sprite code
.SpriteIsNotActive .SpriteIsNotActive
PLB ; Get back the databank we stored previously PLB
RTL ; Go back to original code RTL
} }
; ========================================================= ; =========================================================
@@ -54,10 +49,8 @@ Sprite_RotatingTrack_Long:
Sprite_RotatingTrack_Prep: Sprite_RotatingTrack_Prep:
{ {
PHB : PHK : PLB PHB : PHK : PLB
LDA.b #$80 : STA $0CAA, X LDA.b #$80 : STA $0CAA, X
LDA.w SprSubtype, X : STA.w SprAction,X LDA.w SprSubtype, X : STA.w SprAction,X
PLB PLB
RTL RTL
} }
@@ -151,7 +144,6 @@ Sprite_RotatingTrack_Draw:
LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame LDA $0DC0, X : CLC : ADC $0D90, X : TAY;Animation Frame
LDA .start_index, Y : STA $06 LDA .start_index, Y : STA $06
PHX PHX
LDX .nbr_of_tiles, Y ;amount of tiles -1 LDX .nbr_of_tiles, Y ;amount of tiles -1
LDY.b #$00 LDY.b #$00