[C++] 纯文本查看 复制代码 #include <graphics.h>
#include <time.h>
#include <bits/stdc++.h>
using namespace std;
float t=0;
int height=600,width=800;
int wall_w=50;
int wall_pass=200;
char ch;
float rnx(int min,int max)
{
float t;
t=rand()%(max-min)+min;
return t;
}
struct ballon
{
int r;
double g,y,vy,x;
}ball;
struct wall
{
double yr,yl,xr,xl,vx,t;
}wall[2];
void start()
{
initgraph(width, height);
setcolor(BLACK);
setbkcolor(YELLOW);
srand(time(0));
setfont(25,0,"幼圆");
setbkmode(TRANSPARENT);
ball.y=50;
ball.x=100;
ball.vy=0.5;
ball.r=20;
ball.g=0.2;
wall[0].xl=700;
wall[0].xr=750;
wall[0].yl=0;
wall[0].yr=200;
wall[1].xl=700;
wall[1].xr=750;
wall[1].yl=400;
wall[1].yr=600;
}
void draw_ball()
{
ball.vy+=ball.g;
ball.y+=ball.vy;
if(kbhit())
{
ch = getch();
if(ch==' ')
{
ball.vy = -10;
}
}
if(ball.y>=height-ball.r)
{
ball.vy=-ball.vy;
ball.y=height-ball.r;
}
if(ball.y<=ball.r)
{
ball.vy=-ball.vy;
}
setfillcolor(RED);
fillellipse(ball.x, ball.y,ball.r,ball.r);
}
void draw_wall()
{
setfillcolor(RED);
for(int i=0;i<2;i++)
{
bar(wall[i].xl,wall[i].yl,wall[i].xr,wall[i].yr);
}
}
int main()
{
start();
while(1)
{ cleardevice();
draw_wall();
draw_ball();
Sleep(10);
}
} |