Discuz! Board

 找回密码
 立即注册
查看: 1926|回复: 0

12.8 flybird

[复制链接]

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
发表于 2022-12-8 19:31:36 | 显示全部楼层 |阅读模式
[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);
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-7-18 11:24 , Processed in 0.058083 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表