[C] 纯文本查看 复制代码 #include <graphics.h> //包含EGE的头文件
#define pass 200
#include <time.h> //包含随机数,时间函数
int wide=800;
int height=600;
int ch;
int wall_height;
int wall_wide=100;
struct ball
{
float x,y;//坐标
float Vy;//y的速度
float R;//球的半径
float G;//球的加速度
}bird;
struct Wall{
int xr;//x坐标
int yr;//y坐标
int xl;//长度
int yl;//高度
int vx;//x向速度
}wall;
void start()
{
srand(time(0));//随机种子函数
initgraph(wide,height); //初始化图形界面
setcolor(RED); //设置画图线为红色
setbkcolor(WHITE);//设置背景颜色为白色
setfillcolor(RED);//设置填充颜色为红色
bird.x=wide/4;
bird.y=height/2;
bird.Vy=0;
bird.R=50;
bird.G=2;
wall.xl=600;
wall.yl=0;
wall.xr=600+wall_wide;
wall.yr=(rand()%200)+50;
wall.vx=25;
}
void update()
{
bird.y=bird.y+bird.Vy;
bird.Vy=bird.Vy+bird.G;
if(kbhit())
{
ch = getch();
if(ch==' ')
{
bird.Vy = -20;
}
}
if(bird.y>height-bird.R)
{
bird.Vy=-bird.Vy+2;
}
bar(wall.xl,wall.yl,wall.xr,wall.yr);
bar(wall.xl,wall.yr+pass,wall.xr,height);
}
void draw()
{
fillellipse(bird.x,bird.y,bird.R,bird.R); //画一个实心圆
//circle(400, 200, 50); //画一个空心圆 圆心坐标(320,240),半径为10
//floodfillsurface(400, 300, RED);
Sleep(15);
cleardevice();
}
int main()
{
start();
while(1)
{
draw();
update();
}
getch(); //暂停,等待键盘按键
closegraph(); //关闭图形界面
return 0;
}
|