长春高端网站制作,wordpress伪静态不跳转404,网页美工设计流程为,建卡盟网站建设 网站定制开发实现弹球小游戏 一.实现弹球小游戏:1.初始化布#xff1a;2.初始化一个球的信息#xff1a;3.球的移动和碰撞反弹4.底边挡板的绘制和移动碰撞重置数据。 二.整体代码#xff1a; 一.实现弹球小游戏:
1.初始化布#xff1a;
int main()
{initgraph(800, 600);setorigin(40… 实现弹球小游戏 一.实现弹球小游戏:1.初始化布2.初始化一个球的信息3.球的移动和碰撞反弹4.底边挡板的绘制和移动碰撞重置数据。 二.整体代码 一.实现弹球小游戏:
1.初始化布
int main()
{initgraph(800, 600);setorigin(400, 300);setaspectratio(1, -1);setbkcolor(RGB(188, 227, 245));cleardevice();getchar();closegraph();
}画面效果
2.初始化一个球的信息 1.球的中心点坐标球的半径 2.球的实际速度水平竖直的分量速度。 3.球的颜色。 4.定义一个结构体去保存这些数值。 #define radius 30typedef struct ball {double x, y;double v, vx, vy;int radius;COLORREF colour;
}Ba;//初始化球
void InitBall(Ba* ball)
{//在一个范围内随机生成一个球数值全部都是随机的ball-x ((rand() % 301) - 150);//[-150,150]ball-y ((rand() % 201) - 100);//生成随机速度ball-v (rand() % 6)3;//[3,8];//生成随机的角度int thead rand() % 360;//定义水平竖直的速度ball-vx ball-v *cos((double)thead);ball-vy ball-v *sin((double)thead);//初始化颜色ball-colour GREEN;
}3.球的移动和碰撞反弹 //球的移动和碰撞反弹
void CrashBall(Ba* ball)
{while (1){cleardevice();//设置颜色绘制球setfillcolor(ball-colour);fillcircle(ball-x, ball-y,radius);Sleep(40);//球的移动(ball-x) (ball-vx);(ball-y) (ball-vy);//判断球是否到墙壁;//不考虑底边是否存在挡板的情况if ((ball-x 400 - radius) || (ball-x -400 radius)){ball-vx (-(ball-vx));}if ((ball-y 300 - radius) || (ball-y -300 radius)){ball-vy (-(ball-vy));}}
}4.底边挡板的绘制和移动碰撞重置数据。 void CrashBall(Ba* ball)
{int left, top, right, bottom;left -100, top -270;right 100, bottom -300;while (1){cleardevice();//设置颜色绘制球setfillcolor(ball-colour);fillcircle(ball-x, ball-y,radius);//绘制挡板setfillcolor(RGB(113, 187, 234));//挡板不可以出界fillrectangle(left, top, right, bottom);Sleep(40);//球的移动(ball-x) (ball-vx);(ball-y) (ball-vy);//控制挡板移动if (_kbhit()){char ch _getch();switch (ch){case a:case A:if (left -400)break;left - 5;right - 5;break;case d:case D:if (right 400)break;left 5;right 5;break;}}//判断球是否到墙壁;//不考虑底边是否存在挡板的情况if ((ball-x 400 - radius) || (ball-x -400 radius)){ball-vx (-(ball-vx));}if ((ball-y 300 - radius)){ball-vy (-(ball-vy));}//撞到挡板if ((ball-x left) (ball-x right)){if (ball-y -240)ball-vy (-(ball-vy));}//判断出界if ((ball-x left) || (ball-x right)){if (ball-y -300){InitBall(ball);left -100, top -270;right 100, bottom -300;}}}
}二.整体代码
#define _CRT_SECURE_NO_WARNINGS 1#includestdio.h
#includeeasyx.h
#includeconio.h
#includetime.h
#includemath.h
#includestdbool.h#define radius 30
#define move 10typedef struct ball {double x, y;double v, vx, vy;COLORREF colour;
}Ba;//初始化球
void InitBall(Ba* ball)
{//在一个范围内随机生成一个球数值全部都是随机的ball-x ((rand() % 301) - 150);//[-150,150]ball-y ((rand() % 201) - 100);//生成随机速度ball-v (rand() % 6) 5;//[5,11];//生成随机的角度int thead rand() % 360;//定义水平竖直的速度ball-vx (ball-v) * cos((double)thead);ball-vy (ball-v) * sin((double)thead);//初始化颜色ball-colour GREEN;
}//球的移动和碰撞反弹void CrashBall(Ba* ball)
{int left, top, right, bottom;left -100, top -270;right 100, bottom -300;while (1){cleardevice();//设置颜色绘制球setfillcolor(ball-colour);fillcircle(ball-x, ball-y,radius);//绘制挡板setfillcolor(RGB(113, 187, 234));//挡板不可以出界fillrectangle(left, top, right, bottom);Sleep(40);//球的移动(ball-x) (ball-vx);(ball-y) (ball-vy);//控制挡板移动if (_kbhit()){char ch _getch();switch (ch){case a:case A:if (left -400)break;left - 5;right - 5;break;case d:case D:if (right 400)break;left 5;right 5;break;}}//判断球是否到墙壁;//不考虑底边是否存在挡板的情况if ((ball-x 400 - radius) || (ball-x -400 radius)){ball-vx (-(ball-vx));}if ((ball-y 300 - radius)){ball-vy (-(ball-vy));}//撞到挡板if ((ball-x left) (ball-x right)){if (ball-y -240)ball-vy (-(ball-vy));}//判断出界if ((ball-x left) || (ball-x right)){if (ball-y -300){InitBall(ball);left -100, top -270;right 100, bottom -300;}}}
}int main()
{initgraph(800, 600);setorigin(400, 300);setaspectratio(1, -1);setbkcolor(RGB(188, 227, 245));cleardevice();//获取当前时间作为随机数种子srand((unsigned int)time(NULL));//定义变量Ba ball;//初始化球InitBall(ball);//球的移动和碰撞反弹CrashBall(ball);getchar();closegraph();
}