Changed the switch tracks to allow for more than just one switch

This commit is contained in:
Jared_Brian_
2025-02-08 11:55:46 -07:00
parent 717d9fb108
commit 7f3fbad7ae
3 changed files with 113 additions and 70 deletions

View File

@@ -127,8 +127,6 @@ Sprite_Minecart_Long:
{
PHB : PHK : PLB
print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: ", pc
JSR Sprite_Minecart_DrawTop ; Draw behind Link
JSR Sprite_Minecart_DrawBottom ; Draw in front of Link
@@ -976,13 +974,17 @@ CheckForCornerTiles:
HandleDynamicSwitchTileDirections:
{
; Check for the switch tile.
LDA.w SPRTILE : CMP.b #$BF : BEQ .onSwitchTile
LDA.w SPRTILE : CMP.b #$D0 : BEQ .onSwitchTile
CMP.b #$D1 : BEQ .onSwitchTile
CMP.b #$D2 : BEQ .onSwitchTile
CMP.b #$D3 : BEQ .onSwitchTile
CLC
RTS
.onSwitchTile
; Find out if the sprite $B0 is in the room.
JSR CheckSpritePresence : BCS .B0Present
; Find out if the sprite $B0 is in the room and if we are
; currently touching it.
JSR CheckTrackSpritePresence : BCS .B0Present
CLC
RTS
.B0Present
@@ -991,15 +993,16 @@ HandleDynamicSwitchTileDirections:
ASL #3 ; Multiply by 8 to offset rows in the lookup table
STA.b $07 ; Store the action index in $07
; Get the type (TL, BL, TR, BL) of the track by taking the subtype and
; cutting out the extra data. Then x2 so we get the correct data from
; the table.
LDY.b $04
LDA.w SprSubtype, Y : AND.b #$18 : LSR #2
; Get the subtype of the track so that we can get its on/off state.
LDA.w SprSubtype, Y : TAY
; Normalize the tile data and get the type of track (TL, BL, TR, BR) and
; x2 so that we can read the correct column in the table.
LDA.w SPRTILE : SEC : SBC.b #$D0 : ASL
; Add the current direction and the state of the switch to determine
; which direction we should go next.
CLC : ADC.b SwitchRam : CLC : ADC.b $07 : TAY
CLC : ADC.w SwitchRam, Y : CLC : ADC.b $07 : TAY
LDA.w .DirectionTileLookup, Y
CMP.b #$01 : BEQ .move_north
CMP.b #$02 : BEQ .move_east
@@ -1047,10 +1050,11 @@ HandleDynamicSwitchTileDirections:
db $03, $00, $01, $03, $00, $00, $00, $01 ; West
}
; TL turns into TR when on.
; TR turns into BR when on.
; BR turns into BL when on.
; BL turns into TL when on.
; $D0 TL turns into TR when on.
; $D1 BL turns into TL when on.
; $D2 TR turns into BR when on.
; $D3 BR turns into BL when on.
}
; Unused?
@@ -1114,22 +1118,30 @@ RoundCoords:
; $04 = sprite index of sprite ID $B0
; SEC if sprite is present.
CheckSpritePresence:
CheckTrackSpritePresence:
{
PHX
CLC ; Assume sprite ID $B0 is not present
LDX.b #$10
.x_loop
DEX
LDA $0E20, X : CMP.b #$B0 : BNE .not_b0
SEC ; Set flag indicating sprite ID $B0 is present
STX.w $04
LDY.b #$10
.loop
DEY
; Check if the sprite is $B0
LDA.w $0E20, Y : CMP.b #$B0 : BNE .not_b0
; Check if the high bytes of the coordinates match.
LDA.w SprYH, X : CMP.w SprYH, Y : BNE .not_b0
LDA.w SprXH, X : CMP.w SprXH, Y : BNE .not_b0
; Check if the low bytes match but round the cart's coordinates.
; Offset the Y by 8 so that we match the cart
LDA.w SprY, X : CLC : ADC.b #$04 : AND.b #$F8 : CLC : ADC.b #$08
CMP.w SprY, Y : BNE .not_b0
LDA.w SprX, X : CLC : ADC.b #$04 : AND.b #$F8
CMP.w SprX, Y : BNE .not_b0
STY.b $04
SEC ; Set flag indicating sprite ID $B0 is present.
BRA .done
.not_b0
CPX.b #$00 : BNE .x_loop
CPY.b #$00 : BNE .loop
CLC ; Assume sprite ID $B0 is not present
.done
PLX
RTS
}

View File

