试一下 moving ball
今天图老师小编要跟大家分享试一下 moving ball,精心挑选的过程简单易学,喜欢的朋友一起来学习吧!
#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:c2gi"); setcolor(15);
setwritemode(XOR_PUT);while(k!='q')
{while(bioskey(1)==0)
{printf("t=%f,v=%f,a=%f(%d,%d)",t,v,a,x,y);
if(x=0x=639)a=PI-a;if(y=0y=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;
}
}
}