日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言+Easy X图形库实现飞机大战,源码加素材

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言+Easy X图形库实现飞机大战,源码加素材 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近學習c語言,看了Mooc上童晶老師的課,用c和Easy x圖形庫寫了一個簡單的飛機大戰,練練手,第一次寫出完整的,雖然還有好多功能沒有實現,但是也是有點成就感的,大家看看就好,不喜勿噴!!注:我是用vs2019寫的,素材好像傳不上,需要的私。

簡單效果圖如下:

?

?

#include<graphics.h> #include <conio.h> #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include<mmsystem.h> #pragma comment(lib,"Winmm.lib") #define high 640//定義畫布大小 #define width 480IMAGE img_bk;//背景圖片 IMAGE img_planeNormal_1, img_planeNormal_2;//飛機圖片顯示 IMAGE img_bullet_1, img_bullet_2;//飛機子彈 IMAGE img_enemyPlane_1, img_enemyPlane_2;//敵機 IMAGE img_planeBoom_1, img_planeBoom_2;//飛機相撞int position_x, position_y;//飛機坐標 int bullet_x, bullet_y;//子彈坐標 int enemyPlane_x, enemyPlane_y;//敵機坐標 int planBoom_x, planBoom_y;//爆炸坐標 int isExplode = 0;//飛機是否爆炸 int score = 0;void startup()//數據初始化 {mciSendString(_T("open E:\\游戲素材\\飛機大戰\\game_music.mp3 alias bkmusic"), NULL, 0, NULL);mciSendString(_T("play bkmusic repeat"), NULL, 0, NULL);initgraph(width, high);loadimage(&img_bk, "E:\\游戲素材\\飛機大戰\\background.jpg");//背景loadimage(&img_planeNormal_1, "E:\\游戲素材\\飛機大戰\\planeNormal_1.jpg");//我方飛機loadimage(&img_planeNormal_2, "E:\\游戲素材\\飛機大戰\\planeNormal_2.jpg");loadimage(&img_bullet_1, "E:\\游戲素材\\飛機大戰\\bullet_1.jpg");loadimage(&img_bullet_2, "E:\\游戲素材\\飛機大戰\\bullet_2.jpg");//子彈loadimage(&img_enemyPlane_1, "E:\\游戲素材\\飛機大戰\\enemyPlane_1.jpg");loadimage(&img_enemyPlane_2, "E:\\游戲素材\\飛機大戰\\enemyPlane_2.jpg");//敵機loadimage(&img_planeBoom_1, "E:\\游戲素材\\飛機大戰\\planeBoom_1.jpg");loadimage(&img_planeBoom_2, "E:\\游戲素材\\飛機大戰\\planeBoom_2.jpg");//碰撞position_x = width * 0.4;position_y = high * 0.7;bullet_x = position_x+45;bullet_y = -85;enemyPlane_x = 0.5 * width;enemyPlane_y = 0;planBoom_x =-100;planBoom_y = -100;BeginBatchDraw(); } void show()//顯示畫面 {putimage(0, 0, &img_bk);//顯示背景if (isExplode == 0){putimage(position_x, position_y, &img_planeNormal_1, NOTSRCERASE);putimage(position_x, position_y, &img_planeNormal_2, SRCINVERT);//顯示飛機putimage(bullet_x, bullet_y, &img_bullet_1, NOTSRCERASE);putimage(bullet_x, bullet_y, &img_bullet_2, SRCINVERT);//顯示子彈putimage(enemyPlane_x, enemyPlane_y, &img_enemyPlane_1, NOTSRCERASE);putimage(enemyPlane_x, enemyPlane_y, &img_enemyPlane_2, SRCINVERT);//顯示敵機}else{putimage(planBoom_x, planBoom_y, &img_planeBoom_1, NOTSRCERASE);putimage(planBoom_x, planBoom_y, &img_planeBoom_2, SRCINVERT);outtextxy(width * 0.48, high * 0.48, _T("小辣雞,這都能死!"));}TCHAR s[] = _T("得分:");outtextxy(width * 0.48, high*0.8 , s);char a[5];sprintf(a,"%d", score);outtextxy(width * 0.55, high*0.8, a);Sleep(20);FlushBatchDraw(); } void updateWithoutInput()//與用戶輸入無關的更新 {if(bullet_y>-30)//子彈上升bullet_y = bullet_y - 5;if (enemyPlane_y < high)//敵機下落enemyPlane_y+=2;else{srand(time(NULL));enemyPlane_x =rand() % width;//隨機生成新敵機enemyPlane_y = 0;}if (abs(enemyPlane_x - bullet_x) + abs(enemyPlane_y - bullet_y) < 70)//子彈擊中敵機{srand(time(NULL));enemyPlane_x = rand() % width;enemyPlane_y = 0;score++;}if (abs(enemyPlane_x - position_x) + abs(enemyPlane_y - position_y) < 70)//敵機與我機碰撞{mciSendString("close boo", NULL, 0, NULL);mciSendString("open E:\\游戲素材\\飛機大戰\\explode.mp3 alias boo", NULL, 0, NULL);//子彈爆炸音效mciSendString("play boo ", NULL, 0, NULL);planBoom_x = position_x;planBoom_y = position_y;isExplode = 1;} }void updateWithInput()//與用戶輸入有關的更新 {MOUSEMSG m;//記錄鼠標消息while (MouseHit()){m = GetMouseMsg();if (m.uMsg == WM_MOUSEMOVE)//鼠標移動時,飛機坐標變化{position_x = m.x;position_y = m.y;}else if (m.uMsg==WM_LBUTTONDOWN){mciSendString("close pi", NULL, 0, NULL);mciSendString("open E:\\游戲素材\\飛機大戰\\f_gun.mp3 alias pi", NULL, 0, NULL);//子彈發射音效mciSendString("play pi ", NULL, 0, NULL);mciSendString("close ps", NULL, 0, NULL);mciSendString("open E:\\游戲素材\\飛機大戰\\5.mp3 alias ps", NULL, 0, NULL);mciSendString("play ps ", NULL, 0, NULL);bullet_x = position_x+45;bullet_y = position_y - 50;}} }int main() {startup();//數據初始化while (1){show();//顯示畫面 updateWithoutInput();//與用戶輸入無關的更新updateWithInput();//與用戶輸入有關的更新}EndBatchDraw();return 0; }

總結

以上是生活随笔為你收集整理的c语言+Easy X图形库实现飞机大战,源码加素材的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。