c语言飞机大战

#include"game.h"
#include<conio.h>
#include<iostream>
#include<stdio.h>
#include<easyx.h>
#include<graphics.h>
#include<windows.h>
#include<mmsystem.h>//包含多媒体设备接口文件
#pragma comment(lib,"winmm.lib")//加载静态库 
#define _CRT_SECURE_NO_WARNINGS
#define width 624
#define highth 960
#define bul_max 100//屏幕上同时出现的子弹上限
#define enemy_bul_max 100
#define enemy1_hp 30
#define enemy2_hp 50
#define enemy3_hp 150
#define enemy4_hp 50
#define enemy5_hp 4000
#define enemy6_hp 5000
IMAGE bg1,bg2,bg3,bg;
IMAGE Start2;
IMAGE loading2;
IMAGE player[2];
IMAGE player_bullet[2];
IMAGE protect[2];
IMAGE heart[2];
IMAGE supply[2];
IMAGE supply_draw[2];
IMAGE GG[2];
IMAGE Enemy1[3];//小飞机
IMAGE Enemy2[2];//中飞机
IMAGE Enemy2Bullet[2];//中飞机子弹
IMAGE Enemy3[2];//大飞机
IMAGE Enemy3Bullet[2];//大飞机子弹
IMAGE Enemy4[2];//横行飞机
IMAGE Enemy4Bullet[2];//横行飞机子弹
IMAGE Enemy5[2];//第二关boss
IMAGE Enemy5Bullet[2];//第二关boss子弹
IMAGE Enemy6[2];//第三关boss
IMAGE Enemy6Bullet[2];//第三关boss子弹
struct Plane  //玩家子弹
{
	double x;
	double y;
	bool life;
	int hp;
	int atk;
	double wide;
	double high;
}bullet[bul_max], plane, enemy1[10], enemy2[5], enemy2_bullet[enemy_bul_max], enemy3[3], enemy3_bullet[enemy_bul_max], enemy4[3], enemy4_bullet[enemy_bul_max], enemy5[1], enemy5_bullet[enemy_bul_max], enemy6[1], enemy6_Sbullet[enemy_bul_max], enemy6_Lbullet[enemy_bul_max], enemy6_Rbullet[enemy_bul_max],Boom[1];
int score = 0;//2500分后出现第一关boss,5000通过第一关,8000分第二关boss出现,12000分进入第三关
int supply_count = 1;
int enemy3_direct0 = 1;
int enemy3_direct1 = 1;
int enemy3_direct2 = 1;
int enemy5_direct0 = 1;
int enemy6_direct0 = 1;
int level_change_count = 1;
//系统设置,游戏画面及声音实现
int main();
void LoadImg()//加载图片
{
	//加L或_T可以解决Realease版本不能加载图片的问题

	//我方飞机
	if (level() == 1)
	{
		loadimage(&bg1, L"E:\\飞机大战素材\\L1.jpg");
	}
	else if (level() == 2)
	{
		loadimage(&bg2, L"E:\\飞机大战素材\\L2.png");
	}
	else
	{
		loadimage(&bg3, L"E:\\飞机大战素材\\L3.jpg");
	}
	
	loadimage(&player[0], L"E:\\飞机大战素材\\planeyy.jpg");//掩码图
	loadimage(&player[1], L"E:\\飞机大战素材\\plane.jpg");//一定得用jpg格式的图片啊!!!
	loadimage(&player_bullet[0], L"E:\\飞机大战素材\\bullet0.jpg");
	loadimage(&player_bullet[1], L"E:\\飞机大战素材\\bullet1.jpg");
	loadimage(&protect[0], L"E:\\飞机大战素材\\proy.jpg");
	loadimage(&protect[1], L"E:\\飞机大战素材\\pro.jpg");
	loadimage(&heart[0], L"E:\\飞机大战素材\\hearty.jpg");
	loadimage(&heart[1], L"E:\\飞机大战素材\\heart.jpg");
	loadimage(&supply[0], L"E:\\飞机大战素材\\bomb_supplyy.jpg");
	loadimage(&supply[1], L"E:\\飞机大战素材\\bomb_supply.jpg");
	loadimage(&supply_draw[0], L"E:\\飞机大战素材\\bomby.jpg");
	loadimage(&supply_draw[1], L"E:\\飞机大战素材\\bomb.jpg");
	loadimage(&GG[0], L"E:\\飞机大战素材\\R-C (1)y.jpg");
	loadimage(&GG[1], L"E:\\飞机大战素材\\R-C (1).jpg");



	/*loadimage(&player[0], "E:\\飞机大战素材\\kunkun.jpg");
	loadimage(&player[1], "E:\\飞机大战素材\\kunkuny.jpg");
	loadimage(&player_bullet[0], "E:\\飞机大战素材\\RCy.jpg");
	loadimage(&player_bullet[1], "E:\\飞机大战素材\\RC.jpg");*/

	//敌方飞机
	loadimage(&Enemy1[0], L"E:\\飞机大战素材\\enemy1y_jpg.jpg");//敌机1
	loadimage(&Enemy1[1], L"E:\\飞机大战素材\\enemy1_jpg.jpg");
	//loadimage(&Enemy1[2], "E:\\飞机大战素材\\enemy1_down2.png");

	loadimage(&Enemy2[0], L"E:\\飞机大战素材\\enemy2yy.jpg");//敌机2
	loadimage(&Enemy2[1], L"E:\\飞机大战素材\\enemy2_jpg.jpg");

	loadimage(&Enemy2Bullet[0], L"E:\\飞机大战素材\\llly_jpg.jpg");
	loadimage(&Enemy2Bullet[1], L"E:\\飞机大战素材\\lll_jpg.jpg");

	//敌机3
	loadimage(&Enemy3[0], L"E:\\飞机大战素材\\enemyPlane1.jpg");
	loadimage(&Enemy3[1], L"E:\\飞机大战素材\\enemyPlane2.jpg");
	loadimage(&Enemy3Bullet[0], L"E:\\飞机大战素材\\enemy3_buly.jpg");
	loadimage(&Enemy3Bullet[1], L"E:\\飞机大战素材\\enemy3_bull.jpg");

	//敌机4
	loadimage(&Enemy4[0], L"E:\\飞机大战素材\\enemy4y.jpg");
	loadimage(&Enemy4[1], L"E:\\飞机大战素材\\enemy4.jpg");
	loadimage(&Enemy4Bullet[0], L"E:\\飞机大战素材\\enemy4_buly.jpg");
	loadimage(&Enemy4Bullet[1], L"E:\\飞机大战素材\\enemy4_bul.jpg");

	//敌机5
	loadimage(&Enemy5[0], L"E:\\飞机大战素材\\银翼杀手2y.jpg");
	loadimage(&Enemy5[1], L"E:\\飞机大战素材\\银翼杀手2.jpg");
	loadimage(&Enemy5Bullet[0], L"E:\\飞机大战素材\\boss1y.jpg");
	loadimage(&Enemy5Bullet[1], L"E:\\飞机大战素材\\boss1.jpg");

	//敌机6
	loadimage(&Enemy6[0], L"E:\\飞机大战素材\\银翼杀手2y.jpg");
	loadimage(&Enemy6[1], L"E:\\飞机大战素材\\金色毁灭2.jpg");
	loadimage(&Enemy6Bullet[0], L"E:\\飞机大战素材\\boss2y.jpg");
	loadimage(&Enemy6Bullet[1], L"E:\\飞机大战素材\\boss2.jpg");

	

}
//void LoadBgm()
//{
//	mciSendString("open E:\\c语言练习\\PlaneWar\\黑麦 - 游戏音乐试听(飞机大战).mp3", NULL, 0, NULL);
//	mciSendString("play E:\\c语言练习\\PlaneWar\\黑麦 - 游戏音乐试听(飞机大战).mp3", NULL, 0, NULL);
//}
//这里有待学习
bool Timer_enemycreat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_enemy2_bullet_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_enemy3_bullet_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_enemy4_bullet_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_enemy5_bullet_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_enemy6_bullet_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer_supply_creat(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}


