cleanup minecart and switch track

This commit is contained in:
scawful
2024-07-04 15:42:12 -04:00
parent 9f0f17ebf3
commit 3f9fad8c7f
2 changed files with 194 additions and 245 deletions

View File

@@ -248,8 +248,8 @@ HandleTossedCart:
Sprite_Minecart_Main: Sprite_Minecart_Main:
{ {
LDA.w SprAction, X ; Load the SprAction LDA.w SprAction, X
JSL UseImplicitRegIndexedLocalJumpTable ; Goto the SprAction JSL UseImplicitRegIndexedLocalJumpTable
dw Minecart_WaitHoriz ; 0x00 dw Minecart_WaitHoriz ; 0x00
dw Minecart_WaitVert ; 0x01 dw Minecart_WaitVert ; 0x01
@@ -263,34 +263,35 @@ Sprite_Minecart_Main:
; 0x00 ; 0x00
Minecart_WaitHoriz: Minecart_WaitHoriz:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
LDA SprTimerA, X : BNE .not_ready LDA SprTimerA, X : BNE .not_ready
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
JSR CheckIfPlayerIsOn : BCC .not_ready JSR CheckIfPlayerIsOn : BCC .not_ready
LDA.w SprMiscF, X : BNE .active_cart LDA.w SprMiscF, X : BNE .active_cart
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
.active_cart .active_cart
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
LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos
LDA #$01 : STA !LinkInCart ; Set Link in cart flag LDA #$01 : STA !LinkInCart ; Set Link in cart flag
; Check if the cart is facing east or west ; Check if the cart is facing east or west
LDA SprSubtype, X : CMP.b #$03 : BNE .opposite_direction LDA SprSubtype, X : CMP.b #$03 : BNE .opposite_direction
STA.w !MinecartDirection STA.w !MinecartDirection
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 HandleLiftAndToss JSR HandleLiftAndToss
JSL ThrownSprite_TileAndSpriteInteraction_long
RTS RTS
} }
@@ -298,34 +299,35 @@ Sprite_Minecart_Main:
; 0x01 ; 0x01
Minecart_WaitVert: Minecart_WaitVert:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
LDA SprTimerA, X : BNE .not_ready LDA SprTimerA, X : BNE .not_ready
LDA !LinkCarryOrToss : AND #$03 : BNE .lifting
JSR CheckIfPlayerIsOn : BCC .not_ready JSR CheckIfPlayerIsOn : BCC .not_ready
LDA.w SprMiscF, X : BNE .active_cart LDA.w SprMiscF, X : BNE .active_cart
LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button LDA $F4 : AND.b #$80 : BEQ .not_ready ; Check for B button
.active_cart .active_cart
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
LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos LDA $0FDA : SEC : SBC #$0B : STA $20 ; Adjust player pos
LDA #$01 : STA !LinkInCart ; Set Link in cart flag LDA #$01 : STA !LinkInCart ; Set Link in cart flag
; Check if the cart is facing north or south ; Check if the cart is facing north or south
LDA SprSubtype, X : BEQ .opposite_direction LDA SprSubtype, X : BEQ .opposite_direction
STA.w !MinecartDirection STA.w !MinecartDirection
LDA #$01 : STA !SpriteDirection, X LDA #$01 : STA !SpriteDirection, X
%GotoAction(4) ; Minecart_MoveSouth %GotoAction(4) ; Minecart_MoveSouth
RTS RTS
.opposite_direction .opposite_direction
STA.w !MinecartDirection STA.w !MinecartDirection
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 HandleLiftAndToss JSR HandleLiftAndToss
JSL ThrownSprite_TileAndSpriteInteraction_long
RTS RTS
} }
@@ -333,100 +335,100 @@ Sprite_Minecart_Main:
; 0x02 ; 0x02
Minecart_MoveNorth: Minecart_MoveNorth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%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 .continue
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA.w SprYSpeed, X LDA.b #-!DoubleSpeed : STA.w SprYSpeed, X
.continue .continue
JSL Sprite_MoveVert JSL Sprite_MoveVert
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x03 ; 0x03
Minecart_MoveEast: Minecart_MoveEast:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%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 .continue
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA $0D50, X LDA.b #!DoubleSpeed : STA $0D50, X
.continue .continue
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x04 ; 0x04
Minecart_MoveSouth: Minecart_MoveSouth:
{ {
%PlayAnimation(2,3,8) %PlayAnimation(2,3,8)
%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 .continue
.fast_speed .fast_speed
LDA.b #!DoubleSpeed : STA.w SprYSpeed, X LDA.b #!DoubleSpeed : STA.w SprYSpeed, X
.continue .continue
JSL Sprite_MoveVert JSL Sprite_MoveVert
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
; ------------------------------------------------------- ; -------------------------------------------------------
; 0x05 ; 0x05
Minecart_MoveWest: Minecart_MoveWest:
{ {
%PlayAnimation(0,1,8) %PlayAnimation(0,1,8)
%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 .continue
.fast_speed .fast_speed
LDA.b #-!DoubleSpeed : STA $0D50, X LDA.b #-!DoubleSpeed : STA $0D50, X
.continue .continue
JSL Sprite_MoveHoriz JSL Sprite_MoveHoriz
; Get direction of the cart (0 to 3) ; Get direction of the cart (0 to 3)
LDY.w !SpriteDirection, X LDY.w !SpriteDirection, X
JSL DragPlayer JSL DragPlayer
JSR CheckForPlayerInput JSR CheckForPlayerInput
%HandlePlayerCamera() %HandlePlayerCamera()
%MoveCart() %MoveCart()
RTS RTS
} }
@@ -434,26 +436,25 @@ Sprite_Minecart_Main:
; 0x06 ; 0x06
Minecart_Release: Minecart_Release:
{ {
%StopCart() %StopCart()
LDA SprTimerD, X : BNE .not_ready LDA SprTimerD, X : BNE .not_ready
LDA #$40 : STA.w SprTimerA, X LDA #$40 : STA.w SprTimerA, X
LDA.w !SpriteDirection, X : CMP.b #$00 : BEQ .vert LDA.w !SpriteDirection, X : CMP.b #$00 : BEQ .vert
CMP.b #$02 : BEQ .vert CMP.b #$02 : BEQ .vert
JMP .horiz JMP .horiz
.vert .vert
%GotoAction(1) ; Minecart_WaitVert %GotoAction(1) ; Minecart_WaitVert
RTS
.horiz
%GotoAction(0)
.not_ready
RTS RTS
.horiz
%GotoAction(0)
.not_ready
RTS
} }
} }
; ========================================================= ; =========================================================
HandleTileDirections: HandleTileDirections:
{ {
LDA SprTimerA, X : BEQ + LDA SprTimerA, X : BEQ +
@@ -616,18 +617,6 @@ HandleTileDirections:
db $00, $02, $00, $04 ; South db $00, $02, $00, $04 ; South
db $03, $01, $00, $00 ; West 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
}
} }
; ========================================================= ; =========================================================
@@ -636,61 +625,51 @@ HandleTileDirections:
HandleDynamicSwitchTileDirections: HandleDynamicSwitchTileDirections:
{ {
; Find out if the sprite $B0 is in the room ; Find out if the sprite $B0 is in the room
JSR CheckSpritePresence : BCC .no_b0 JSR CheckSpritePresence : BCC .no_b0
PHX
LDA $02 : TAX
JSL Link_SetupHitBox
JSL Sprite_SetupHitBox ; X is now the ID of the sprite $B0
PLX
JSL CheckIfHitBoxesOverlap : BCC .no_b0
LDA !MinecartDirection : CMP.b #$00 : BEQ .east_or_west
CMP.b #$01 : BEQ .north_or_south
CMP.b #$02 : BEQ .east_or_west
CMP.b #$03 : BEQ .north_or_south
.no_b0
RTS
PHX : LDA $02 : TAX .east_or_west
JSL Link_SetupHitBox LDA SwitchRam : BNE .go_west
LDA #$01 : STA.w SprSubtype, X
STA.w !MinecartDirection
LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast
RTS
; X is now the ID of the sprite $B0 .go_west
JSL Sprite_SetupHitBox LDA #$03 : STA.w SprSubtype, X
PLX STA.w !MinecartDirection
LDA #$02 : STA !SpriteDirection, X
JSL CheckIfHitBoxesOverlap : BCC .no_b0 %GotoAction(5) ; Minecart_MoveWest
RTS
LDA !MinecartDirection : CMP.b #$00 : BEQ .east_or_west
CMP.b #$01 : BEQ .north_or_south
CMP.b #$02 : BEQ .east_or_west
CMP.b #$03 : BEQ .north_or_south
.no_b0
RTS
.east_or_west
LDA SwitchRam : BNE .go_west
LDA #$01 : STA.w SprSubtype, X
STA.w !MinecartDirection
LDA #$03 : STA !SpriteDirection, X
%GotoAction(3) ; Minecart_MoveEast
; LDA SprY, X : AND #$F8 : STA.w SprY, X
RTS
.go_west
LDA #$03 : STA.w SprSubtype, X
STA.w !MinecartDirection
LDA #$02 : STA !SpriteDirection, X
%GotoAction(5) ; Minecart_MoveWest
; LDA SprY, X : AND #$F8 : STA.w SprY, X
RTS
.north_or_south
LDA SwitchRam : BNE .go_south
LDA #$00 : STA.w SprSubtype, X
STA.w !MinecartDirection
STA !SpriteDirection, X
%GotoAction(2) ; Minecart_MoveNorth
; LDA SprX, X : AND #$F8 : STA.w SprX, X
RTS
.go_south
LDA #$02 : STA.w SprSubtype, X
STA.w !MinecartDirection
LDA #$01 : STA !SpriteDirection, X
%GotoAction(4) ; Minecart_MoveSouth
; LDA SprX, X : AND #$F8 : STA.w SprX, X
RTS
.north_or_south
LDA SwitchRam : BNE .go_south
LDA #$00 : STA.w SprSubtype, X
STA.w !MinecartDirection
STA !SpriteDirection, X
%GotoAction(2) ; Minecart_MoveNorth
RTS
.go_south
LDA #$02 : STA.w SprSubtype, X
STA.w !MinecartDirection
LDA #$01 : STA !SpriteDirection, X
%GotoAction(4) ; Minecart_MoveSouth
RTS
} }
; ========================================================= ; =========================================================
@@ -786,21 +765,20 @@ CheckForPlayerInput:
CheckIfPlayerIsOn: CheckIfPlayerIsOn:
{ {
REP #$20 REP #$20
LDA $22 : CLC : ADC #$0009 : CMP $0FD8 : BCC .left LDA $22 : CLC : ADC #$0009 : CMP $0FD8 : BCC .left
LDA $22 : SEC : SBC #$0009 : CMP $0FD8 : BCS .right LDA $22 : SEC : SBC #$0009 : CMP $0FD8 : BCS .right
LDA $20 : CLC : ADC #$0012 : CMP $0FDA : BCC .up
LDA $20 : CLC : ADC #$0012 : CMP $0FDA : BCC .up LDA $20 : SEC : SBC #$0012 : CMP $0FDA : BCS .down
LDA $20 : SEC : SBC #$0012 : CMP $0FDA : BCS .down SEP #$21
RTS ; Return with carry set
SEP #$21 : RTS ; Return with carry set
.left .left
.right .right
.up .up
.down .down
SEP #$20 SEP #$20
CLC : RTS ; Return with carry cleared CLC
RTS ; Return with carry cleared
} }
@@ -852,19 +830,16 @@ FollowerDraw_CalculateOAMCoords:
LDA.b $02 : STA.b ($90),Y LDA.b $02 : STA.b ($90),Y
INY INY
CLC : ADC.w #$0080 CLC : ADC.w #$0080 : CMP.w #$0180 : BCS .off_screen
CMP.w #$0180 : BCS .off_screen LDA.b $02 : AND.w #$0100 : STA.b $74
LDA.b $00 : STA.b ($90),Y
LDA.b $02 : AND.w #$0100 : STA.b $74 CLC : ADC.w #$0010 : CMP.w #$0100 : BCC .on_screen
LDA.b $00 : STA.b ($90),Y
CLC : ADC.w #$0010 .off_screen:
CMP.w #$0100 : BCC .on_screen
.off_screen:
LDA.w #$00F0 : STA.b ($90),Y LDA.w #$00F0 : STA.b ($90),Y
.on_screen: .on_screen:
SEP #$20 SEP #$20
INY INY
RTS RTS

