本文主要是介绍EasyX与C++的反弹球消砖块,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C++反弹球消砖块
游戏描述
一款用C++语言加上EasyX写的小游戏
游戏效果:
定义变量
#define width 400
#define high 600int ball_x, ball_y; //小球中心坐标
int vx, vy; //小球速度
int radius; //小球半径
int wood_x, wood_y; //木板中心坐标
int brick_count; //砖块数量
int brick_x, brick_y; //砖块长宽
int tag[5][10]; //标记数组
初始化
void startup()
{initgraph(width, high);ball_x = 200;ball_y = 580;radius = 10;vx = 1;vy = -1;wood_x = 200;wood_y = 595;brick_count = 50;brick_x = 40;brick_y = 20;//做标记for (int i = 0; i < 5; i++)for (int j = 0; j < 10; j++)tag[i][j] = 0;BeginBatchDraw();
}
与用户无关的更新
void updataWithoutInput()
{Sleep(5);//擦出圆setfillcolor(BLACK);solidcircle(ball_x, ball_y, radius);ball_x = ball_x + vx;ball_y = ball_y + vy;//小球碰壁后反弹if (ball_x <= radius || ball_x >= width - radius){vx = -vx;}if (ball_y <= radius || ball_y >= high - radius){vy = -vy;}//小球碰到挡板后反弹if (ball_y + 3 + radius >= wood_y-5&&ball_x + radius + 1 >= wood_x - 40&&ball_x - radius - 1 <= wood_x +40){if (ball_x + radius + 1 == wood_x - 40&&ball_x - radius - 1
这篇关于EasyX与C++的反弹球消砖块的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!