Angle Question...

BlitzPlus Forums/BlitzPlus Programming/Angle Question...

Hiya all, I have a little problem :)

In the code below, I have a small dot that follows the mouse, and when I hit the mouse button, I want the dot to travel from the point of the mouse, to another point on the screen!

But, it's not working! Well, it is (ish), so... the question is, how do I get it working properly? :/

Graphics 640,480

;Scores position on the screen
Global scoreX = 400,scoreY = 100


Global dot = CreateImage(2,2)
SetBuffer ImageBuffer(dot)
Rect 0,0,1,1

SetBuffer BackBuffer()
Repeat
Cls
 
mx = MouseX()
my = MouseY()

If MouseHit(1)
	CreateMovingScore(mx,my,20)
End If

UpdateMovingScore()
DrawBlock dot,mx,my
Flip
Until KeyDown(1)

Type MoveScore
	Field x#,y#,speed#
	Field startX#,startY#
	Field finishX#,finishY#
	Field score
End Type

Function CreateMovingScore(x,y,score)
	createScore.MoveScore = New MoveScore
	createScore\startX = x
	createScore\startY = y
	createScore\speed = 1
	createScore\finishX = scoreX
	createScore\finishY = scoreY
	createScore\score = score
End Function

Function UpdateMovingScore()
	For updateMovement.MoveScore = Each MoveScore
		angle=ATan2((updateMovement\finishY + updateMovement\startY),(updateMovement\finishX + updateMovement\startX))
		updateMovement\x=(updateMovement\x + Cos( angle )*updateMovement\speed) 
		updateMovement\y=(updateMovement\y + Sin( angle )*updateMovement\speed) 
		DrawBlock dot,updateMovement\x,updateMovement\y
		Text 10,10,updateMovement\x+":"+updateMovement\y
		If updateMovement\x > scoreX And updateMovement\y > startY Then Delete updateMovement
	Next
End Function



Thanks in advance

Dabz

P.S. If this eventually works, it should go straight in the archives, because it's a right bugger of a problem, especially for someone who got a D in maths! :D

*EDIT*
Just noticed, the dot travels through the two points exactly half way... mmmm

Dabz starts scratching his head!!!!