void Enemy_Clean()
{
	int i, j;
	for (i = 0; i < 10; i++)//敌机1
	{
		if (enemy1[i].life == true)
		{
			enemy1[i].life = false;

		}
	}
	for (j = 0; j < 5; j++)//敌机2,这个地方应该不会有问题
	{
		if (enemy2[j].life == true)
		{
			enemy2[j].life = false;

		}
	}

	for (j = 0; j < 3; j++)//敌机3
	{
		if (enemy3[j].life == true)
		{
			enemy3[j].life = false;


		}
	}
	for (j = 0; j < 3; j++)//敌机4
	{
		if (enemy4[j].life == true)
		{
			enemy4[j].life = false;

		}
	}

	//以下为子弹清除
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy2_bullet[i].life == true)
		{
			enemy2_bullet[i].life = false;
			
		}
		if (enemy3_bullet[i].life == true)
		{
			enemy3_bullet[i].life = false;

		}
		if (enemy4_bullet[i].life == true)
		{
			enemy4_bullet[i].life = false;

		}
	}
}
int level()
{
	if (score > 5000 && score < 10000)
	{
		return 2;
	}
	else if (score < 5000)
	{
		return 1;
	}
	else if (score>10000)
	{
		return 3;
	}
	if (score > 17000)
	{
		return 4;
	}
}
void level_change()
{
	int ret = level();
	if (level_change_count == 1 && score > 5000)
	{
		level_change_count += 1;
		plane.hp = 100;
		Enemy_Clean();
	}
	if (level_change_count == 2 && score >= 12000)
	{
		level_change_count += 1;
		plane.hp = 100;
		Enemy_Clean();

	}
	
	

}
//level()放在主函数用于判断是否进入下一关
void BeginMenu(int x, int y)
{
	loadimage(&bg, L"E:\\飞机大战素材\\black.jpg");
	putimage(0, -900, &bg);

	
	initgraph(width, highth);
	setaspectratio(1, 1);
	setorigin(0, 0);
	TCHAR time_test1[50];
	TCHAR time_test2[50];
	TCHAR time_test3[50];
	TCHAR time_test4[50];
	TCHAR time_test5[50];

	_stprintf_s(time_test1, _T("若干年后,外星敌机来犯,人类陷入恐慌"));
	_stprintf_s(time_test2, _T("身为星际王牌飞行员的你,"));
	_stprintf_s(time_test3, _T("嘴角勾起了一丝不易令人察觉的弧度,"));
	_stprintf_s(time_test4, _T("低声道:"));
	_stprintf_s(time_test5, _T("\"无所谓,我会出手\""));

	settextstyle(25, 0, _T("宋体"));
	Sleep(1000);

	outtextxy(x, y, time_test1);
	Sleep(2000);

	outtextxy(x, y + 50, time_test2);
	Sleep(2000);

	outtextxy(x, y + 100, time_test3);
	Sleep(2000);

	outtextxy(x, y + 150, time_test4);
	Sleep(3000);

	outtextxy(x, y + 200, time_test5);
	Sleep(3000);
	
}
void FailMenu()
{




	char input;
	printf("Game Over\n");
	printf("是否继续游戏?\n请输入:(yes/no)并回车\n");
	while (1)
	{
		scanf("%s", &input);

		if (strcmp(&input, "yes") == 0)
		{
			break;
		}
		else if (strcmp(&input, "no") == 0)
		{
			exit(0);
		}
		else
		{
			printf("输入无效,请重新输入\n");
		}
	}
	main();
}
void EndMenu()
{
	Enemy_Clean();
	enemy6[0].life = false;
	
	/*int x = 10;
	int y = 20;
	Sleep(1000);
	

	initgraph(width, highth);

	setaspectratio(1, 1);
	setorigin(0, 0);
	putimage(0, -900, &bg);
	TCHAR time_test6[50];
	TCHAR time_test7[50];
	TCHAR time_test8[50];
	_stprintf_s(time_test6, _T("地球安全了,"));
	_stprintf_s(time_test7, _T("你漠视着满天的敌机残骸,笑道:"));
	_stprintf_s(time_test8, _T("\"我无敌\""));

	settextstyle(25, 0, _T("宋体"));
	Sleep(1000);

	outtextxy(x, y, time_test6);
	Sleep(2000);

	outtextxy(x, y + 50, time_test7);
	Sleep(3000);

	outtextxy(x, y + 100, time_test8);
	Sleep(4000);*/
	printf("地球安全了,\n你漠视着漫天的敌机残骸,\n笑道:\n\"我无敌\"");
	exit(0);
}
void Judge()
{
	if (plane.hp <= 0)
	{
		if (level() == 1)
		{
			score = 0;
		}
		if (level() == 2 && score < 8000)
		{
			score = 5001;
		}
		if (level() == 2 && score > 8000)
		{
			score = 8001;
		}
		if (level() == 3)
		{
			score = 12001;
		}
		supply_count = 1;
		FailMenu();
	}

	if (score > 17000)
	{
		EndMenu();
	}
}
bool Timer(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}
bool Timer2(int ms)//定时器
{
	static DWORD t1 = 0, t2 = 0;
	if (t2 - t1 > ms)
	{
		t1 = t2;
		return true;
	}
	t2 = clock();
	return false;
}

