bounce.c

来自「This is an animation of bouncing ball..」· C语言 代码 · 共 66 行

C
66
字号
// bouncing BallProgram
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>

main(void)
{
int maxx,maxy,area,x=25,y=25,ch,xdir=1,ydir=1;{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");



while(!kbhit())
{
setcolor(15);
rectangle(0,0,getmaxx(),getmaxy());
outtextxy(200,1,"Press ESC to EXIT...!");

setcolor(14);

x=x+(xdir*5);
y=y+(ydir*2);

circle(x,y,25);

setfillstyle(WIDE_DOT_FILL,2);
floodfill(x+5,y+5,14);

delay(10);

setfillstyle(SOLID_FILL,0);
floodfill(x+5,y+5,14);

setcolor(0);
circle(x,y,25);
floodfill(x+2,y+2,0);

if(x>getmaxx()-25||x<25)
{
sound(5000);
delay(40);
sound(3000);
delay(40);
nosound();
xdir*=-1;
}
if(y>getmaxy()-25||y<25)
{
sound(5000);
delay(40);
sound(3000);
delay(40);
nosound();
ydir*=-1;
}
}
getch();
closegraph();
restorecrtmode();
return 0;
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?