大一新生,求大神教两圆碰撞后弹开的程序,我只能写出两个圆
#include <graphics.h>#define R 100
int main()
{
int dx=1,y=0,x=300,dy=1,x1=0,y1=400,dx1=1,dy1=1;
initgraph(800,600);
setbkcolor(BLACK);
setlinewidth(5);
for(;is_run();delay_fps(200))
{
if(y>=getheight()-2*R)
{
setcolor(RED);
dy=-1;
}
if(y<=0)
{
setcolor(BLUE);
dy=1;
}
if(x>=getwidth()-2*R)
{
setcolor(GREEN);
dx=-1;
}
if(x<=0)
{
setcolor(YELLOW);
dx=1;
}
if(y1>=getheight()-2*R)
{
setcolor(RED);
dy1=-1;
}
if(y1<=0)
{
setcolor(BLUE);
dy1=1;
}
if(x1>=getwidth()-2*R)
{
setcolor(GREEN);
dx1=-1;
}
if(x1<=0)
{
setcolor(YELLOW);
dx1=1;
}
cleardevice();
y=y+dy;
x=x+dx;
circle(x+R,y+R,R);
y1=y1+dy1;
x1=x1+dx1;
circle(x1+R,y1+R,R);
}
getch();
closegraph();
return 0;
}