In this method we will use the Intercept theorem to execute the Homing Attack. For more information about the Intercept theorem visit: http://en.wikipedia.org/wiki/Intercept_theorem#Similarity_and_similar_Triangles
This method don't use CalcAngle and CalcSine, and the effect is exactly the same.

If you want download the compiled ROM, download here: http://goo.gl/lOJLM
To apply this, you need first apply the Homing Attack in Sonic 1.
And implement in your code the square root subroutine.
In HA_Move, modify this:
This method don't use CalcAngle and CalcSine, and the effect is exactly the same.

If you want download the compiled ROM, download here: http://goo.gl/lOJLM
To apply this, you need first apply the Homing Attack in Sonic 1.
And implement in your code the square root subroutine.
In HA_Move, modify this:
- Code:
jsr (CalcAngle).l ; calculates the angle
jsr (CalcSine).l ; calculates the sine and the cosine
muls.w #$C,d1 ; multiply cosine by $C
move.w d1,$10(a0) ; move d1 to X-velocity
muls.w #$C,d0 ; multiply sine by $C
move.w d0,$12(a0) ; move d0 to Y-velocity
- Code:
move.w d1,d0 ; copy x-distance to d0
move.w d2,d3 ; copy y-distance to d3
muls.w d0,d0 ; x-distance^2
muls.w d3,d3 ; y-distance^2
add.l d3,d0 ; x^2 + y^2 = H^2
jsr SquareRoot ; square root of H^2
; 255 = Real Speed // 12 = Sonic's Speed Constant
muls.w #255*12,d1 ; X*delta
muls.w #255*12,d2 ; Y*delta
; divide to fix the problem of "speed by distance" (near = slow, far = fast)
divs.w d0,d1 ; X'/H
divs.w d0,d2 ; Y'/H
; the gravity can make changes (+5 or -5) in Real Speed
move.w d1,$10(a0) ; move d1 to X-velocity
move.w d2,$12(a0) ; move d0 to Y-velocity