1 Star 0 Fork 0

丁弢/easyx rebounded ball

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
easyx rebounded ball.cpp 978 Bytes
一键复制 编辑 原始数据 按行查看 历史
丁弢 提交于 2019-11-11 15:31 . 多球反弹
#include <graphics.h>
#include <conio.h>
#include <time.h>
#define N 11
#define width 640
#define length 480
#define R 20
void change(int *rx, int *ry, int *x, int *y);
void wcircle(int *x, int *y);
void main()
{
initgraph(640,480);
int x[N], y[N];
int rx[N], ry[N];
int i;
srand((unsigned)time(NULL));
for(i = 0;i < N;i++)
{
x[i] = rand()%320;
y[i] = rand()%240;
rx[i] = rand()%2 + 1;
ry[i] = rand()%2 + 1;
}
while(1)
{
cleardevice();
BeginBatchDraw();
for(i = 0;i < N;i++)
{
wcircle(&x[i], &y[i]);
change(&rx[i], &ry[i], &x[i], &y[i]);
}
FlushBatchDraw();
Sleep(10);
}
getch();
closegraph();
}
void wcircle(int *x, int *y)
{
setfillcolor(RED);
fillcircle(*x, *y, R);
}
void change(int *rx, int *ry, int *x, int *y)
{
if((*x+20) > width || (*x-20) < 0)
{
*rx *= -1;
}
if((*y+20) > length || (*y-20) < 0)
{
*ry *= -1;
}
*x += *rx;
*y += *ry;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/D1ngtao/easyx-rebounded-ball.git
git@gitee.com:D1ngtao/easyx-rebounded-ball.git
D1ngtao
easyx-rebounded-ball
easyx rebounded ball
master

搜索帮助

Cb406eda 1850385 E526c682 1850385