试一下 moving ball
2008-03-08 12:47:57 来源:WEB开发网核心提示:\***'w'加速,'s'减速,'a','d'转向\#include <bios.h>#include <math.h>#include <graphics.h>#include <stdio.h>#incl
\*******'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<=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;
}
}
}
#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<=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;
}
}
}
[]
更多精彩
赞助商链接