#include<graphics.h>
#include<conio.h>
#include<stdio.h>//引用Windows Multimedia API
#pragma comment(lib,"Winmm.lib")#define high 700           //游戏画面尺寸
#define width 590IMAGE img_bk;                //背景图片
int position_x, position_y;   //飞机位置
int bullet_x, bullet_y;       //子弹位置
float enemy_x, enemy_y;         //敌机位置
IMAGE img_planeNormal1, img_planeNormal2;    //飞机图片
IMAGE img_planeExplode1, img_planeExplode2;     //飞机爆炸图片
IMAGE img_bullet1, img_bullet2;              //子弹图片
IMAGE img_enemyPlane1, img_enemyPlane2;      //敌机图片
int isExplode = 0;                           //飞机是否爆炸
int score=0;                               //得分void startup()
{mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\game_music.mp3 alias bkmusic"), NULL, 0, NULL);  //打开背景音乐mciSendString(_T("play bkmusic repeat"), NULL, 0, NULL);      //循环播放initgraph(width,high);loadimage(&img_bk, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\background.jpg"));loadimage(&img_planeNormal1, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\planeNormal_1.jpg"));loadimage(&img_planeNormal2, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\planeNormal_2.jpg"));loadimage(&img_bullet1, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\bullet1.jpg"));loadimage(&img_bullet2, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\bullet2.jpg"));loadimage(&img_enemyPlane1, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\enemyPlane1.jpg"));loadimage(&img_enemyPlane2, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\enemyPlane2.jpg"));loadimage(&img_planeExplode1, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\planeExplode_1.jpg"));loadimage(&img_planeExplode2, _T("C:\\Users\\asus\\Desktop\\飞机大战素材\\planeExplode_2.jpg"));position_x = width * 0.7;          //初始化飞机位置position_y = high * 0.5;bullet_x = position_x;            //初始化子弹位置bullet_y = -85;enemy_x = width * 0.5;enemy_y = 10;BeginBatchDraw();
}void show()
{putimage(0, 0, &img_bk);              //显示背景if (isExplode == 0){putimage(position_x - 50, position_y - 60, &img_planeNormal1, NOTSRCERASE);  //显示正常飞机putimage(position_x - 50, position_y - 60, &img_planeNormal2, SRCINVERT);putimage(bullet_x - 7, bullet_y, &img_bullet1, NOTSRCERASE);         //显示子弹putimage(bullet_x - 7, bullet_y, &img_bullet2, SRCINVERT);putimage(enemy_x, enemy_y, &img_enemyPlane1, NOTSRCERASE);           //显示敌机putimage(enemy_x, enemy_y, &img_enemyPlane2, SRCINVERT);}else {putimage(position_x - 50, position_y - 60, &img_planeExplode1, NOTSRCERASE);  //显示爆炸飞机putimage(position_x - 50, position_y - 60, &img_planeExplode2, SRCINVERT);outtextxy(width * 0.48, high * 0.35, _T("游戏失败!  按任意键退出游戏"));}outtextxy(width * 0.48, high * 0.25, _T("得分:"));TCHAR s[5];_stprintf_s(s, _T("%d"), score);outtextxy(width * 0.55, high * 0.25, s);FlushBatchDraw();Sleep(2);
}void updateWithoutInput()
{if (bullet_y > -25)bullet_y -= 3;if (enemy_y < high - 25){if (score < 10)enemy_y = enemy_y + 0.5;else if (score < 20)enemy_y = enemy_y + 1;else if (score < 30)enemy_y = enemy_y + 2;else if (score < 40)enemy_y = enemy_y + 3;elseenemy_y = enemy_y + 4;}elseenemy_y = 10;if ((bullet_x-50 - enemy_x)* (bullet_x-50 - enemy_x) + (bullet_y-50 - enemy_y)* (bullet_y-50 - enemy_y) < 2500){enemy_x = rand()% (width-100)+50;enemy_y = -40;bullet_y = -85;mciSendString(_T("close gemusic"), NULL, 0, NULL);           //先关闭前面的音乐mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\gotEnemy.mp3 alias gemusic"), NULL, 0, NULL);  //打开音乐mciSendString(_T("play gemusic"), NULL, 0, NULL);   //仅播放一次score++;if (score > 0 && score % 5 == 0 && score % 2 != 0){mciSendString(_T("close 5music"), NULL, 0, NULL);mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\5.mp3 alias 5music"), NULL, 0, NULL);mciSendString(_T("play 5music"), NULL, 0, NULL);}if (score % 10 == 0){mciSendString(_T("close 10music"), NULL, 0, NULL);mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\10.mp3 alias 10music"), NULL, 0, NULL);mciSendString(_T("play 10music"), NULL, 0, NULL);}}if ((position_x-50 - enemy_x)* (position_x-50 - enemy_x) + (position_y-190 - enemy_y)* (position_y - enemy_y) < 500){isExplode = 1;mciSendString(_T("close exmusic"), NULL, 0, NULL);mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\explode.mp3 alias exmusic"), NULL, 0, NULL);mciSendString(_T("play exmusic"), NULL, 0, NULL);}
}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){//按下鼠标左键发射子弹bullet_x = position_x;bullet_y = position_y - 85;mciSendString(_T("close fgmusic"), NULL, 0, NULL);mciSendString(_T("open C:\\Users\\asus\\Desktop\\飞机大战素材\\f_gun.MP3 alias fgmusic"), NULL, 0, NULL);mciSendString(_T("play fgmusic"), NULL, 0, NULL);}}
}void gameover()
{EndBatchDraw();closegraph();
}int main()
{startup();          //数据初始化while (1){show();if (isExplode == 1){_getch();break;}updateWithoutInput();updateWithInput();}gameover();                //游戏结束,进行后续处理return 0;
}

