• 当前位置:首页>>C语言>>C语言编程实例>>试一下 moving ball
  • 试一下 moving ball
  • \*******'w'加速,'s'减速,'a','d'转向************\

    #include <bios.h>
    #include <math.h>
    #include <graphics.h>
    #include <stdio.h>
    #include <time.h>
    #include <dos.h>
    #define PI 3.14159265
    #define r 15
    #define c(c) setfillstyle(1,c)

    main()
    {int x=320,y=240,x0=320,y0=240;float v=0,t=0,a=0;
     char k='0';
     int gdriver=DETECT,gmode;
      initgraph(&gdriver,&gmode,"c:\\tc2\\bgi");

     setcolor(15);
    setwritemode(XOR_PUT);

    while(k!='q')
     {while(bioskey(1)==0)
       {printf("t=%f,v=%f,a=%f(%d,%d)\r",t,v,a,x,y);
       if(x<=0||x>=639)a=PI-a;if(y<=0||y>=479)a=-a;
       x=v*cos(a)*t+x;y=v*sin(a)*t+y;
        line(x0,y0,x,y);
        circle(x,y,5);
        delay(5000);
        circle(x,y,5);
          x0=x;y0=y;
          t+=0.01;
          }
       k=bioskey(0);
    switch(k)
      {case 'a': a-=0.1;break;
       case 'd': a+=0.1;break;
       case 's': v-=0.1;break;
       case 'w': v+=0.1;break;
      }
    }
    }
    

     

    [1]