Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include<graphics.h>
  3. #include<math.h>
  4.  
  5. using namespace std;
  6. int distance(int x1,int y1,int x2,int y2)
  7. {
  8.     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  9.  
  10. }
  11. float angle(int x1 , int y1, int x2 , int y2)
  12. {
  13.     float ang;
  14.     if(x1-x2==0)
  15.     {
  16.         ang=-1.57;
  17.     }
  18.     else
  19.     {
  20.         ang = atan((float)(y1 - y2) / (x1 - x2));
  21.     }
  22.     if (ang < 0 && y1> y2)
  23.     {
  24.         ang += 3.14;
  25.         //cout<<"C";
  26.     }
  27.     else if (ang > 0 && x1 < x2)
  28.     {
  29.         // cout<<"A";
  30.         ang += 3.14;
  31.     }
  32.     return ang;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.  
  39.     float x1=200,y1=200,x2=200,y2=200, s=100;
  40.     float vx2=0,vy2=0;
  41.  
  42.  
  43.     //int gd = DETECT, gm;
  44.     //int x = 320, y = 240, radius;
  45.     //cout<<&gd;
  46.     initwindow (550, 400,"Windows BGI",50,50, false,true);
  47.  
  48.     while(1)
  49.     {
  50.  
  51.         x1=mousex();
  52.         y1=mousey();
  53.  
  54.         int d1=distance(x1,y1,x2,y2);
  55.         float ang1=angle(x1,y1,x2,y2);
  56.         if(d1-s>0)
  57.         {
  58.             vy2+=(d1-s)*sin(ang1)*.007;
  59.             vx2+=(d1-s)*cos(ang1)*.007;
  60.  
  61.         }
  62.  
  63.         //  cout<<ang1*180/3.14<<endl;
  64.         vy2+=.23;
  65.  
  66.         y2+=vy2;
  67.         x2+=vx2;
  68.  
  69.         vy2*=.99;
  70.         vx2*=.99;
  71.  
  72.         circle(x1,y1,25);
  73.         circle(x2,y2,25);
  74.         line (x1,y1,x2,y2);
  75.         delay(40);
  76.         swapbuffers();
  77.         cleardevice();
  78.     }
  79.     getch();
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement