1 Star 0 Fork 0

Tranquil / 反弹球消砖块游戏

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#include <conio.h> #include <graphics.h>

#define High 480 // 游戏画面尺寸 #define Width 640

// 全局变量 int ball_x,ball_y; // 小球的坐标 int ball_vx,ball_vy; // 小球的速度 int radius; // 小球的半径 int brick_x,brick_y;//砖块坐标 int bar_x,bar_y;//挡板中心坐标 int bar_left,bar_right,bar_top,bar_bottom;//挡板上下左右边界坐标 int bar_width,bar_high;//挡板宽度 高度 int a[8]={0,0,0,0,0,0,0,0};

void startup() // 数据初始化 { ball_x = Width/2; ball_y = High/2; ball_vx = 1; ball_vy = 1; radius = 20; bar_x=Width/2; bar_y=465; bar_width=80; bar_high=15;

initgraph(Width, High);
BeginBatchDraw();

}

void clean() // 显示画面 { // 绘制黑线、黑色填充的圆 setcolor(BLACK); setfillcolor(BLACK); fillcircle(ball_x, ball_y, radius); setcolor(BLACK); setfillcolor(BLACK); fillrectangle(bar_left,bar_high,bar_right,bar_bottom);

}

void show() // 显示画面 { // 绘制黄线、绿色填充的圆 setcolor(YELLOW); setfillcolor(GREEN); fillcircle(ball_x, ball_y, radius);
//绘制挡板 setcolor(YELLOW); setfillcolor(GREEN); fillrectangle(bar_left,bar_high,bar_right,bar_bottom);

setcolor(YELLOW);
setfillcolor(RED);
fillrectangle(0,0,80,40);
fillrectangle(80,0,160,40);
fillrectangle(160,0,240,40);
fillrectangle(240,0,320,40);
fillrectangle(320,0,400,40);
fillrectangle(400,0,480,40);
fillrectangle(480,0,560,40);
fillrectangle(560,0,640,40);
if(a[0])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(0,0,80,40);
}
if(a[1])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(80,0,160,40);
}
if(a[2])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(160,0,240,40);
}
if(a[3])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(240,0,320,40);
}
if(a[4])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(320,0,400,40);
}
if(a[5])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(400,0,480,40);
}
if(a[6])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(480,0,560,40);
}
if(a[7])
{
    setcolor(BLACK);
    setfillcolor(BLACK);
    fillrectangle(560,0,640,40);
}


FlushBatchDraw();
// 延时
Sleep(3);    

}

void updateWithoutInput() // 与用户输入无关的更新 { // 更新小圆坐标 ball_x = ball_x + ball_vx; ball_y = ball_y + ball_vy;

if ((ball_x<=radius)||(ball_x>=Width-radius))
    ball_vx = -ball_vx;
if ((ball_y<=radius)||(ball_y>=High-radius))
    ball_vy = -ball_vy;    
if(bar_y-ball_y<=35&&bar_y-ball_y>=0&&(ball_x-bar_x<=80||ball_x-bar_x>=80))
    ball_vy = -ball_vy;    
if(ball_y<=60)
    ball_vy = -ball_vy;    

if(ball_x>=0&&ball_x<=80 && ball_y==62)
    a[0]=1;
if(ball_x>80&&ball_x<=160 && ball_y==62)
    a[1]=1;
if(ball_x>160&&ball_x<=240 && ball_y==62)
    a[2]=1;    
if(ball_x>240&&ball_x<=320 &&ball_y==62)
    a[3]=1;    
if(ball_x>320&&ball_x<=400&&ball_y==62)
    a[4]=1;    
if(ball_x>400&&ball_x<=480&&ball_y==62)
    a[5]=1;    
if(ball_x>480&&ball_x<=560&&ball_y==62)
    a[6]=1;
if(ball_x>560&&ball_x<=640&&ball_y==62)
    a[7]=1;

bar_left=bar_x-80;
bar_right=bar_x+80;
bar_high=bar_y-15;
bar_bottom=bar_y+15;

}

void updateWithInput() // 与用户输入有关的更新 {
MOUSEMSG m; // 定义鼠标消息

// 获取一条鼠标消息
m = GetMouseMsg();        
if(m.uMsg == WM_MOUSEMOVE)
{
    bar_x=m.x;
    bar_y=m.y;
}

}

void gameover() { EndBatchDraw(); closegraph(); }

int main() { startup(); // 数据初始化
while (1) // 游戏循环执行 { clean(); // 把之前绘制的内容清除 updateWithoutInput(); // 与用户输入无关的更新 updateWithInput(); // 与用户输入有关的更新 show(); // 显示新画面 } gameover(); // 游戏结束、后续处理 return 0; }

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/tranquilcgy/rebound_ball_antibrick_game.git
git@gitee.com:tranquilcgy/rebound_ball_antibrick_game.git
tranquilcgy
rebound_ball_antibrick_game
反弹球消砖块游戏
master

搜索帮助