Hi !
See this code.
when the white ship is near the planet (green zone) it should be attracted. In some situations it is not the case... so Could you help me to understand what'is wrong with my code ! Thanks !
See this code.
when the white ship is near the planet (green zone) it should be attracted. In some situations it is not the case... so Could you help me to understand what'is wrong with my code ! Thanks !
Graphics 800,600 Const cte_div = 5 HideMouse() ' init MoveMouse GraphicsWidth()/2, GraphicsHeight() / 2 px# = MouseX() py# = MouseY() cx = 200 cy = 150 cr1 = 50 cr2 = 120 speed# = 0.5 While Not KeyDown (KEy_ESCAPE) Cls ' player movement (rockout style) xdist# = MouseX() - px ydist# = MouseY() - py xs = xdist / cte_div ys = ydist / cte_div px = px + xs py = py + ys ' display planet SetColor 0,255,0 DrawOval cx - cr2, cy- cr2, cr2 * 2,cr2 * 2 SetColor 0,0,255 DrawOval cx - cr1,cy - cr1 ,cr1 * 2, cr1 * 2 SetColor 255,255,255 Plot ccx,ccy ' planet attraction code d = Int (Sqr((px-cx) * (px-cx) + (py-cy) * (py-cy))) If d <= cr2 And d > cr1 Then SetColor 255,255,255 DrawText "attracted !",cx,cy angle = ATan2((cy - py),(cx - px)) xmov# = Cos (angle) * speed# ymov# = Sin (angle) * speed# px = px + xmov# py = py + ymov# MoveMouse MouseX() + xmov#, MouseY() + ymov# DrawLine cx,cy, px,py End If ' display player SetColor 255,255,255 DrawOval px-25, py-25, 50,50 SetColor 255,0,0 DrawOval MouseX()-3, MouseY()-3,6,6 ' display infos DrawText "dist=" + String (d),0,0 DrawText "x=" + String (px),0,10 DrawText "y=" + String (py),0,20 DrawText "xmov=" + String (xmov),0,30 DrawText "ymov=" + String (ymov),0,40 DrawText "angle=" + String (angle),0,50 Flip Wend ShowMouse()