@@ -52,7 +52,11 @@ Sprite_LeverSwitch_Prep:
PHB : PHK : PLB
LDA.b #$00 : STA.w SprDefl, X
LDA.w SwitchRam : STA.w SprAction, X : STA.w SprFrame, X
; Get the subtype of the switch so that we can get its on/off state.
LDA.w SprSubtype, X : TAY
LDA.w SwitchRam, Y : STA.w SprAction, X : STA.w SprFrame, X
LDA.b #$00 : STA.w SprTileDie, X
STZ.w SprBulletproof, X
@@ -81,8 +85,11 @@ Sprite_LeverSwitch_Main:
JSL Sprite_CheckDamageFromPlayer : BCC .NoDamage
LDA #$25 : STA $012F
; Get the subtype of the switch so that we can get its on/off state.
LDA.w SprSubtype, X : TAY
; Turn the switch on.
LDA #$01 : STA.b SwitchRam
LDA #$01 : STA.w SwitchRam, Y
LDA #$10 : STA.w SprTimerA, X
%GotoAction(1)
.NoDamage
@@ -96,8 +103,11 @@ Sprite_LeverSwitch_Main:
JSL Sprite_CheckDamageFromPlayer : BCC .NoDamage
LDA #$25 : STA $012F
; Get the subtype of the switch so that we can get its on/off state.
LDA.w SprSubtype, X : TAY
; Turn the switch off.
STZ.w SwitchRam
LDA #$00 : STA.w SwitchRam, Y
LDA #$10 : STA.w SprTimerA, X
%GotoAction(0)
.NoDamage

View File

@@ -50,7 +50,20 @@ Sprite_RotatingTrack_Prep:
{
PHB : PHK : PLB
LDA.b #$80 : STA.w SprDefl, X
LDA.w SprSubtype, X : AND.b #$18 : LSR #3
; Setup Minecart position to look for tile IDs
; We use AND #$F8 to clamp to a 8x8 grid.
; Subtract 8 from the Y position to get the tile right above instead.
LDA.w SprY, X : AND #$F8 : SEC : SBC.b #$08 : STA.b $00
LDA.w SprYH, X : STA.b $01
LDA.w SprX, X : AND #$F8 : STA.b $02
LDA.w SprXH, X : STA.b $03
; Fetch tile attributes based on current coordinates
LDA.b #$00 : JSL Sprite_GetTileAttr
LDA.w SPRTILE : SEC : SBC.b #$D0 : STA.w SprAction, X
; Run the main frame once so that the animation frame is
; started correctly.
@@ -66,59 +79,67 @@ Sprite_RotatingTrack_Prep:
; 2 = BottomRight -> BottomLeft
; 3 = BottomLeft -> TopLeft
SwitchRam = $37
; The state of each switch. Up to $0250 used which is all free ram.
SwitchRam = $0230
Sprite_RotatingTrack_Main:
{
; Get the subtype of the track so that we can get its on/off state.
LDA.w SprSubtype, X : TAY
LDA.w SprAction, X
JSL UseImplicitRegIndexedLocalJumpTable
dw TopLeftToTopRight
dw BottomLeftToTopLeft
dw TopRightToBottomRight
dw BottomRightToBottomLeft
dw BottomLeftToTopLeft
; -------------------------------------------------------
; 00 = TopLeft -> TopRight
TopLeftToTopRight:
{
LDA.w SwitchRam : BNE part2
%PlayAnimation(0,0,4)
part2:
%PlayAnimation(1,1,4)
LDA.w SwitchRam, Y : BNE .part2
LDA.b #$00 : STA.w SprFrame, X
RTS
.part2
LDA.b #$01 : STA.w SprFrame, X
RTS
}
; -------------------------------------------------------
; 01 = TopRight -> BottomRight
TopRightToBottomRight:
{
LDA.w SwitchRam : BNE part2_a
%PlayAnimation(1,1,4)
part2_a:
%PlayAnimation(2,2,4)
RTS
}
; -------------------------------------------------------
; 02 = BottomRight -> BottomLeft
BottomRightToBottomLeft:
{
LDA.w SwitchRam : BEQ part2_b
%PlayAnimation(2,2,4)
part2_b:
%PlayAnimation(3,3,4)
RTS
}
; -------------------------------------------------------
; 03 = BottomLeft -> TopLeft
; 01 = BottomLeft -> TopLeft
BottomLeftToTopLeft:
{
LDA.w SwitchRam : BNE part2_c
%PlayAnimation(3,3,4)
part2_c:
%PlayAnimation(0,0,4)
LDA.w SwitchRam, Y : BNE .part2_c
LDA.b #$03 : STA.w SprFrame, X
RTS
.part2_c
LDA.b #$00 : STA.w SprFrame, X
RTS
}
; -------------------------------------------------------
; 02 = TopRight -> BottomRight
TopRightToBottomRight:
{
LDA.w SwitchRam, Y : BNE .part2_a
LDA.b #$01 : STA.w SprFrame, X
RTS
.part2_a
LDA.b #$02 : STA.w SprFrame, X
RTS
}
; -------------------------------------------------------
; 03 = BottomRight -> BottomLeft
BottomRightToBottomLeft:
{
LDA.w SwitchRam, Y : BEQ .part2_b
LDA.b #$03 : STA.w SprFrame, X
RTS
.part2_b
LDA.b #$02 : STA.w SprFrame, X
RTS
}
}
@@ -190,10 +211,10 @@ Sprite_RotatingTrack_Draw:
db $44
db $44
.properties
db $0D
db $4D
db $CD
db $8D
db $3D
db $7D
db $FD
db $BD
}
; =========================================================