Update sprite functions, remove Sprite_BounceOffWall

This commit is contained in:
scawful
2025-01-06 17:51:54 -05:00
parent 1b9ce3e0fb
commit 5177cdfd63
4 changed files with 118 additions and 211 deletions

View File

@@ -1,9 +1,9 @@
; =========================================================
; return carry set if active
; Deactivates the sprite in certain situations
Sprite_CheckActive:
{
; Deactivates the sprite in certain situations
LDA.w SprState, X : CMP.b #$09 : BNE .inactive
LDA.w SprFreeze : BNE .inactive
LDA $11 : BNE .inactive
@@ -18,47 +18,34 @@ Sprite_CheckActive:
}
; =========================================================
; make the sprite move X axis
Sprite_MoveHoriz:
{
LDA.w SprXSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL
CLC : ADC.w SprXRound, X : STA.w SprXRound, X
ASL #4 : CLC : ADC.w SprXRound, X : STA.w SprXRound, X
LDY.b #$00
LDA.w SprXSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP
BPL ++
PHP : LSR #4 : PLP : BPL ++
ORA.b #$F0
DEY
++ ADC.w SprX, X : STA.w SprX, X
++
ADC.w SprX, X : STA.w SprX, X
TYA : ADC.w SprXH, X : STA.w SprXH, X
.no_velocity
RTL
}
; =========================================================
; make the sprite move both directions (also height)
Sprite_MoveXyz:
JSL Sprite_MoveAltitude
Sprite_Move:
JSL Sprite_MoveHoriz
; no RTL, just continue into Sprite_MoveVert
; =========================================================
; make the sprite move Y axis
Sprite_MoveVert:
{
LDA.w SprYSpeed, X : BEQ .no_velocity
ASL : ASL : ASL : ASL
CLC : ADC.w SprYRound, X : STA.w SprYRound, X
LDY.b #$00
LDA.w SprYSpeed, X
PHP : LSR : LSR : LSR : LSR : PLP
@@ -74,27 +61,19 @@ Sprite_MoveVert:
RTL
}
; =========================================================
; make the sprite move Z axis (height)
Sprite_MoveZ:
Sprite_MoveAltitude:
{
LDA.w SprTimerF, X : ASL : ASL : ASL : ASL
LDA.w SprTimerF, X : ASL #4
CLC : ADC.w SprHeightS, X : STA.w SprHeightS, X
LDA.w SprTimerF, X : PHP
LSR : LSR : LSR : LSR
PLP : BPL .positive
LDA.w SprTimerF, X : PHP : LSR #4 : PLP : BPL .positive
ORA.b #$F0
.positive
ADC.w SprHeight, X : STA.w SprHeight, X
RTL
}
; =========================================================
; make the sprite bounce toward player
; movement, collision are handled by this function
; $09 = speed, $08 = max height ( e.g. height:20 = vitreous)
@@ -138,40 +117,25 @@ Sprite_BounceFromTileCollision:
{
JSL Sprite_CheckTileCollision : AND.b #$03 : BEQ ++
LDA.w SprXSpeed, X : EOR.b #$FF : INC : STA.w SprXSpeed, X
++ LDA.w SprCollision, X : AND.b #$0C : BEQ ++
++
LDA.w SprCollision, X : AND.b #$0C : BEQ ++
LDA.w SprYSpeed, X : EOR.b #$FF : INC : STA.w SprYSpeed, X
++ RTL
}
; =========================================================
Sprite_BounceOffWall:
LDA.w SprCollision, X : AND.b #$03 : BEQ .no_horizontal_collision
JSL Sprite_InvertSpeed_X
.no_horizontal_collision
LDA.w SprCollision, X : AND.b #$0C : BEQ .no_vertical_collision
JSL Sprite_InvertSpeed_Y
.no_vertical_collision
++
RTL
; =========================================================
}
Sprite_InvertSpeed_XY:
JSL Sprite_InvertSpeed_Y
Sprite_InvertSpeed_X:
LDA.w SprXSpeed, X
EOR.b #$FF
INC A
EOR.b #$FF : INC A
STA.w SprXSpeed, X
RTL
Sprite_InvertSpeed_Y:
LDA.w SprYSpeed, X
EOR.b #$FF
INC A
EOR.b #$FF : INC A
STA.w SprYSpeed, X
RTL
@@ -651,48 +615,40 @@ Sprite_ApplySpeedTowardsPlayerXOrY:
{
JSL Sprite_IsBelowPlayer : BEQ .player_below
;playerAbove
REP #$20
; if link.y is 6 above sprite.y it is considered below
LDA.w SprCachedY : SEC : SBC $20 : CLC : ADC.w #$0006 : STA $01 ;delta Y
SEP #$20
JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_Right1
JSL Sprite_IsToRightOfPlayer : BEQ .player_to_the_right1
;player_to_the_Left
REP #$20
LDA.w SprCachedX : SEC : SBC $22 ; delta X
CMP $01 : BCS .XGreaterThanY1
REP #$20 ; delta X
LDA.w SprCachedX : SEC : SBC $22 : CMP $01 : BCS .XGreaterThanY1
;YGreaterThanX
SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed
STZ.w SprXSpeed
RTL
.XGreaterThanY1
SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprXSpeed
STZ.w SprYSpeed
RTL
.player_to_the_Right1
REP #$20
LDA $22 : SEC : SBC.w SprCachedX ; delta X
CMP $01 : BCS .XGreaterThanY2
.player_to_the_right1
REP #$20 ; delta X
LDA $22 : SEC : SBC.w SprCachedX : CMP $01 : BCS .XGreaterThanY2
;YGreaterThanX
SEP #$20
LDA.b #$00 : SEC : SBC $00 : STA.w SprYSpeed
STZ.w SprXSpeed
RTL
.XGreaterThanY2
SEP #$20
LDA.b #$00 : CLC : ADC $00 : STA.w SprXSpeed
STZ.w SprYSpeed
RTL
.player_below
REP #$20
; if link.y is 6 above sprite.y it is considered below
@@ -717,12 +673,9 @@ Sprite_ApplySpeedTowardsPlayerXOrY:
STZ.w SprYSpeed
RTL
.player_to_the_Right2
REP #$20
LDA $22 : SEC : SBC.w SprCachedX ; delta X
CMP $01 : BCS .XGreaterThanY4
REP #$20 ; delta X
LDA $22 : SEC : SBC.w SprCachedX : CMP $01 : BCS .XGreaterThanY4
;YGreaterThanX
SEP #$20
LDA.b #$00 : CLC : ADC $00 : STA.w SprYSpeed
@@ -762,7 +715,6 @@ GetDistance8bit_Long:
Sprite_CheckIfRecoiling:
{
PHB : PHK : PLB
LDA.w $0EA0, X : BEQ .exit
AND.b #$7F : BEQ .recoil_over
LDA.w SprYSpeed, X
@@ -784,11 +736,8 @@ Sprite_CheckIfRecoiling:
TAY
LDA.b $1A : AND.w .masks, Y : BNE .no_movement
LDA.w SprYRecoil, X : STA.w SprYSpeed, X
LDA.w SprXRecoil, X : STA.w SprXSpeed, X
LDA.w SprBump, X : BMI .handle_movement
JSL Sprite_CheckTileCollision_long

View File

@@ -56,6 +56,14 @@ macro sta_x(...)
%loop(STA.w, ..., X)
endmacro
macro mode16()
REP #$30
endmacro
macro mode8()
SEP #$30
endmacro
macro accum16()
REP #$20
endmacro
@@ -91,26 +99,6 @@ macro JumpTable(index, ...)
endwhile
endmacro
macro SetMode(bit_mode)
if <bit_mode> == "16bit"
REP #$30
elseif <bit_mode> == "8bit"
SEP #$30
endif
endmacro
macro ScopedMode(bit_mode, body)
if <bit_mode> == "16bit"
%SetMode("16bit")
<body>
%SetMode("8bit")
elseif <bit_mode> == "8bit"
%SetMode("8bit")
<body>
%SetMode("16bit")
endif
endmacro
macro SpriteJumpTable(...)
LDA.w SprAction, X
JSL JumpTableLocal
@@ -123,34 +111,24 @@ macro SpriteJumpTable(...)
endmacro
macro SetFlag(flag_addr, bit_pos)
LDA.b flag_addr
ORA.b #(1 << bit_pos)
STA.b flag_addr
LDA.b flag_addr : ORA.b #(1 << bit_pos) : STA.b flag_addr
endmacro
macro ClearFlag(flag_addr, bit_pos)
LDA.b flag_addr
AND.b #~(1 << bit_pos)
STA.b flag_addr
LDA.b flag_addr : AND.b #~(1 << bit_pos) : STA.b flag_addr
endmacro
macro ToggleFlag(flag_addr, bit_pos)
LDA.b flag_addr
EOR.b #(1 << bit_pos)
STA.b flag_addr
LDA.b flag_addr : EOR.b #(1 << bit_pos) : STA.b flag_addr
endmacro
macro CheckFlag(flag_addr, bit_pos, set_label, clear_label)
LDA.b flag_addr
AND.b #(1 << bit_pos)
BEQ clear_label
LDA.b flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label
BRA set_label
endmacro
macro CheckFlagLong(flag_addr, bit_pos, set_label, clear_label)
LDA.l flag_addr
AND.b #(1 << bit_pos)
BEQ clear_label
LDA.l flag_addr : AND.b #(1 << bit_pos) : BEQ clear_label
BRA set_label
endmacro
@@ -158,6 +136,7 @@ endmacro
; reset to (frame_start) when reaching (frame_end)
; This is using SprTimerB
macro PlayAnimation(frame_start, frame_end, frame_wait)
{
LDA.w SprTimerB, X : BNE +
LDA.w SprFrame, X : INC : STA.w SprFrame, X
CMP.b #<frame_end>+1 : BCC .noframereset
@@ -165,6 +144,7 @@ macro PlayAnimation(frame_start, frame_end, frame_wait)
.noframereset
LDA.b #<frame_wait> : STA.w SprTimerB, X
+
}
endmacro
macro PlayAnimBackwards(frame_start, frame_end, frame_wait)
@@ -183,7 +163,6 @@ macro StartOnFrame(frame)
+
endmacro
; Show message if the player is facing toward sprite and pressing A
; Return Carry Set if message is displayed
; can use BCC .label <> .label to see if message have been displayed
@@ -254,16 +233,6 @@ macro AllowPlayerMovement()
STZ.w $02E4
endmacro
; Enter 16bit mode
macro Set16bitmode()
REP #$30
endmacro
; Enter 8bit mode
macro Set8bitmode()
SEP #$30
endmacro
; This is a 16 bit will load A with current rupee count
; to use with instructions CMP and BCC/BCS
macro GetPlayerRupees()
@@ -282,47 +251,38 @@ macro SetSpriteSpeedX(speed)
LDA.b #<speed> : STA.w SprXSpeed, x
endmacro
; Will play a sound SFX 1 See Zelda_3_RAM.log for more informations
macro PlaySFX1(sfxid)
LDA.b #<sfxid> : STA $012E
endmacro
; Will play a sound SFX 2 See Zelda_3_RAM.log for more informations
macro PlaySFX2(sfxid)
LDA.b #<sfxid> : STA $012F
endmacro
; Will play a music See Zelda_3_RAM.log for more informations
macro PlayMusic(musicid)
LDA.b #<musicid> : STA $012C
endmacro
; Will set the timer A to wait (length) amount of frames
macro SetTimerA(length)
LDA.b #<length> : STA.w SprTimerA, X
endmacro
; Will set the timer B to wait (length) amount of frames
macro SetTimerB(length)
LDA.b #<length> : STA.w SprTimerB, X
endmacro
; Will set the timer C to wait (length) amount of frames
macro SetTimerC(length)
LDA.b #<length> : STA.w SprTimerC, X
endmacro
; Will set the timer D to wait (length) amount of frames
macro SetTimerD(length)
LDA.b #<length> : STA.w SprTimerD, X
endmacro
; Will set the timer E to wait (length) amount of frames
macro SetTimerE(length)
LDA.b #<length> : STA.w SprTimerE, X
endmacro
; Will set the timer F to wait (length) amount of frames
macro SetTimerF(length)
LDA.b #<length> : STA.w SprTimerF, X
endmacro

View File

@@ -78,7 +78,6 @@ Sprite_Puffstool_Main:
+
JSL Sprite_MoveXyz
JSL Sprite_BounceFromTileCollision
JSL Sprite_BounceOffWall
JSL Sprite_DamageFlash_Long
JSL ThrownSprite_TileAndSpriteInteraction_long
JSL Sprite_CheckIfRecoiling

View File

@@ -115,7 +115,6 @@ Sprite_Piratian_Move:
JSL Sprite_MoveXyz
JSL Sprite_BounceFromTileCollision
JSL Sprite_BounceOffWall
JSL Sprite_DamageFlash_Long
JSL ThrownSprite_TileAndSpriteInteraction_long