guided rocket

BlitzMax Forums/BlitzMax Beginners Area/guided rocket

hub(Posted 2006) [#1]
Hi !
i'm searching a code to implement a guided rocket shoot into my space game ! for example the Enemy lauch a rocket in direction of the player. the rocket 'follow' the player and hit ! (the path isn't a bresenham line algo !)
i've seen a code example somewhere into this site, but i've not found it today !

http://www.bayre.com/zigwigwis/


tonyg(Posted 2006) [#2]
Some code hacked from BB...
Graphics 640,480
Global my_x#=100.0,my_y#=100.0, pointx#=100.0,pointy#=100.0,xspeed#=3.0,yspeed#=3.0
While Not KeyHit(1)
  Cls
  DrawOval my_x-10.0,my_y-10.0,20,20
  DrawText "my_x : " + my_x + " my_y : " + my_y,0,0
  DrawText "Point_x : " + pointx + " Point_y : " + pointy,0,10
'  If MouseDown(1) moveoval()
  moveoval()  
  Flip
Wend
Function moveoval()	
          pointx# = Float(MouseX())
          pointy# = Float(MouseY())
	angle# = ATan2((pointy-my_y),(pointx-my_x))
	xmov# = Cos(angle) * xspeed
	ymov# = Sin(angle) * yspeed
	my_x# = my_x + xmov
	my_y# = my_y + ymov 
	DrawText ((my_x-pointx)*(my_x-pointx)) + ((my_y-pointy)*(my_y-pointy)),0,20
	If ((my_x-pointx)*(my_x-pointx)) + ((my_y-pointy)*(my_y-pointy)) < 10.0 
	   my_x=pointx
	   my_y=pointy
	EndIf 
End Function        



hub(Posted 2006) [#3]
Thanks tonyg !