void GameDraw()//打印游戏画面
{
	
	LoadImg();
	if (level() == 1)
	{
		putimage(0, 0, &bg1);
	}
	else if (level() == 2)
	{
		putimage(0, 0, &bg2);
	}
	else
	{
		putimage(0, 0, &bg3);
	}
	//Show_Score(100, 0, score);//显示分数

	/*putimage(plane.x, plane.y, &protect[0], NOTSRCERASE);
	putimage(plane.x, plane.y, &protect[1], SRCINVERT);*/
	putimage(plane.x + 12, plane.y + 10, &player[0], NOTSRCERASE);
	putimage(plane.x + 12, plane.y + 10, &player[1], SRCINVERT);
	if (Boom[0].life)
	{
		putimage(Boom[0].x, Boom[0].y, &supply[0], NOTSRCERASE);
		putimage(Boom[0].x, Boom[0].y, &supply[1], SRCINVERT);
	}
	if (plane.hp >= 30)
	{
		putimage(10, 10, &heart[0], NOTSRCERASE);
		putimage(10, 10, &heart[1], SRCINVERT);
	}
	if (plane.hp >= 40)
	{
		putimage(55, 10, &heart[0], NOTSRCERASE);
		putimage(55, 10, &heart[1], SRCINVERT);
	}
	if (plane.hp >= 60)
	{
		putimage(100, 10, &heart[0], NOTSRCERASE);
		putimage(100, 10, &heart[1], SRCINVERT);
	}
	if (plane.hp >= 80)
	{
		putimage(145, 10, &heart[0], NOTSRCERASE);
		putimage(145, 10, &heart[1], SRCINVERT);
	}
	if (plane.hp >= 100)
	{
		putimage(190, 10, &heart[0], NOTSRCERASE);
		putimage(190, 10, &heart[1], SRCINVERT);
	}

	if (supply_count >= 1)
	{
		putimage(10, 60, &supply_draw[0], NOTSRCERASE);
		putimage(10, 60, &supply_draw[1], SRCINVERT);
	}
	if (supply_count >= 2)
	{
		putimage(55, 60, &supply_draw[0], NOTSRCERASE);
		putimage(55, 60, &supply_draw[1], SRCINVERT);
	}
	if (supply_count >= 3)
	{
		putimage(100, 60, &supply_draw[0], NOTSRCERASE);
		putimage(100, 60, &supply_draw[1], SRCINVERT);
	}
	int i;
	for (i = 0; i < bul_max; i++)
	{
		if (bullet[i].life == true)
		{
			putimage(bullet[i].x, bullet[i].y, &player_bullet[0], NOTSRCERASE);
			putimage(bullet[i].x, bullet[i].y, &player_bullet[1], SRCINVERT);
		}
	}
	//敌方飞机
	for (i = 0; i < 10; i++)//敌机1
	{
		if (enemy1[i].life == true)
		{
			putimage(enemy1[i].x, enemy1[i].y, &Enemy1[0], NOTSRCERASE);
			putimage(enemy1[i].x, enemy1[i].y, &Enemy1[1], SRCINVERT);
		}
	}

	for (i = 0; i < 5; i++)//敌机2
	{
		if (enemy2[i].life == true)
		{
			putimage(enemy2[i].x, enemy2[i].y, &Enemy2[0], NOTSRCERASE);
			putimage(enemy2[i].x, enemy2[i].y, &Enemy2[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy2_bullet[i].life == true)
		{
			putimage(enemy2_bullet[i].x, enemy2_bullet[i].y, &Enemy2Bullet[0], NOTSRCERASE);
			putimage(enemy2_bullet[i].x, enemy2_bullet[i].y, &Enemy2Bullet[1], SRCINVERT);
		}
	}

	for (i = 0; i < 3; i++)//敌机3
	{
		if (enemy3[i].life == true)
		{
			putimage(enemy3[i].x, enemy3[i].y, &Enemy3[0], NOTSRCERASE);
			putimage(enemy3[i].x, enemy3[i].y, &Enemy3[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy3_bullet[i].life == true)
		{
			putimage(enemy3_bullet[i].x, enemy3_bullet[i].y, &Enemy3Bullet[0], NOTSRCERASE);
			putimage(enemy3_bullet[i].x, enemy3_bullet[i].y, &Enemy3Bullet[1], SRCINVERT);
		}
	}

	for (i = 0; i < 3; i++)//敌机4
	{
		if (enemy4[i].life == true)
		{
			putimage(enemy4[i].x, enemy4[i].y, &Enemy4[0], NOTSRCERASE);
			putimage(enemy4[i].x, enemy4[i].y, &Enemy4[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy4_bullet[i].life == true)
		{
			putimage(enemy4_bullet[i].x, enemy4_bullet[i].y, &Enemy4Bullet[0], NOTSRCERASE);
			putimage(enemy4_bullet[i].x, enemy4_bullet[i].y, &Enemy4Bullet[1], SRCINVERT);
		}
	}


	for (i = 0; i < 1; i++)//敌机5
	{
		if (enemy5[i].life == true)
		{
			putimage(enemy5[i].x, enemy5[i].y, &Enemy5[0], NOTSRCERASE);
			putimage(enemy5[i].x, enemy5[i].y, &Enemy5[1], SRCINVERT);
		}
	}

	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy5_bullet[i].life == true)
		{
			putimage(enemy5_bullet[i].x, enemy5_bullet[i].y, &Enemy5Bullet[0], NOTSRCERASE);
			putimage(enemy5_bullet[i].x, enemy5_bullet[i].y, &Enemy5Bullet[1], SRCINVERT);
		}
	}

	for (i = 0; i < 1; i++)//敌机6
	{
		if (enemy6[i].life == true)
		{
			putimage(enemy6[i].x, enemy6[i].y, &Enemy6[0], NOTSRCERASE);
			putimage(enemy6[i].x, enemy6[i].y, &Enemy6[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy6_Sbullet[i].life == true)
		{
			putimage(enemy6_Sbullet[i].x, enemy6_Sbullet[i].y, &Enemy6Bullet[0], NOTSRCERASE);
			putimage(enemy6_Sbullet[i].x, enemy6_Sbullet[i].y, &Enemy6Bullet[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy6_Lbullet[i].life == true)
		{
			putimage(enemy6_Lbullet[i].x, enemy6_Lbullet[i].y, &Enemy6Bullet[0], NOTSRCERASE);
			putimage(enemy6_Lbullet[i].x, enemy6_Lbullet[i].y, &Enemy6Bullet[1], SRCINVERT);
		}
	}
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy6_Rbullet[i].life == true)
		{
			putimage(enemy6_Rbullet[i].x, enemy6_Rbullet[i].y, &Enemy6Bullet[0], NOTSRCERASE);
			putimage(enemy6_Rbullet[i].x, enemy6_Rbullet[i].y, &Enemy6Bullet[1], SRCINVERT);
		}
	}
	
}
void GameInit()//游戏各数据初始化
{
	int i;
	plane.life = true;//玩家飞机初始化
	plane.x = width / 2 - 50;
	plane.y = 1;
	plane.hp = 100;
	plane.wide = 115;
	plane.high = 115;

	Boom[0].wide = 48;
	Boom[0].high = 85;
	Boom[0].x = -200;
	Boom[0].y = -200;
	Boom[0].life = false;

	//以下为敌机初始化
	for (i = 0; i < 10; i++)
	{
		enemy1[i].life = false;
		enemy1[i].hp = 30;
		enemy1[i].x = -10;
		enemy1[i].y = -10;
		enemy1[i].atk = 10;
		enemy1[i].wide = 52;
		enemy1[i].high = 39;


	}
	for (i = 0; i < 5; i++)
	{
		enemy2[i].life = false;
		enemy2[i].hp = 50;
		enemy2[i].x = -1;
		enemy2[i].y = -1;
		enemy2[i].atk = 20;
		enemy2[i].wide = 69;
		enemy2[i].high = 99;
	}
	for (i = 0; i < 3; i++)
	{
		enemy3[i].life = false;
		enemy3[i].hp = 150;
		enemy3[i].x = -1;
		enemy3[i].y = -1;
		enemy3[i].atk = 30;
		enemy3[i].wide = 104;
		enemy3[i].high = 148;
	}


	for (i = 0; i < 3; i++)
	{
		enemy4[i].life = false;
		enemy4[i].hp = 50;
		enemy4[i].x = -1;
		enemy4[i].y = -1;
		enemy4[i].atk = 30;
		enemy4[i].wide = 79;
		enemy4[i].high = 120;
	}

	for (i = 0; i < 1; i++)
	{
		enemy5[i].life = false;
		enemy5[i].hp = 4000;
		enemy5[i].x = -1;
		enemy5[i].y = -1;
		enemy5[i].atk = 100;
		enemy5[i].wide = 324;
		enemy5[i].high = 220;
	}

	for (i = 0; i < 1; i++)
	{
		enemy6[i].life = false;
		enemy6[i].hp = 4000;
		enemy6[i].x = -1;
		enemy6[i].y = -1;
		enemy6[i].atk = 100;
		enemy6[i].wide = 324;
		enemy6[i].high = 220;
	}

	//以下为子弹初始化
	for (i = 0; i < bul_max; i++)//先把所有子弹全都设置在界面外
	{   //玩家子弹
		bullet[i].life = false;
		bullet[i].x = -1;
		bullet[i].y = -1;
		bullet[i].atk = 15;
		bullet[i].wide = 9;
		bullet[i].high = 21;
	}

	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机2子弹
		enemy2_bullet[i].life = false;
		enemy2_bullet[i].x = -1;
		enemy2_bullet[i].y = -1;
		enemy2_bullet[i].atk = 15;
		enemy2_bullet[i].wide = 32;
		enemy2_bullet[i].high = 32;

	}
	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机3子弹
		enemy3_bullet[i].life = false;
		enemy3_bullet[i].x = -5;
		enemy3_bullet[i].y = -5;
		enemy3_bullet[i].atk = 30;
		enemy3_bullet[i].wide = 29;
		enemy3_bullet[i].high = 40;
	}

	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机4子弹
		enemy4_bullet[i].life = false;
		enemy4_bullet[i].x = -5;
		enemy4_bullet[i].y = -5;
		enemy4_bullet[i].atk = 30;
		enemy4_bullet[i].wide = 20;
		enemy4_bullet[i].high = 50;
	}

	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机5子弹
		enemy5_bullet[i].life = false;
		enemy5_bullet[i].x = -5;
		enemy5_bullet[i].y = -5;
		enemy5_bullet[i].atk = 30;
		enemy5_bullet[i].wide = 40;
		enemy5_bullet[i].high = 80;
	}

	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机6子弹
		enemy6_Sbullet[i].life = false;
		enemy6_Sbullet[i].x = -5;
		enemy6_Sbullet[i].y = -5;
		enemy6_Sbullet[i].atk = 30;
		enemy6_Sbullet[i].wide = 30;
		enemy6_Sbullet[i].high = 30;
	}
	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机6子弹
		enemy6_Lbullet[i].life = false;
		enemy6_Lbullet[i].x = -5;
		enemy6_Lbullet[i].y = -5;
		enemy6_Lbullet[i].atk = 30;
		enemy6_Lbullet[i].wide = 30;
		enemy6_Lbullet[i].high = 30;
	}
	for (i = 0; i < enemy_bul_max; i++)
	{   //敌机6子弹
		enemy6_Rbullet[i].life = false;
		enemy6_Rbullet[i].x = -5;
		enemy6_Rbullet[i].y = -5;
		enemy6_Rbullet[i].atk = 30;
		enemy6_Rbullet[i].wide = 30;
		enemy6_Rbullet[i].high = 30;
	}
}
bool IsContain_my(int x,int y,bool life)
{                 //x,y是敌机子弹或敌机的坐标
	double  x1, x2, x3, y1, y2, y3;
	x1 = plane.x + plane.wide / 2, y1 = plane.y + plane.high;//飞机头
	x2 = plane.x, y2 = plane.y + 55;//左侧机翼
	x3 = plane.x + plane.wide + 25, y3 = plane.y + 55;//右侧机翼

	if (life == true)
	{
		
		double xx1 = x - x1; double yy1 = y - y1;//MA
		double xx2 = x - x2; double yy2 = y - y2;//MB
		double xx3 = x - x3; double yy3 = y - y3;//MC


		double a = xx1 * yy2 - yy1 * xx2;//MA*MB
		double c = xx2 * yy3 - yy2 * xx3;//MB*MC
		double b = yy1 * xx3 - xx1 * yy3;//MC*MA,注意这个地方调换了顺序

		if (a < 0 && b < 0 && c < 0)
		{
			return true;
		}
		if (a > 0 && b > 0 && c > 0)
		{
			return true;
		}
		
	}

	x2 = plane.x + plane.wide / 3, y2 = plane.y;//左侧机尾
	x3 = plane.x + plane.wide + 25 - plane.wide / 3, y3 = plane.y;//右侧机尾

	if (life == true)
	{

		double xx1 = x - x1; double yy1 = y - y1;//MA
		double xx2 = x - x2; double yy2 = y - y2;//MB
		double xx3 = x - x3; double yy3 = y - y3;//MC


		double a = xx1 * yy2 - yy1 * xx2;//MA*MB
		double c = xx2 * yy3 - yy2 * xx3;//MB*MC
		double b = yy1 * xx3 - xx1 * yy3;//MC*MA,注意这个地方调换了顺序

		if (a < 0 && b < 0 && c < 0)
		{
			return true;
		}
		else if (a > 0 && b > 0 && c > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	

}
//用于判断敌方攻击是否攻击到我方飞机

bool IsContain_enemy(int x, int y,bool life_my_bullet, int x1, int y1, int x2, int y2, int x3, int y3, bool life_enemy)
{
	if (life_my_bullet == true && life_enemy == true)
	{

		double xx1 = x - x1; double yy1 = y - y1;//MA
		double xx2 = x - x2; double yy2 = y - y2;//MB
		double xx3 = x - x3; double yy3 = y - y3;//MC


		double a = xx1 * yy2 - yy1 * xx2;//MA*MB
		double c = xx2 * yy3 - yy2 * xx3;//MB*MC
		double b = yy1 * xx3 - xx1 * yy3;//MC*MA,注意这个地方调换了顺序

		if (a < 0 && b < 0 && c < 0)
		{
			return true;
		}
		else if (a > 0 && b > 0 && c > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
//用于判断我方攻击是否攻击到敌方飞机

//我方飞机函数实现
void AttackCreat()//创造子弹(这个地方要复习)
{

	int i;
	for (i = 0; i < bul_max; i++)
	{

		if (bullet[i].life == false)//判断bullet数组里的第i个位置是否有空位
			//若没有,则访问i+1的位置,直到找到空位
			//若一直没找到空位则说明屏幕上的子弹已满
		{
			bullet[i].x = plane.x + plane.wide / 2;
			bullet[i].y = plane.y + plane.high;
			bullet[i].life = true;
			break;//一次发射一颗子弹
		}
	}


}
void AttackMove()
{
	int i;
	for (i = 0; i < bul_max; i++)
	{
		if (bullet[i].life == true)
		{

			bullet[i].y += 3.5;
			if (bullet[i].y > highth + 20)
			{
				bullet[i].life = false;
			}

		}
	}
}
void Game()//玩家控制台
{

	if (GetAsyncKeyState(VK_UP))
	{
		if (plane.y < highth - 50)
		{
			Plane_Move(0, 5);
		}
	}
	if (GetAsyncKeyState(VK_DOWN))
	{
		if (plane.y > 0)
		{
			Plane_Move(0, -5);
		}
	}
	if (GetAsyncKeyState(VK_RIGHT))
	{
		if (plane.x < width - 50)
		{
			Plane_Move(5, 0);
		}
	}
	if (GetAsyncKeyState(VK_LEFT))
	{
		if (plane.x > -50)
		{
			Plane_Move(-5, 0);
		}
	}

	if (GetAsyncKeyState(VK_SPACE) && Timer(140))
	{
		AttackCreat();

	}

	if (GetAsyncKeyState(VK_MENU) && Timer2(3000))
	{
		if (supply_count >= 1)
		{
			supply_count -= 1;
			Enemy_Clean();
		}
	}

}
void Plane_Move(int x, int y)//飞机接收玩家控制,进行移动
{
	plane.x += x;
	plane.y += y;

}
void BulletCrush()
{
	

	int i, j;
	for (i = 0; i < bul_max; i++)//子弹射敌机1后判断敌机生死
	{
		for (j = 0; j < 10; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy1[j].x + enemy1[j].wide / 2, enemy1[j].y, enemy1[j].x,enemy1[j].y+enemy1[j].high,enemy1[j].x+enemy1[j].wide, enemy1[j].y + enemy1[j].high,enemy1[j].life))
			{   
					bullet[i].life = false;
					enemy1[j].hp -= bullet[i].atk;

					if (enemy1[j].hp <= 0)
					{
						score += enemy1_hp;
						//printf("%d\n", score);

						enemy1[j].life = false;

					}

				
			}
		}
	}

	for (i = 0; i < bul_max; i++)//子弹射敌机2后判断敌机生死
	{
		for (j = 0; j < 5; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy2[j].x + enemy2[j].wide / 2, enemy2[j].y, enemy2[j].x, enemy2[j].y + enemy2[j].high, enemy2[j].x + enemy2[j].wide, enemy2[j].y + enemy2[j].high, enemy2[j].life))
			{
				bullet[i].life = false;
				enemy2[j].hp -= bullet[i].atk;

				if (enemy2[j].hp <= 0)
				{
					score += enemy2_hp;
					//printf("%d\n", score);

					enemy2[j].life = false;

				}


			}
		}
	}

	for (i = 0; i < bul_max; i++)//子弹射击敌机3
	{
		for (j = 0; j < 3; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy3[j].x + enemy3[j].wide / 2, enemy3[j].y, enemy3[j].x, enemy3[j].y + enemy3[j].high, enemy3[j].x + enemy3[j].wide, enemy3[j].y + enemy3[j].high, enemy3[j].life))
			{
				bullet[i].life = false;
				enemy3[j].hp -= bullet[i].atk;

				if (enemy3[j].hp <= 0)
				{
					score += enemy3_hp;
					plane.hp += 10;
					//printf("%d\n", score);

					enemy3[j].life = false;

				}


			}
		}
	}

	for (i = 0; i < bul_max; i++)//子弹射击敌机4
	{
		for (j = 0; j < 3; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy4[j].x + enemy4[j].wide / 2, enemy4[j].y, enemy4[j].x, enemy4[j].y + enemy4[j].high, enemy4[j].x + enemy4[j].wide, enemy4[j].y + enemy4[j].high, enemy4[j].life))
			{
				bullet[i].life = false;
				enemy4[j].hp -= bullet[i].atk;

				if (enemy4[j].hp <= 0)
				{
					score += enemy4_hp;
					plane.hp += 3;
					//printf("%d\n", score);

					enemy4[j].life = false;

				}


			}
		}
	}

	for (i = 0; i < bul_max; i++)//子弹射击敌机5
	{
		for (j = 0; j < 1; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy5[j].x + enemy5[j].wide / 2, enemy5[j].y, enemy5[j].x, enemy5[j].y + enemy5[j].high, enemy5[j].x + enemy5[j].wide, enemy5[j].y + enemy5[j].high, enemy5[j].life))
			{
				bullet[i].life = false;
				enemy5[j].hp -= bullet[i].atk;

				if (enemy5[j].hp <= 0)
				{
					score += enemy5_hp;
					//printf("%d\n", score);

					enemy5[j].life = false;

				}


			}
		}
	}

	for (i = 0; i < bul_max; i++)//子弹射击敌机6
	{
		for (j = 0; j < 1; j++)
		{
			if (IsContain_enemy(bullet[i].x, bullet[i].y, bullet[i].life, enemy6[j].x + enemy6[j].wide / 2, enemy6[j].y, enemy6[j].x, enemy6[j].y + enemy6[j].high, enemy6[j].x + enemy6[j].wide, enemy6[j].y + enemy6[j].high, enemy6[j].life))
			{
				bullet[i].life = false;
				enemy6[j].hp -= bullet[i].atk;

				if (enemy6[j].hp <= 0)
				{
					score += enemy6_hp;
					//printf("%d\n", score);

					enemy6[j].life = false;
					Judge();

				}


			}
		}
	}

}
void Supply_Creat()
{
	if (score < 8000)
	{
		if (Timer_supply_creat(60000) && Boom[0].life == false && supply_count < 3)
		{
			Boom[0].life = true;
			Boom[0].x = rand() % (width - 60);
			Boom[0].y = rand() % highth + highth;
		}
	}
}
void Supply_Move()
{
	if (Boom[0].life)
	{
		Boom[0].y -= 0.5;
		if (Boom[0].y < -5)
		{
			Boom[0].life = false;
		}
	}
}
void Supply_Catch()
{
	int x, y;
	x = Boom[0].x + Boom[0].wide;
	y = Boom[0].y;
	if (IsContain_my(x,y, Boom[0].life))
	{
		Boom[0].life = false;
		supply_count += 1;
	}
}