View File

@@ -3,7 +3,7 @@
; ========================================================= ; =========================================================
!SPRID = $B0 ; The sprite ID you are overwriting (HEX) !SPRID = $B0 ; The sprite ID you are overwriting (HEX)
!NbrTiles = 04 ; Number of tiles used in a frame !NbrTiles = 02 ; Number of tiles used in a frame
!Harmless = 00 ; 00 = Sprite is Harmful, 01 = Sprite is Harmless !Harmless = 00 ; 00 = Sprite is Harmful, 01 = Sprite is Harmless
!HVelocity = 00 ; Is your sprite going super fast? put 01 if it is !HVelocity = 00 ; Is your sprite going super fast? put 01 if it is
!Health = 01 ; Number of Health the sprite have !Health = 01 ; Number of Health the sprite have
@@ -13,7 +13,7 @@
!SmallShadow = 00 ; 01 = small shadow, 00 = no shadow !SmallShadow = 00 ; 01 = small shadow, 00 = no shadow
!Shadow = 00 ; 00 = don't draw shadow, 01 = draw a shadow !Shadow = 00 ; 00 = don't draw shadow, 01 = draw a shadow
!Palette = 00 ; Unused in this template (can be 0 to 7) !Palette = 00 ; Unused in this template (can be 0 to 7)
!Hitbox = $1C ; 00 to 31, can be viewed in sprite draw tool !Hitbox = 00 ; 00 to 31, can be viewed in sprite draw tool
!Persist = 01 ; 01 = your sprite continue to live offscreen !Persist = 01 ; 01 = your sprite continue to live offscreen
!Statis = 00 ; 00 = is sprite is alive?, (kill all enemies room) !Statis = 00 ; 00 = is sprite is alive?, (kill all enemies room)
!CollisionLayer = 00 ; 01 = will check both layer for collision !CollisionLayer = 00 ; 01 = will check both layer for collision
@@ -87,11 +87,9 @@ Sprite_RotatingTrack_Main:
; 00 = TopLeft -> TopRight ; 00 = TopLeft -> TopRight
TopLeftToTopRight: TopLeftToTopRight:
{ {
LDA SwitchRam : BEQ part2 LDA SwitchRam : BNE part2
%PlayAnimation(0,0,4)
%PlayAnimation(0,0,4) part2:
part2:
%PlayAnimation(1,1,4) %PlayAnimation(1,1,4)
RTS RTS
} }
@@ -101,10 +99,8 @@ Sprite_RotatingTrack_Main:
TopRightToBottomRight: TopRightToBottomRight:
{ {
LDA SwitchRam : BNE part2_a LDA SwitchRam : BNE part2_a
%PlayAnimation(1,1,4)
%PlayAnimation(1,1,4) part2_a:
part2_a:
%PlayAnimation(2,2,4) %PlayAnimation(2,2,4)
RTS RTS
} }
@@ -114,24 +110,19 @@ Sprite_RotatingTrack_Main:
BottomRightToBottomLeft: BottomRightToBottomLeft:
{ {
LDA SwitchRam : BNE part2_b LDA SwitchRam : BNE part2_b
%PlayAnimation(2,2,4)
%PlayAnimation(2,2,4) part2_b:
part2_b: %PlayAnimation(3,3,4)
RTS
%PlayAnimation(3,3,4) }
RTS
}
; ------------------------------------------------------- ; -------------------------------------------------------
; 03 = BottomLeft -> TopLeft ; 03 = BottomLeft -> TopLeft
BottomLeftToTopLeft: BottomLeftToTopLeft:
{ {
LDA SwitchRam : BNE part2_c LDA SwitchRam : BNE part2_c
%PlayAnimation(3,3,4)
%PlayAnimation(3,3,4) part2_c:
part2_c:
%PlayAnimation(0,0,4) %PlayAnimation(0,0,4)
RTS RTS
} }
@@ -141,15 +132,13 @@ Sprite_RotatingTrack_Main:
TopRightToTopLeft: TopRightToTopLeft:
{ {
LDA SwitchRam : BNE part2_d LDA SwitchRam : BNE part2_d
%StartOnFrame(1)
%StartOnFrame(1) %PlayAnimation(1,1,4)
%PlayAnimation(1,1,4) part2_d:
%StartOnFrame(0)
part2_d: %PlayAnimation(0,0,4)
%StartOnFrame(0) RTS
%PlayAnimation(0,0,4) }
RTS
}
} }
; ========================================================= ; =========================================================
@@ -178,10 +167,10 @@ Sprite_RotatingTrack_Draw:
REP #$20 REP #$20
LDA $00 : CLC : ADC .x_offsets, X : STA ($90), Y LDA $00 : STA ($90), Y
AND.w #$0100 : STA $0E AND.w #$0100 : STA $0E
INY INY
LDA $02 : CLC : ADC .y_offsets, X : STA ($90), Y LDA $02 : STA ($90), Y
CLC : ADC #$0010 : CMP.w #$0100 CLC : ADC #$0010 : CMP.w #$0100
SEP #$20 SEP #$20
BCC .on_screen_y BCC .on_screen_y
@@ -200,7 +189,7 @@ Sprite_RotatingTrack_Draw:
TYA : LSR #2 : TAY TYA : LSR #2 : TAY
LDA .sizes, X : ORA $0F : STA ($92), Y ; store size in oam buffer LDA.b #$02 : ORA $0F : STA ($92), Y ; store size in oam buffer
PLY : INY PLY : INY
@@ -215,16 +204,6 @@ Sprite_RotatingTrack_Draw:
db $00, $01, $02, $03 db $00, $01, $02, $03
.nbr_of_tiles .nbr_of_tiles
db 0, 0, 0, 0 db 0, 0, 0, 0
.x_offsets
dw 0
dw 0
dw 0
dw 0
.y_offsets
dw 0
dw 0
dw 0
dw 0
.chr .chr
db $44 db $44
db $44 db $44
@@ -235,9 +214,4 @@ Sprite_RotatingTrack_Draw:
db $3D db $3D
db $FD db $FD
db $BD db $BD
.sizes
db $02
db $02
db $02
db $02
} }