Angle Question...

BlitzPlus Forums/BlitzPlus Programming/Angle Question...

Not perfect, but it works:-


Graphics 800,600
SetBuffer BackBuffer()

Type moveObject
	Field x,y
	Field px,py
End Type


While Not KeyHit(1)
	Cls
	
	If MouseHit(1) Then
			setpath(MouseX(),MouseY(),400,100)
	End If

	move()
	Color 200,200,200
	Rect MouseX()-1,MouseY()-1,2,2
	Rect 400,100,2,2
	Flip
Wend
End


Function move()
	For loopObjects.moveObject = Each moveObject
	ang#=0
		ang=ATan2(loopObjects\py-loopObjects\y,loopObjects\px-loopObjects\x)
		loopObjects\x=loopObjects\x+Cos(ang)*3
		loopObjects\y=loopObjects\y+Sin(ang)*3
		Color 100,200,100
		Rect loopObjects\x-3,loopObjects\y-3,6,6 
		If Abs(loopObjects\x-loopObjects\px)<2 And Abs(loopObjects\y-loopObjects\py)<2 Then
			Delete loopObjects
		End If
	Next 
End Function


Function setPath(x,y,futureX,futureY)
	createPath.moveObject = New moveObject
	createPath\x = x
	createPath\y = y
	createPath\px = futureX
	createPath\py = futureY
End Function



I'll sleep better tonight knowing that's sorted! :)

Dabz