//敌方飞机函数实现
void EnemyMove()
{
	int i;
	for (i = 0; i < 10; i++)//最小敌机前进,不发射子弹
	{
		if (enemy1[i].life == true)
		{
			enemy1[i].y -= 0.7;
			if (enemy1[i].y < 0)
			{
				enemy1[i].life = false;
			}
		}

	}
	for (i = 0; i < 5; i++)//中飞机,缓慢前进,并发射子弹
	{
		if (enemy2[i].life == true)
		{
			enemy2[i].y -= 0.2;
			if (enemy2[i].y < 0)
			{
				enemy2[i].life = false;
			}
		}
	}

	for (i = 0; i < 3; i++)//大飞机,左右移动,偶尔前进,并发射子弹
	{
		if (enemy3[i].life == true)
		{
			if (i == 0)//型号为0的飞机,奇数向左,偶数向右,且先向左
			{
				if (enemy3[i].y > highth - highth / 6)//先移动到画面中
				{
					enemy3[i].y -= 0.3;
				}
				else
				{
					if (enemy3_direct0 % 2 == 1)
					{
						enemy3[i].x -= 0.3;
						if (enemy3[i].x < 0)
						{
							enemy3_direct0++;
						}
					}
					if (enemy3_direct0 % 2 == 0)
					{
						enemy3[i].x += 0.3;
						if (enemy3[i].x + enemy3[i].wide> width)
						{
							enemy3_direct0++;
						}
					}
				}

			}
			if (i == 1)//型号为1的飞机,奇数向右,偶数向左,且先向右边
			{
				if (enemy3[i].y > highth - 2 * (highth / 6))//先移动到画面中
				{
					enemy3[i].y -= 0.3;
				}
				else
				{
					if (enemy3_direct1 % 2 == 0)
					{
						enemy3[i].x -= 0.3;
						if (enemy3[i].x < 0)
						{
							enemy3_direct1++;
						}
					}
					if (enemy3_direct1 % 2 == 1)
					{
						enemy3[i].x += 0.3;
						if (enemy3[i].x + enemy3[i].wide > width)
						{
							enemy3_direct1++;
						}
					}
				}

			}
			
			if (i == 2)//型号为2的飞机,奇数向左,偶数向右,且先向左
			{
				if (enemy3[i].y > highth - highth / 2)//先移动到画面中
				{
					enemy3[i].y -= 0.3;
				}
				else
				{
					if (enemy3_direct2 % 2 == 1)
					{
						enemy3[i].x -= 0.3;
						if (enemy3[i].x < 0)
						{
							enemy3_direct2++;
						}
					}
					if (enemy3_direct2 % 2 == 0)
					{
						enemy3[i].x += 0.3;
						if (enemy3[i].x + enemy3[i].wide > width)
						{
							enemy3_direct2++;
						}
					}
				}

			}
			


			if (enemy3[i].y < -3)
			{
		     	enemy3[i].life = false;
			}
		}
	}


	for (i = 0; i < 3; i++)//横行飞机,敌机4
	{
		if (enemy4[i].life)
		{
			enemy4[i].x += 0.5;
			if (enemy4[i].x > width + 5)
			{
				enemy4[i].life = false;
			}
		}
	}

	for (i = 0; i < 1; i++)//敌机5
	{
		if (enemy5[i].life)
		{
			if (enemy5[i].y > highth - enemy5[i].high)
			{
				enemy5[i].y -= 0.5;
			}
			else
			{
				if (enemy5_direct0 % 2 == 1)
				{
					if (enemy5[i].hp > 2000)
					{
						enemy5[i].x -= 0.5;
					}
					else if (enemy5[i].hp > 2000 && enemy5[i].hp <= 3000)
					{
						enemy5[i].x -= 0.6;
					}
					else if (enemy5[i].hp > 1000 && enemy5[i].hp <= 2000)
					{
						enemy5[i].x -= 0.7;
					}
					else
					{
						enemy5[i].x -= 0.9;
					}

					if (enemy5[i].x + 20 < 0)
					{
						enemy5_direct0++;
					}
				}
				if (enemy5_direct0 % 2 == 0)
				{
					if (enemy5[i].hp > 3000)
					{
						enemy5[i].x += 0.5;
					}
					else if (enemy5[i].hp > 2000 && enemy5[i].hp <= 3000)
					{
						enemy5[i].x += 0.6;
					}
					else if (enemy5[i].hp > 1000 && enemy5[i].hp <= 2000)
					{
						enemy5[i].x += 0.7;
					}
					else
					{
						enemy5[i].x += 0.9;
					}

					if (enemy5[i].x + enemy5[i].wide -20 > width)
					{
						enemy5_direct0++;
					}
				}
			}
			
		}
	}

	for (i = 0; i < 1; i++)
	{
		if (enemy6[i].life)
		{
			if (enemy6[i].y > highth - enemy6[i].high)
			{
				enemy6[i].y -= 0.5;
			}
			else
			{
				if (enemy6_direct0 % 2 == 1)
				{
					if (enemy6[i].hp > 2000)
					{
						enemy6[i].x -= 0.5;
					}
					else if (enemy6[i].hp > 2000 && enemy6[i].hp <= 3000)
					{
						enemy6[i].x -= 0.6;
					}
					else if (enemy6[i].hp > 1000 && enemy6[i].hp <= 2000)
					{
						enemy6[i].x -= 0.7;
					}
					else
					{
						enemy6[i].x -= 0.9;
					}

					if (enemy6[i].x + 20 < 0)
					{
						enemy6_direct0++;
					}
				}
				if (enemy6_direct0 % 2 == 0)
				{
					if (enemy6[i].hp > 3000)
					{
						enemy6[i].x += 0.5;
					}
					else if (enemy6[i].hp > 2000 && enemy6[i].hp <= 3000)
					{
						enemy6[i].x += 0.6;
					}
					else if (enemy6[i].hp > 1000 && enemy6[i].hp <= 2000)
					{
						enemy6[i].x += 0.7;
					}
					else
					{
						enemy6[i].x += 0.9;
					}

					if (enemy6[i].x + enemy6[i].wide - 20 > width)
					{
						enemy6_direct0++;
					}
				}
			}
		}
	}
}
void EnemyCreat_L1()
{
	int i, j;
	int count1 = 0, count2 = 0;
	if (Timer_enemycreat(3000))
	{
		for (i = 0; i < 10; i++)//敌机1
		{
			if (enemy1[i].life == false)
			{
				enemy1[i].life = true;
				enemy1[i].x = rand() % (width - 60);
				enemy1[i].y = rand() % highth + highth;
				enemy1[i].hp = 30;
				//n~m,n+rand()%(m-n+1)

				count1++;
				if (count1 == 2)
				{
					count1 = 0;
					break;
				}

			}
		}
		for (j = 0; j < 5; j++)//敌机2
		{
			if (enemy2[j].life == false)
			{
				enemy2[j].life = true;
				enemy2[i].hp = 50;
				enemy2[j].x = rand() % (width - 60);
				enemy2[j].y = rand() % (highth / 3) + highth;
					count2++;
					if (count2 == 1)
					{
						count2 = 0;
						break;
					}


			}
		}
		
		if (score > 2500)
		{
			for (j = 0; j < 3; j++)//敌机3
			{
				if (enemy3[j].life == false)
				{
					//printf("%d\n", count++);
					enemy3[j].life = true;
					enemy3[j].hp = 150;
					enemy3[j].x = rand() % (width - 60);
					enemy3[j].y = rand() % (highth / 3) + highth * 1.2;
					break;

				}
			}
		}
	}
}
void EnemyCreat_L2()
{
	int i, j;
	if (Timer_enemycreat(3000))
	{
		if (score > 5000 && score <=8000)
		{
			for (i = 0; i < 10; i++)//敌机1
			{
				if (enemy1[i].life == false)
				{
					enemy1[i].life = true;
					enemy1[i].x = rand() % (width - 60);
					enemy1[i].y = rand() % highth + highth;
					enemy1[i].hp = 30;
					break;
				}
			}
			for (j = 0; j < 3; j++)//敌机2,这个地方应该不会有问题
			{
				if (enemy2[j].life == false)
				{
					enemy2[j].life = true;
					enemy2[i].hp = 50;
					enemy2[j].x = rand() % (width - 60);
					enemy2[j].y = rand() % (highth / 3) + highth;
					break;

				}
			}

			for (j = 0; j < 3; j++)//敌机4
			{
				if (enemy4[j].life == false)
				{
					enemy4[j].life = true;
					enemy4[j].hp = 50;
					enemy4[j].x = -enemy4[i].wide * 1.5;
					enemy4[j].y = highth / 2 + rand() % (highth / 3);
					break;
				}
			}
		}
		if (score > 8000)
		{
			Enemy_Clean();
			supply_count = 0;
			for (j = 0; j < 1; j++)//敌机5
			{
				if (enemy5[j].life == false)
				{
					enemy5[j].life = true;
					enemy5[j].hp = 4000;
					enemy5[j].x = width / 2 - enemy5[j].wide / 2;
					enemy5[j].y = rand() % (highth / 3) + highth;
					break;
				}
			}
		}

	}
}
void EnemyCreat_L3()
{
	Enemy_Clean();
	supply_count = 0;
	int j;
	if (score < 17000)
	{
		for (j = 0; j < 1; j++)//敌机6
		{
			if (enemy6[j].life == false)
			{
				enemy6[j].life = true;
				enemy6[j].hp = 5000;
				enemy6[j].x = width / 2 - enemy5[j].wide / 2;
				enemy6[j].y = rand() % (highth / 3) + highth;
				break;
			}
		}
	}

}
void EnemyCrush()
{
	int j;
	int x, y;
	for (j = 0; j < 10; j++)//敌机1碰撞玩家时玩家扣血
	{
		x = enemy1[j].x + enemy1[j].wide / 2;
		y = enemy1[j].y;
		if (IsContain_my( x, y,enemy1[j].life))
		{
			enemy1[j].life = false;

			plane.hp -= enemy1[j].atk;

			Judge();
		}
	}
	for (j = 0; j < 5; j++)//敌机2碰撞玩家时玩家扣血
	{
		x = enemy2[j].x + enemy2[j].wide / 2;
		y = enemy2[j].y;
		if (IsContain_my( x, y,enemy2[j].life))
		{
			enemy2[j].life = false;

			plane.hp -= enemy2[j].atk;
			//printf("%d\n", plane.hp);
			Judge();
		}
	}

	for (j = 0; j < 3; j++)//敌机3碰撞玩家时玩家扣血
	{
		x = enemy3[j].x + enemy3[j].wide / 2;
		y = enemy3[j].y;
		if (IsContain_my(x, y, enemy3[j].life))
		{
			enemy3[j].life = false;

			plane.hp -= enemy3[j].atk;
			Judge();
		}
	}

	for (j = 0; j < 3; j++)//敌机4碰撞玩家时玩家扣血
	{
		int x2, y2;
		x = enemy4[j].x + enemy4[j].wide / 2;
		y = enemy4[j].y;
		x2 = enemy4[j].x + enemy4[j].wide / 2;
		y2 = enemy4[j].y + enemy4[j].high;
		if (IsContain_my(x, y, enemy4[j].life) == true || IsContain_my(x2, y2, enemy4[j].life))
		{
			enemy4[j].life = false;

			plane.hp -= enemy4[j].atk;
			//printf("%d\n", plane.hp);
			Judge();
		}
	}

	for (j = 0; j < 1; j++)//敌机5碰撞玩家时玩家扣血
	{
		int x2, y2, x3, y3, x4, y4;
		x = enemy5[j].x + enemy5[j].wide / 2;
		y = enemy5[j].y;
		x2 = enemy5[j].x + enemy5[j].wide / 2;
		y2 = enemy5[j].y + enemy5[j].high;
		x3 = enemy5[j].x + 10;
		y3 = enemy5[j].y + enemy5[j].high / 2;
		x4 = enemy5[j].x + enemy5[j].wide - 10;
		y4 = enemy5[j].y + enemy5[j].high / 2;

		if (IsContain_my(x, y, enemy5[j].life) || IsContain_my(x2, y2, enemy5[j].life) || IsContain_my(x3, y3, enemy5[j].life) || IsContain_my(x4, y4, enemy5[j].life))
		{
			enemy5[j].life = false;

			plane.hp -= enemy5[j].atk;
			//printf("%d\n", plane.hp);
			Judge();
		}
	} 

	for (j = 0; j < 1; j++)//敌机6碰撞玩家时玩家扣血
	{
		int x2, y2, x3, y3, x4, y4;
		x = enemy6[j].x + enemy6[j].wide / 2;
		y = enemy6[j].y;
		x2 = enemy6[j].x + enemy6[j].wide / 2;
		y2 = enemy6[j].y + enemy6[j].high;
		x3 = enemy6[j].x + 10;
		y3 = enemy6[j].y + enemy6[j].high / 2;
		x4 = enemy6[j].x + enemy6[j].wide - 10;
		y4 = enemy6[j].y + enemy6[j].high / 2;

		if (IsContain_my(x, y, enemy6[j].life) || IsContain_my(x2, y2, enemy6[j].life) || IsContain_my(x3, y3, enemy6[j].life) || IsContain_my(x4, y4, enemy6[j].life))
		{
			enemy6[j].life = false;

			plane.hp -= enemy6[j].atk;
			//printf("%d\n", plane.hp);
			Judge();
		}
	}

}
void Enemy_Bullet_Creat()
{
	int i, j;
	if (Timer_enemy2_bullet_creat(5000))//子弹发射频率
	{
		for (j = 0; j < 5; j++)
		{
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy2_bullet[i].life == false && enemy2[j].life == true)
				{
					enemy2_bullet[i].life = true;
					enemy2_bullet[i].x = enemy2[j].x + enemy2[j].wide / 2 - 33;
					enemy2_bullet[i].y = enemy2[j].y;
					break;
				}
			}
		}
	}
	int count3 = 1;
	
	if (Timer_enemy3_bullet_creat(7000))
	{
		for (j = 0; j < 3; j++)
		{
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy3_bullet[i].life == false && enemy3[j].life == true)
				{
					if (count3 == 1)
					{
						enemy3_bullet[i].life = true;
						enemy3_bullet[i].x = enemy3[j].x + enemy3[j].wide / 4 - 15;
						enemy3_bullet[i].y = enemy3[j].y;
						count3++;
						continue;
					//i += 1;
					}
					if (count3 == 2)
					{
						enemy3_bullet[i].life = true;
						enemy3_bullet[i].x = enemy3[j].x + (enemy3[j].wide / 4) * 3 - 15;
						enemy3_bullet[i].y = enemy3[j].y;
						count3 = 1;
						break;
					}
				}
			}
		}
	}
	
	if (Timer_enemy4_bullet_creat(3000))
	{
		for (j = 0; j < 3; j++)
		{
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy4_bullet[i].life == false && enemy4[j].life == true)
				{
					enemy4_bullet[i].life = true;
					enemy4_bullet[i].x = enemy4[j].x + enemy4[j].wide / 2;
					enemy4_bullet[i].y = enemy4[j].y;
					break;
				}
			}
		}
	}

	int count5 = 1;

	if (Timer_enemy5_bullet_creat(400))
	{
		for (j = 0; j < 1; j++)
		{
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy5_bullet[i].life == false && enemy5[j].life == true)
				{
					enemy5_bullet[i].life = true;
					if (count5 == 1)
					{
						enemy5_bullet[i].x = enemy5[j].x + 38;
						enemy5_bullet[i].y = enemy5[j].y + 37;
						count5 += 1;
						continue;
					}

					if (count5 == 2)
					{
						count5 = 1;
						enemy5_bullet[i].x = enemy5[j].x +enemy5[j].wide - 73;
						enemy5_bullet[i].y = enemy5[j].y + 37;
						break;
					}
					
				}
			}
		}
	}

	int count6 = 1;
	if (Timer_enemy6_bullet_creat(2000))
	{
		for (j = 0; j < 1; j++)
		{
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy6_Sbullet[i].life == false && enemy6[j].life == true)
				{
					enemy6_Sbullet[i].life = true;
					if (count6 == 1)
					{
						enemy6_Sbullet[i].x = enemy6[j].x + 38;
						enemy6_Sbullet[i].y = enemy6[j].y + 37;
						count6 += 1;
						continue;
					}

					if (count6 == 2)
					{
						enemy6_Sbullet[i].x = enemy6[j].x + enemy6[j].wide - 73;
						enemy6_Sbullet[i].y = enemy6[j].y + 37;
						count6 = 1;
						break;
					}
				}
			}

			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy6_Lbullet[i].life == false && enemy6[j].life == true)
				{
					enemy6_Lbullet[i].life = true;
					if (count6 == 1)
					{
						enemy6_Lbullet[i].x = enemy6[j].x + 38;
						enemy6_Lbullet[i].y = enemy6[j].y + 37;
						count6 += 1;
						continue;
					}

					if (count6 == 2)
					{
						enemy6_Lbullet[i].x = enemy6[j].x + enemy6[j].wide - 73;
						enemy6_Lbullet[i].y = enemy6[j].y + 37;
						count6 = 1;
						break;
					}
				}
			}
			for (i = 0; i < enemy_bul_max; i++)
			{
				if (enemy6_Rbullet[i].life == false && enemy6[j].life == true)
				{
					enemy6_Rbullet[i].life = true;
					if (count6 == 1)
					{
						enemy6_Rbullet[i].x = enemy6[j].x + 38;
						enemy6_Rbullet[i].y = enemy6[j].y + 37;
						count6 += 1;
						continue;
					}

					if (count6 == 2)
					{
						enemy6_Rbullet[i].x = enemy6[j].x + enemy6[j].wide - 73;
						enemy6_Rbullet[i].y = enemy6[j].y + 37;
						count6 = 1;
						break;
					}
				}
			}
					
		}
	}
	
}
void Enemy_Bullet_Move()
{
	int i;

	//敌机2
	for (i = 0; i < enemy_bul_max; i++)
	{

		if (enemy2_bullet[i].life == true)
		{


			enemy2_bullet[i].y -= 0.6;
			
			if (enemy2_bullet[i].y < -5)
			{
				enemy2_bullet[i].life = false;
			}


		}
	}

	//敌机3
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy3_bullet[i].life == true)
		{
			enemy3_bullet[i].y -= 0.6;
			if (enemy3_bullet[i].y < -3)
			{
				enemy3_bullet[i].life = false;
			}
		}
	}

	//敌机4
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy4_bullet[i].life == true)
		{
			enemy4_bullet[i].y -= 0.7;
			if (enemy4_bullet[i].y < -3)
			{
				enemy4_bullet[i].life = false;
			}
		}
	}

	//敌机5
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy5_bullet[i].life == true)
		{
			enemy5_bullet[i].y -= 1;
			if (enemy5_bullet[i].y < -3)
			{
				enemy5_bullet[i].life = false;
			}
		}
	}

	//敌机6
	for (i = 0; i < enemy_bul_max; i++)
	{
		if (enemy6_Sbullet[i].life == true)
		{
			enemy6_Sbullet[i].y -= 1;
		}
			


			if (enemy6_Lbullet[i].life == true)
			{
				enemy6_Lbullet[i].y -= 1;
				enemy6_Lbullet[i].x -= 0.5;
			}

			if (enemy6_Rbullet[i].life == true)
			{
				enemy6_Rbullet[i].y -= 1;
				enemy6_Rbullet[i].x += 0.5;
				
			}

			if (enemy6_Sbullet[i].y < -3)
			{
				enemy6_Sbullet[i].life = false;
			}
			if (enemy6_Lbullet[i].y < -3)
			{
				enemy6_Lbullet[i].life = false;
			}
			if (enemy6_Rbullet[i].y < -3)
			{
				enemy6_Rbullet[i].life = false;
			}
		
	}
	
	
}
void Enemy_Bullet_Crush()
{
	int i;
	int x, y;
	//敌机2子弹碰撞玩家扣血
	for (i = 0; i < enemy_bul_max; i++)
	{
		x = enemy2_bullet[i].x + enemy2_bullet[i].wide / 2;
		y = enemy2_bullet[i].y;
		if (IsContain_my( x, y, enemy2_bullet[i].life))
		{
			enemy2_bullet[i].life = false;
			plane.hp -= enemy2_bullet[i].atk;
			Judge();
		}
	}

	//敌机3子弹碰撞玩家扣血
	for (i = 0; i < enemy_bul_max; i++)
	{
		x = enemy3_bullet[i].x + enemy3_bullet[i].wide / 2;
		y = enemy3_bullet[i].y;
		if (IsContain_my(x, y, enemy3_bullet[i].life))
		{
			enemy3_bullet[i].life = false;
			plane.hp -= enemy3_bullet[i].atk;
			Judge();
		}
	}

	//敌机4子弹碰撞玩家扣血
	for (i = 0; i < enemy_bul_max; i++)
	{
		x = enemy4_bullet[i].x + enemy4_bullet[i].wide / 2;
		y = enemy4_bullet[i].y;
		if (IsContain_my(x, y, enemy4_bullet[i].life))
		{
			enemy4_bullet[i].life = false;
			plane.hp -= enemy4_bullet[i].atk;
			Judge();
		}
	}

	//敌机5子弹碰撞玩家扣血
	for (i = 0; i < enemy_bul_max; i++)
	{
		x = enemy5_bullet[i].x + enemy5_bullet[i].wide / 2;
		y = enemy5_bullet[i].y;
		if (IsContain_my(x, y, enemy5_bullet[i].life))
		{
			enemy5_bullet[i].life = false;
			plane.hp -= enemy5_bullet[i].atk;
			Judge();
		}
	}

	//敌机6子弹碰撞玩家扣血
	for (i = 0; i < enemy_bul_max; i++)
	{
		x = enemy6_Sbullet[i].x + enemy6_Sbullet[i].wide / 2;
		y = enemy6_Sbullet[i].y;
		if (IsContain_my(x, y, enemy6_Sbullet[i].life))
		{
			enemy6_Sbullet[i].life = false;
			plane.hp -= enemy6_Sbullet[i].atk;
			Judge();
		}

		x = enemy6_Lbullet[i].x + enemy6_Lbullet[i].wide / 2;
		y = enemy6_Lbullet[i].y;
		if (IsContain_my(x, y, enemy6_Lbullet[i].life))
		{
			enemy6_Lbullet[i].life = false;
			plane.hp -= enemy6_Lbullet[i].atk;
			Judge();
		}

		x = enemy6_Rbullet[i].x + enemy6_Rbullet[i].wide / 2;
		y = enemy6_Rbullet[i].y;
		if (IsContain_my(x, y, enemy6_Rbullet[i].life))
		{
			enemy6_Rbullet[i].life = false;
			plane.hp -= enemy6_Rbullet[i].atk;
			Judge();
		}
	}
}
#include <conio.h>
#include<graphics.h>
#include"game.h"
#include <iostream>
#include<stdio.h>
#include<easyx.h>
#include<windows.h>
#include<mmsystem.h>
#pragma comment(lib,"Winmm.lib")
#define _CRT_SECURE_NO_WARNINGS
#define width 624
#define highth 960
#define bul_max 100//屏幕上同时出现的子弹上限
IMAGE Start;
IMAGE loading;

