Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sonic_HomingAttack:
- tst.w $3a(a0) ; Check if target has been set (AKA target is not zero)
- beq.s Sonic_HomingAttack_NoTarget ; If target is not set, branch
- cmpi.w #$FFFF, $3a(a0) ; Is special target
- beq.s Sonic_HomingAttack_Dash ; If so, execute airdash
- bra.s Sonic_HomingAttack_Home ; Home into target otherwise
- Sonic_HomingAttack_NoTarget:
- andi.b #btnA, (v_jpadpress1).w
- beq.s Sonic_HomingAttack_Ret
- move.w #$FFFF, $3a(a0)
- move.w v_lvlobjspace, a1
- btst.b #$00, $22(a0) ; Is facing left?
- beq.s .init_left ; If so, branch
- move.w #$8000, d1 ; Initialise
- bra.s Sonic_HomingAttack_Loop_Targets
- .init_left:
- move.w #$7FFF, d1 ; Initialise
- Sonic_HomingAttack_Loop_Targets:
- cmpi.w #$F000, a1 ; Is iteration at the end?
- bge.w Sonic_HomingAttack_Ret ; If so, branch
- btst.b #$00, $22(a0) ; Is facing left?
- beq.s Sonic_HomingAttack_Target_Left ; If so, branch
- ;;; Case: Sonic is facing right!
- move.w obX(a1), d2 ; Save current object X position
- cmp.w d1, d2 ; Is current X smaller than previous
- bge.s Sonic_HomingAttack_Loop_Targets ; If not, branch
- move.w a1, $3a(a0) ; Safe the new target
- move.w d2, d1
- ;;; Case ends
- Sonic_HomingAttack_Target_Loop_Increment:
- addi.w #$40, a1 ; Increment pointer
- bra.s Sonic_HomingAttack_Loop_Targets
- Sonic_HomingAttack_Target_Left:
- move.w obX(a1), d2 ; Save current object X position
- cmp.w d1, d2 ; Is current X smaller than the previous (Because of how sign works, is it bigger)
- bcs.s Sonic_HomingAttack_Loop_Targets ; If not, branch
- move.w a1, $3a(a0) ; Safe the new target
- move.w d2, d1
- bra.s Sonic_HomingAttack_Target_Loop_Increment ; Return Back to loop
- Sonic_HomingAttack_Ret:
- rts
- Sonic_HomingAttack_Dash: ; Airdash
- move.w #$0000, $3a(a0) ; Unset target
- move.w #$FFF, obVelX(a0) ; TODO - FIX ME
- bra.s Sonic_HomingAttack_Ret ; Return
- Sonic_HomingAttack_Home: ; Actual homing part
- move.l #$FFFF0000, a1
- move.w $3a(a0), a1 ; Initialise a1
- move.w obX(a1), d1 ; Do some arithmetic
- move.w obY(a1), d2
- sub.w obX(a0), d1
- sub.w obY(a0), d2
- jsr (CalcAngle).l
- jsr (CalcSine).l ; Some amazing maths going on :)
- muls.w #-$700, d1
- asr.l #8, d1
- move.w d1, obVelX(a0) ; Make Sonic home in
- muls.w #-$700, d0
- asr.l #8, d0
- move.w d0, obVelY(a0) ; Make Sonic home in
- bra.s Sonic_HomingAttack_Ret ; Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement