中易网

VS2010下报错

答案:1  悬赏:0  
解决时间 2021-01-14 07:28
  • 提问者网友:火车头
  • 2021-01-14 03:21
VS2010下报错
最佳答案
  • 二级知识专家网友:duile
  • 2021-01-14 04:37
你先要安装 easyx,然后再粘贴我帮你修改的代码。已经帮你调试好了:

#include
#include
#include
#include
#include

#define MAX 12
typedef struct
{
float x,y;
float vx,vy;
int color;
}ball;
void main()
{
int i,j,k,t;
ball ba[MAX];

double dt=7e-2;
int issuit(ball *,int i);
void hitpro(ball*,int ,int);
initgraph(640, 480);
srand(time(NULL));

for(i=0;i {
ba[i].x=(rand()%5+1)*116;
ba[i].y=(rand()%3+1)*116;
if (!issuit(ba,i)) {i--; continue;}
ba[i].vx=rand()%50-25;
ba[i].vy=rand()%50-25;
ba[i].color=HSLtoRGB((i+1)*30, 1, 0.5);
}
ba[6].color=YELLOW;
ba[7].color=LIGHTMAGENTA;

while(!kbhit())
{
for(i=0;i {
ba[i].x+=ba[i].vx*dt;
ba[i].y+=ba[i].vy*dt;
}
for(j=0;j {
for(k=j+1;k if (ba[j].x<51||ba[j].x>589) ba[j].vx=-ba[j].vx;
if (ba[j].y<51||ba[j].y>429) ba[j].vy=-ba[j].vy;
}
cleardevice();
for(i=0;i<4*MAX;i++)
{
t=i%MAX;
setcolor(ba[t].color);
circle(ba[t].x,ba[t].y,50);
}
Sleep(20);
}
closegraph();
}
int issuit( ball *b1,int n)
{
int i,a,b,c,d;
a=b1[n].x;
b=b1[n].y;
for(i=0;i {
c=b1[i].x;
d=b1[i].y;
if (a==c&&b==d) return 0;
}
return 1;
}
void hitpro(ball *ba,int j ,int k )
{
float r,a,b,c,d,tx1,tx2,ty1,ty2,tem;
tem=(ba[k].x-ba[j].x)*(ba[k].x-ba[j].x)+(ba[k].y-ba[j].y)*(ba[k].y-ba[j].y);
r=sqrt(tem);
if (r>102.0) return ;
a=(ba[k].x-ba[j].x)/r;
b=(ba[k].y-ba[j].y)/r;
c=-b;
d=a;
r=sqrt(c*c+d*d);
c/=r;
d/=r;
tx1=ba[j].vx*a+ba[j].vy*b;
ty1=ba[j].vx*c+ba[j].vy*d;
tx2=ba[k].vx*a+ba[k].vy*b;
ty2=ba[k].vx*c+ba[k].vy*d;
ba[j].vx=tx2*a+ty1*c;
ba[j].vy=tx2*b+ty1*d;
ba[k].vx=tx1*a+ty2*c;
ba[k].vy=tx1*b+ty2*d;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息