int count = 1;
int main()
{
	if (count == 1)
	{
		BeginMenu(10, 20);
	}

	srand((unsigned int)time(NULL));
	initgraph(width, highth);
	setaspectratio(1, -1);
	setorigin(0, highth);
	if (count == 1)
	{
		loadimage(&Start, L"E:\\飞机大战素材\\begin.jpg");
		loadimage(&loading, L"E:\\飞机大战素材\\load(1).jpg");
		putimage(0, 0, &Start);
		putimage(160, highth / 7, &loading);
		//Sleep(2000);
		count += 1;
	}

	GameInit();
	//LoadBgm();
	LoadImg();

	BeginBatchDraw();//双缓冲绘图
	while (1)
	{
		level_change();
		if (level() == 1)
		{
			EnemyCreat_L1();
		}
		if (level() == 2)
		{
			EnemyCreat_L2();
		}
		if (level() == 3)
		{
			EnemyCreat_L3();
		}

		EnemyMove();
		AttackMove();
		BulletCrush();
		EnemyCrush();
		Enemy_Bullet_Creat();
		Enemy_Bullet_Move();
		Enemy_Bullet_Crush();
		Supply_Creat();
		Supply_Move();
		Supply_Catch();
		GameDraw();
		Game();
		FlushBatchDraw();
	}
	EndBatchDraw();
	closegraph();
	return 0;

}
#pragma once
#define _CRT_SECURE_NO_WARNINGS
void LoadImg();
bool Timer(int ms);
void GameDraw();
void EnemyMove();
void EnemyCreat_L1();
void EnemyCreat_L2();
void EnemyCreat_L3();
void Plane_Move(int x, int y);
void GameInit();
bool IsContain(int j);
void BulletCrush();
void EnemyCrush();
void AttackCreat();
void Game();
void AttackMove();
//void LoadBgm();
void Enemy_Bullet_Creat();
void Enemy_Bullet_Move();
void Enemy_Bullet_Crush();
void BeginMenu(int x, int y);
void Judge();
int level();
void level_change();
void Enemy_Bullet_Move();
void Supply_Creat();
void Supply_Move();
void Supply_Catch();
void EndMenu();

记得要把属性从Unicode改为多字节

以上是源代码,且需要用到easyx图形库,飞机大战素材包的原图以及掩码图可以私信找我要,有什么不懂也可以私信,以下是游戏的一些截图

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值