因为个人的兴趣看着视频
自己敲的打飞机游戏
可能开存在某些bug
但是 可以提供参考
//创建打飞机的基本文件
//引入图形库的文件
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>
//枚举类型
enum my
{
WIDTH = 570,
HEIGHT=740,
BULLEL_NUM=15,//子弹数量
PLANE_NUM=10,//敌机数量
BIG,
SMALL
};
//存放飞机的数据
struct place {
int x;//飞机的横向 位移
int y;//飞机的竖向 位移
bool live;//飞机的 生命
}player;
//创建子弹的结构体
struct bullets {
int x;//子弹的横向 位移
int y;//子弹的竖向 位移
bool live;//子弹的 生命
} bull[BULLEL_NUM];
//敌机的结构体
struct badplane {
int x;//子弹的横向 位移
int y;//子弹的竖向 位移
bool live;//子弹的 生命
int width;
int height;
int hp;
int type;
} badPlane[PLANE_NUM];
//接受图片你的类型
IMAGE bg;
IMAGE user;
IMAGE bullet;
IMAGE enemy[2];
//加载图片
void loadImg() {
loadimage(&bg,"./images/bg1.jpg", WIDTH, HEIGHT);
//使用 unicode 会报错
//请使用 多字符集 项目->属性->高级->字符集->多字符集
//加载飞机 user
loadimage(&user, "./images/bg2.jpg", 120, 120);
//加载子弹图片
loadimage(&bullet, "./images/bg.jpg", 10, 24);
//加载敌机的图片
loadimage(&enemy[0], "./images/enemy.jpg", 45, 39);
loadimage(&enemy[1], "./images/enemy1.jpg", 105, 130);
}
//随机初始敌机数据
void planeData(int i) {
if (rand() %10 ==0)//0-9
{
badPlane[i].type = BIG;
badPlane[i].width = 105;
badPlane[i].height = 130;
badPlane[i].hp = 3;
}
else
{
badPlane[i