Enemy turn arround player position

BlitzMax Forums/BlitzMax Programming/Enemy turn arround player position

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

another try. No very smooth and realistic ! How to fix the rotation speed (the same for any distance) ?
Strict

Graphics 1024,768


Global Enemy_x# = 200
Global Enemy_y# = 400

Global Player_x# = GraphicsWidth() / 2
Global Player_y# = GraphicsHeight() / 2
Global d#
Global angle# = 0.0

MoveMouse Player_x#, Player_y#

Local bStartTurn = False

While Not KeyDown(KEY_ESCAPE)

	Cls

	SetColor 255,255,255
	DrawOval Player_x#-2, Player_y#-2,4,4
	SetColor 0,255,0
	DrawOval Enemy_x#-2, Enemy_y#-2,4,4
	
	Player_x# = MouseX()
	Player_y# = MouseY()
	
	SetColor 255,0,0
	
	d# = Float ( (Player_x# - Enemy_x#) * (Player_x# - Enemy_x#) + (Player_y# - Enemy_y#) * (Player_y# - Enemy_y#) )
	If d < 300 * 300 Then
		bStartTurn = True
	End If
	
	If bStartTurn = True
		
		If angle# < 360 Then 
			angle# = angle# + 1.0
		Else
			angle# = 0.0
		End If
		
		Local xmov# = Cos (Angle#) * Sqr(d)
		Local ymov# = Sin (Angle#) * Sqr(d)
		
		Enemy_x# = Player_x# + xmov#	
		Enemy_y# = Player_y# + ymov#		
		
	End If

	SetColor 255,255,255
	DrawText "d=" + Sqr(d),0,0
	
	Flip

Wend