[C++] 纯文本查看 复制代码 #include<bits/stdc++.h>
#include <graphics.h> //包含EGE的头文件
#include<time.h>
using namespace std;
int width=800;
int hight=600;
int number;
int count1=1,count2;
char ch;
int wall_w = 50,wall_h = 50;//障碍物宽和高
int wall_pass = 200;//障碍物间的缺口长度
int score,score_flag;
struct ballon
{
int r;
float vx;
float vy;
float x;
float y;
float g;
COLORS color;
}ball[1];
struct wall{
int xr;//左上x坐标
int yr;//左上y坐标
int xl;//右下x坐标
int yl;//右下y坐标 y
int vx;//x向速度
}w,wall_t;
float inx(int min,int max)
{
float t=rand()%(max-min)+min;
return t;
}
void start()
{
ball[0].x = inx(ball[0].r*2+1,width-ball[0].r);
ball[0].y = inx(ball[0].r*2+1,hight-ball[0].r);
ball[0].vx = rand()%10;
ball[0].vy = rand()%10;
ball[0].r = 10+rand()%10;
ball[0].g=1;
ball[0].color=RED;
w.xr = 200+300+wall_w;
w.yr = 150;//inx(100,300);
w.xl = 200+300;
w.yl = 0;
initgraph(width, hight);
initgraph(800, 600); //初始化图形界面
setcolor(RED); //设置画图线为红色
setbkcolor(WHITE);//设置背景颜色为白色
setfillcolor(RED);//设置填充颜色为红色
}
void update()
{
ball[0].vy=ball[0].vy+ball[0].g;
ball[0].y=ball[0].vy+ball[0].y;
if(ball[0].y>=hight-ball[0].r)
{
ball[0].y=hight-ball[0].r;
ball[0].vy=-ball[0].vy;
}
if(ball[0].y<=ball[0].r)
{
ball[0].y=ball[0].r;
ball[0].vy=-ball[0].vy;
}//球体的运动
if(kbhit())
{
ch = getch();
if(ch==' ')
{
ball[0].vy=-10;
}
}//按键响应
//墙体的运动
}
void draw()
{
setfillcolor(ball[0].color);
fillellipse(ball[0].x, ball[0].y, ball[0].r, ball[0].r); //画一个实心圆
//floodfillsurface(400, 300, RED);
bar(w.xl,w.yl,w.xr,w.yr);
Sleep(10);
cleardevice();//绘制球体
//绘制墙体
}
void gameover()
{
}
int main()
{
start();
while(1)
{
update();
draw();
/*if(gameover()) break;*/
}
getch(); //暂停,等待键盘按键
closegraph(); //关闭图形界面
return 0;
}
|