一、项目介绍
这是一个C语言编写的大球吃小球仿吃鸡游戏。
毒圈缩小,吃掉对手,杀出重围!
编译环境:Visual C++ 2019
第三方库:Easyx2022 注意需要提前安装easyX,如没有基础可以先了解easyX图形编程
二、运行截图
三、主要源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | void Draw() { SetWorkingImage(&Map); cleardevice(); for ( int i = 0; i < FNUM; i++) food[i].draw(); for ( int i = 0; i < AINUM; i++) ai[i].draw(); player->draw(); setlinestyle(PS_SOLID | PS_JOIN_BEVEL, 20); // 改笔的颜色、状态 setlinecolor(RGB(0, 100, 0)); line(( int )lx - 20, ( int )ly - 20, ( int )lx - 20, ( int )ry + 20); // 左竖 line(( int )lx - 20, ( int )ly - 20, ( int )rx + 20, ( int )ly - 20); // 上横 line(( int )lx - 20, ( int )ry + 20, ( int )rx + 20, ( int )ry + 20); // 下横 line(( int )rx + 20, ( int )ly - 20, ( int )rx + 20, ( int )ry + 20); // 右竖 setlinestyle(PS_NULL); IMAGE map2; const float asptime = 1; getimage(&map2, ( int )(player->x - WIDTH * .5 - player->r * asptime), ( int )(player->y - HEIGHT * .5 - player->r * asptime), ( int )(WIDTH + player->r * asptime * 2), ( int )(HEIGHT + player->r * asptime * 2)); float aspx = WIDTH / (WIDTH + player->r * 2); float aspy = HEIGHT / (HEIGHT + player->r * 2); SetWorkingImage(); setaspectratio(aspx, aspy); putimage(0, 0, &map2); const int mapw = 180; const int maph = 130; IMAGE map(( int )(mapw / aspx), ( int )(maph / aspy)); // 小地图 SetWorkingImage(&map); setbkcolor(RGB(120, 165, 209)); // 浅灰色背景 cleardevice(); for ( int i = 0; i < AINUM; i++) // 画 AI { if (ai[i].life == 0) continue ; setfillcolor(ai[i].color); fillcircle(( int )(ai[i].x * mapw / WIDTH / 4 / aspx), ( int )(ai[i].y * maph / HEIGHT / 4 / aspy), int (((ai[i].r * 2) / (aspx + aspy)) / ((MAPH / HEIGHT) * (MAPH / HEIGHT)) - 0.5)); } setfillcolor(player->color); // 画玩家 fillcircle(( int )(player->x * mapw / WIDTH / 4 / aspx), ( int )(player->y * maph / HEIGHT / 4 / aspy), int (((player->r * 2) / (aspx + aspy)) / ((MAPH / HEIGHT) * (MAPH / HEIGHT) - 0.5))); SetWorkingImage(); putimage(( int )(WIDTH - map.getwidth() + player->r * asptime * 2), 0, &map); setlinecolor(LIGHTGRAY); // 改笔颜色 状态 setlinestyle(PS_SOLID | PS_JOIN_BEVEL, ( int )(3 / aspx)); line(map2.getwidth() - map.getwidth(), 0, map2.getwidth() - map.getwidth(), map.getheight()); line(map2.getwidth() - map.getwidth(), map.getheight(), map2.getwidth(), map.getheight()); setlinestyle(PS_NULL); // 恢复笔 settextstyle(( int )(40 / (aspx + aspy)), 0, _T( "宋体" )); TCHAR str[16]; _stprintf_s(str, _T( "质量:%.1f kg" ), ( float )(player->r * player->r * PI / 300)); settextcolor(BLUE); // 改字体 outtextxy(0, 0, str); } |
四、游戏下载
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程