Ok (cough) i'm sorry to bother you again joker but i was just wondering if you could check this code and help me out here.
Basically, i have tried to modify the code in order for me to get a better understanding of it, but for some reason it doesn't seem to be working and i can't see why :(
Heres the code:
Thanks for your kind help joker
:)
BLUE
Basically, i have tried to modify the code in order for me to get a better understanding of it, but for some reason it doesn't seem to be working and i can't see why :(
Heres the code:
Global pathx#=0 ;these are used to position the object on the path Global pathy#=0 Global id_counter=-1 ; keeps track of current point created Global current_point=0 ; current point to follow Global max_points=100 ; maximum allowed number of points Dim point_x(max_points-1) Dim point_y(max_points-1) ;****************************************** ;MAIN CODE ;****************************************** move=0 While Not KeyHit(1) Cls If MouseHit(1) Then create_point(MouseX(),MouseY()); set path point with the mouses current coords End If If KeyHit(57) And move=0 And id_counter>0 Then; if spacebar pressed then move rectangle current_point=0; reset the current path to 0 pathx=point_x(0); set the rectangles coords to the first path point pathy=point_y(0) move=1; set flag for movement started End If If KeyHit(28) Then; if the enter key is pressed then stop movement move=0; clear flag for movement pathx=point_x(0); set rectangle coords to the first path point pathy=point_y(0) current_point=-1; set current path to none exsistant End If follow_path(); function for drawing the pathpoints If move=1 Then update_path(); draw the moving rectangle and move it Color 200,200,200; set drawing color Rect MouseX()-1,MouseY()-1,2,2; draw mouse location with a rectangle Text 0,0,"Click mouse to set path point. Press spacebar to start animation. Press enter to stop." Text 0,10,"movement started="+movement_started Flip Wend End ;************************************************* ;************************************************* Function create_point(x,y) id_counter=id_counter+1 If id_counter>max_points-1 id_counter=max_points-1 Else point_x(id_counter)=x ; assign give values to x and y fields point_y(id_counter)=y EndIf End Function Function update_path() angle#=0 If current_point<id_counter angle=ATan2(point_y(current_point+1)-point_y(current_point),point_x(curent_point+1)-point_x(current_point)) pathx=pathx+Cos(angle) pathy=pathy+Sin(angle) Rect pathx-3,pathy-3,6,6 If Abs(pathx-point_x(current_point+1))<1 And Abs(pathy-point_y(current_point+1))<1 Then current_point=current_point+1; increase the current path point number pathx=point_x(current_point); set the rectangles coords to that of the next path point pathy=point_y(current_point) End If EndIf End Function Function follow_path() For a=0 To id_counter Rect point_x(a),point_y(a),2,2 If a<id_counter Rect point_x(a+1)-1,point_y(a+1)-1,2,2 Line point_x(a),point_y(a),point_x(a+1),point_y(a+1) EndIf Next End Function
Thanks for your kind help joker
:)
BLUE