飞机大战(easyx版)相关推荐

  1. 飞机大战java_java版飞机大战实战项目详细步骤

    本文为大家分享了java版飞机大战实战项目,供大家参考,具体内容如下 分析 飞机大战 首先对这个游戏分析,在屏幕上的物体都是飞行物,我们可以把建一个类,让其他飞行物继承这个类.游戏中应有英雄机(也就是 ...

  2. MATLAB飞机大战第二版,windows程序设计——飞机大战札记(单文档文件登陆界面)...

    windows程序设计--飞机大战笔记(单文档文件登陆界面) //2015/07/21 /by xbw/// /环境 VS 2013 飞机大战做的差不多了,闲来无事加点高大上的东西,关于单文档的登陆界 ...

  3. 飞机大战java_java版飞机大战 实战项目详细步骤.md

    分析 飞机大战 首先对这个游戏分析,在屏幕上的物体都是飞行物,我们可以把建一个类,让其他飞行物继承这个类.游戏中应有英雄机(也就是自己控制的飞机).敌人.而敌人应该分为打死给分的飞机(就是普通飞机), ...

  4. Java学习记录:Java飞机大战进阶版(敌人有子弹、有生命、有boss、有声音、还有大招一键清屏)

    Java飞机大战 序言 一.项目需求分析 二.各个对象类的设计 加载图片类Images 抽象类FlyingObject 天空类Sky 小敌机类Airplane 大敌机类BigAirplane 侦察机类 ...

  5. python 入门实战改进B站小甲鱼飞机大战增强版4.0

    效果: 资源包下载地址:https://download.csdn.net/download/m0_50944918/13977863 部分代码观礼: import pygame import sys ...

  6. C语言飞机大战简易版(包含两种界面)

    以下两种代码均适用于初学者: 先上第一种粗糙的代码,讲解都在代码中了. #include<stdio.h> #include<stdlib.h> #include<con ...

  7. [2015/09/08] Unity3D飞机大战(简陋版) Practice

    自己学的还是太差,进度很慢,不停地查各种资料. 1  2D背景实现自动滚动 1.1 插入2D背景 直接插入图片就好,我还在想sprite到底是用来做什么的-- 3D摄像头改为2D,Orthograph ...

  8. 飞机大战Java版完整版

    这是一款闯关的射击游戏,人物在不同的关 卡里面会触发不同的技能与对应的特效操作,有三个关卡与四个随机事件,每个关卡里面都会触发不同数量的怪物与能量血瓶,通过打败怪物与 到达特点时间点可通关 ⭐本项目演 ...

  9. 云龙开炮版飞机大战(Java+JavaSwing+关卡+技能物品+宠物+商店界面+可切换音乐界面)

    文章目录 前言 一.主界面展示 二.游戏演示效果 三.部分关卡.商店代码展示 ⭐游戏工具类⭐ ⭐游戏面板类⭐ ⭐商店类⭐ ⭐音乐类⭐ ⭐项目图片⭐ 作者:KJ.JK 前言 基于Java Swing,以 ...

  10. 微信小游戏-飞机大战(DoodlePlane)

    项目内容介绍 两种模式 经典模式 打落敌机可得分数,碰到敌机减少飞机携带的血瓶,当为血瓶数为零时碰到敌机游戏结束. 无敌模式 处于无敌状态的飞机一次可发射五发子弹,且飞机碰到敌机时飞机不受影响. 在两 ...

最新文章

  1. atlas单机模式代码_用代码玩太无聊,这样玩海盗游戏《ATLAS》单机模式才是正确玩法...
  2. 僵尸网络中区块链的利用方法分析
  3. Google地图搜索的触角伸向月球
  4. argument在python里什么意思_python add_argument() 的使用方法
  5. 找字符串中第一个只出现一次的字符
  6. 运维太忙?那是你还没掌握 Ansible !
  7. Bash脚本教程之变量
  8. freeBSD的vi
  9. hdu 1505 City Game
  10. 听说,阿里“拆中台”了?
  11. 如何快速搭建自己的独立站?
  12. Linux内存管理 -- smaps讲解
  13. mysql时间段查询语句_MySQL 如何查看慢查询语句
  14. 交换机千兆和百兆对网速影响_电信宽带升级为200M,为什么网速没有提升多少?...
  15. oracle 定时任务 每天执行,Oracle定时任务(定时执行某个SQL语句)
  16. 静态页面练习(pc和移动端两套)
  17. 微信公众号配置失败问题解决方法
  18. sa-token集成jwt
  19. 如约而至:微信自用的移动端IM网络层跨平台组件库Mars已正式开源
  20. 计算机网络——基于IP多播的网络会议程序

热门文章

  1. OHEM在线难样例挖掘的两个细节
  2. 硬件设计分享-⑩电路设计中静电的防护
  3. RNAfold预测RNA的二级结构
  4. Python爬虫v2-手机价位爬虫
  5. 二叉树?深度优先,广度优先遍历,一篇文章搞定(图解+代码+详细思路)
  6. Kali利用msf渗透Windows电脑(超详细)
  7. Oracle:11g服务详细介绍及,哪些服务是必须开启的
  8. php数值取负号,php – 如何让NumberFormatter打印带负号的负货币值?
  9. 占豪--站得高看得远
  10. JQuery qrcode插件生成二维码,并转换为image图片可识别