# 123 **Repository Path**: wjj912409/123 ## Basic Information - **Project Name**: 123 - **Description**: No description available - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-11-28 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README //反弹球消砖块 #include #include #define High 480 // 游戏画面尺寸 #define Width 640 #define num 10 // 全局变量 int ball_x,ball_y; // 小球的坐标 int ball_vx,ball_vy; // 小球的速度 int radius; // 小球的半径 int x,y;//挡板的中心坐标 int bar_high,bar_width;//挡板长宽 int left,right,top,botton;//请确定挡板 int zhuan_high,zhuan_width;//砖块长宽 int a[num];//判断砖块是否存在 void startup() // 数据初始化 { ball_x = Width/2; ball_y = High/2; ball_vx = 1; ball_vy = 1; radius = 20; x=Width/2,y=High-15; bar_high=30,bar_width=150; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; zhuan_high=30; zhuan_width=64; int i; for(i=0;i=Width-radius)) ball_vx = -ball_vx; if ((ball_y<=radius)||(ball_y>=High-radius)) ball_vy = -ball_vy; //判断挡板是否接住小球 if(ball_y+radius==top) { if(ball_x+radius>=left&&ball_x-radius<=right) { ball_vy = -ball_vy; } } //判断小球是否击中砖块 int i; for(i=0;i=i*64)&&(ball_x<=(i+1)*64)) { a[i]=0; ball_vy=-ball_vy; } } } } void updateWithInput() // 与用户输入有关的更新 { /* char input; if(kbhit()) // 判断是否有输入 { input = getch(); // 根据用户的不同输入来移动,不必输入回车 if(input=='a') { x=x-10; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; } if(input=='d') { x=x+10; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; } if(input=='w') { y=y-10; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; } if(input=='s') { y=y+10; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; } } */ if(MouseHit()) { MOUSEMSG m; m=GetMouseMsg(); if(m.uMsg==WM_MOUSEMOVE) { x=m.x; y=m.y; bar_high=30,bar_width=150; left=x-bar_width/2; right=x+bar_width/2; top=y-bar_high/2; botton=y+bar_high/2; } else if(m.uMsg==WM_LBUTTONDOWN) { ball_x=x; ball_y=y-35; } } } void gameover() { EndBatchDraw(); closegraph(); } int main() { startup(); // 数据初始化 while (1) // 游戏循环执行 { clean(); // 把之前绘制的内容清除 updateWithoutInput(); // 与用户输入无关的更新 updateWithInput(); // 与用户输入有关的更新 show(); // 显示新画面 } gameover(); // 游戏结束、后续处理 return 0; }