一、項目介紹
這是一個C語言編寫的大球吃小球仿吃雞游戲。
毒圈縮小,吃掉對手,殺出重圍!
編譯環(huán)境:Visual C++ 2019
第三方庫:Easyx2022 注意需要提前安裝easyX,如沒有基礎(chǔ)可以先了解easyX圖形編程
二、運行截圖
三、主要源碼
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); // 改筆的顏色、狀態(tài) 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); // 改筆顏色 狀態(tài) 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("質(zhì)量:%.1f kg"), (float)(player->r * player->r * PI / 300)); settextcolor(BLUE); // 改字體 outtextxy(0, 0, str); }
四、游戲下載
C語言網(wǎng)提供由在職研發(fā)工程師或ACM藍橋杯競賽優(yōu)秀選手錄制的視頻教程,并配有習題和答疑,點擊了解:
一點編程也不會寫的:零基礎(chǔ)C語言學練課程
解決困擾你多年的C語言疑難雜癥特性的C語言進階課程
從零到寫出一個爬蟲的Python編程課程
只會語法寫不出代碼?手把手帶你寫100個編程真題的編程百練課程
信息學奧賽或C++選手的 必學C++課程
藍橋杯ACM、信息學奧賽的必學課程:算法競賽課入門課程
手把手講解近五年真題的藍橋杯輔導課程