紧急除颤

#include<iostream>
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<Windows.h>
#include<string>
#include<iomanip>
#pragma comment(lib,"Winmm.lib")
#define REP(i, x, y) for(int i = (x);i <= (y);i++)
using namespace std;


int dialogX, dialogY;//记录对话框的左上角位置

struct Player {
	int x, y, preX, preY;
	int anim;
	}plane;//控制台小飞机


void Handle(bool flag) { 
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cci;
	GetConsoleCursorInfo(hOut, &cci);
	cci.bVisible = flag;
	SetConsoleCursorInfo(hOut, &cci);
	}
//隐藏控制台光标


void SetConsole(int x, int y) 

	{

	COORD position;
	position.X = y;//坐标轴与行列不同
	position.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);

	}
//建立函数 移动光标 第一个参数为行

void Clear(int x, int y, int lenth) { 
	SetConsole(x, y);
	REP(i, 1, lenth)
		printf(" ");
	}
//清除第x行y列开始的控制台输出 注:清除完后需要重定向

void Print(string s, int t) { 
	for (int i = 0; i < s.size(); i++) { //使用UNICODE
		if (s[i] < 0) { //汉字
			cout << s[i] << s[i + 1];
			i++;
			}
		else cout << s[i];//字母
		Sleep(t);
		}
	}
//实现间隔一定时间输出一个字

void Loading() {
	for (int i = 1; i <= 5; i++) { 
		printf("/ ");
		Sleep(200); printf("\b\b");
		printf("- ");
		Sleep(200); printf("\b\b");
		printf("\\ ");
		Sleep(200); printf("\b\b");
		printf("| ");
		Sleep(200); printf("\b\b");
		}
	printf("  ");
	}
//转圈圈

void DrawDialogBox(int x, int y, int numLine) { 
	SetConsole(x, y);
	printf(" ————————");
	for (int i = 1; i <= numLine - 2; i++) {
		SetConsole(x + i, y);
		if (i == 1) {
			printf("| ");
			cout << std::left << setw(15) << "";
			printf("\\___________________________________________");
			}
		else if (i == 2) {
			printf("| ");
			cout << std::left << setw(16) << " ";
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
									| FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED);
			printf("                                           ");//输出背景色为黄色
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
									| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
			}
		else if (i == 8) {
			printf("|                                         ");
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
									| FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
			printf(" ///G&K MWCS V1.28 ");
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
									| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
			printf("|");
			}
		else printf("|                                                            |");
		}
	SetConsole(x + numLine - 1, y);
	printf(" ——————————————————————————————");
	}
//从第x行y列开始绘制一个高度为numLine的对话框

void AnimDialogue(int x, int y) {
	dialogX = x, dialogY = y;
	SetConsole(x + 5, y);
	Print(" ——————————————————————————————", 10);
	Clear(x + 5, y, 80);
	SetConsole(x + 4, y);
	printf(" ——————————————————————————————");
	SetConsole(x + 5, y);
	printf("|                                                            |");
	SetConsole(x + 6, y);
	printf(" ——————————————————————————————");


	Sleep(60);
	for(int i = 4;i <= 6;i++)Clear(x + i, y, 80);
	DrawDialogBox(x + 3, y, 5);

	Sleep(60);
	for (int i = 3; i <= 7; i++)Clear(x + i, y, 80);
	DrawDialogBox(x + 2, y, 7);

	Sleep(60);
	for (int i = 2; i <= 8; i++)Clear(x + i, y, 80);
	DrawDialogBox(x + 1, y, 9);

	Sleep(60);
	for (int i = 1; i <= 9; i++)Clear(x + i, y, 80);
	DrawDialogBox(x, y, 10);
	}
//从第x行开始模拟动画并绘制对话窗口

void DrawMap(int x1, int x2, int y, int lenth) {
	SetConsole(x1, y);
	printf(" ");
	REP(i, 1, lenth)
		printf("—");
	REP(i, x1 + 1, x2 - 1) {
		SetConsole(i, y);
		printf("|");
		REP(j, 1, lenth * 2)
			printf(" ");
		printf("|");
		}
	SetConsole(x2, y);
	printf(" ");
	REP(i, 1, lenth)
		printf("—");
	}
//绘制从x1到x2的控制台操作窗口

void AnimMap(int x1, int x2, int y, int lenth) { 
	int mid = (x1 + x2) / 2;
	SetConsole(mid, y);
	Print(" ", 3);
	REP(i, 1, lenth)
		Print("—", 3);
	REP(i, 1, (x2 - x1) / 2) { 
		DrawMap(mid - i, mid + i, y, lenth);
		Sleep(10);
		}
	}
//绘制控制台操控窗口(x2 - x1 + 1是奇数才行)

void BackgroundWhite() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
							| FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED
							| BACKGROUND_BLUE);
	}
void BackgroundBlack() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
							| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	}
void ForeGreen() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
							| FOREGROUND_GREEN);
	}
void ForeYellow() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
							| FOREGROUND_RED | FOREGROUND_GREEN);
	}

void DrawG(int x, int y) {
	SetConsole(x, y); BackgroundWhite();
	printf("           "); SetConsole(x + 1, y);
	printf("  "); SetConsole(x + 2, y);
	printf("  "); SetConsole(x + 3, y);
	printf("  "); BackgroundBlack(); printf("   "); BackgroundWhite(); printf("      "); SetConsole(x + 4, y);
	printf("  "); BackgroundBlack(); printf("       "); BackgroundWhite(); printf("  "); SetConsole(x + 5, y);
	printf("  "); BackgroundBlack(); printf("       "); BackgroundWhite(); printf("  "); SetConsole(x + 6, y);
	printf("           "); 
	BackgroundBlack();
	}
void Drawand(int x, int y) { 
	x++;//比其他两个字母少一行
	y -= 2;//画的时候多了两格出来
	SetConsole(x, y + 5); BackgroundWhite();
	printf("   "); 
	SetConsole(x + 1, y + 4); printf(" ");
	SetConsole(x + 1, y + 8); printf(" ");
	SetConsole(x + 2, y + 5); printf("   ");
	SetConsole(x + 3, y + 3); printf("  "); SetConsole(x + 3, y + 7); printf(" ");
	SetConsole(x + 3, y + 9); printf(" ");
	SetConsole(x + 4, y + 2); printf("  "); SetConsole(x + 4, y + 8); printf(" ");
	SetConsole(x + 5, y + 3); printf("     "); SetConsole(x + 5, y + 9); printf("  ");
	BackgroundBlack();
	}
void DrawK(int x, int y) { 
	BackgroundWhite();
	SetConsole(x, y);printf("  "); SetConsole(x, y + 8); printf("  ");
	SetConsole(x + 1, y); printf("  "); SetConsole(x + 1, y + 6); printf("  ");
	SetConsole(x + 2, y); printf("  "); SetConsole(x + 2, y + 4); printf("  ");
	SetConsole(x + 3, y); printf("    ");
	SetConsole(x + 4, y); printf("  "); SetConsole(x + 4, y + 4); printf("  ");
	SetConsole(x + 5, y); printf("  "); SetConsole(x + 5, y + 6); printf("  ");
	SetConsole(x + 6, y); printf("  "); SetConsole(x + 6, y + 8); printf("   ");
	BackgroundBlack();
	}
void DrawGandK(int x, int y) {
	DrawG(x, y);
	Drawand(x, y + 14);
	DrawK(x, y + 26);
	}
//绘制格里芬

void PrintDialogue(string speaker, string dialogue, int speed) {
	int x = dialogX, y = dialogY;
	SetConsole(x + 1, y + 6);
	printf("         ");
	SetConsole(x + 1, y + 6);
	cout << speaker;
	Clear(x + 5, y + 4, 57);
	SetConsole(x + 5, y + 4);
	Print(dialogue, speed);
	//SetConsole(x + 10, y);
	GetAsyncKeyState(VK_SPACE);//得先把缓存区的东西吃掉
	while (!GetAsyncKeyState(VK_SPACE));
	}
//输出对话,定位跟随对话框

int consoleX, consoleY;
void PrintConsole(int x, string content, int speed, bool stop) { 
	SetConsole(consoleX + x, consoleY);
	cout << "                                 ";
	SetConsole(consoleX + x, consoleY);
	Print(content, speed);
	if (stop) {
		GetAsyncKeyState(VK_SPACE);//得先把缓存区的东西吃掉
		while (!GetAsyncKeyState(VK_SPACE));
		}
	}
//从控制台第x行输出控制台内容(从0开始)


void PrintPlane() { 
	//(x, y)为机头坐标 所以-2
	switch (plane.anim) { //先写绘制
		case 0 :
			SetConsole(plane.x, plane.y - 2);
			printf("  |");
			SetConsole(plane.x + 1, plane.y - 2);
			printf("———");
			SetConsole(plane.x + 2, plane.y - 2);
			printf(" |  |");
			break;
		case 1 :
			SetConsole(plane.x, plane.y - 2);
			printf("  |/");
			SetConsole(plane.x + 1, plane.y - 2);
			printf("  /|");
			SetConsole(plane.x + 2, plane.y - 2);
			printf(" /|");
			break;
		case 2 :
			SetConsole(plane.x, plane.y - 2);
			printf(" \\|");
			SetConsole(plane.x + 1, plane.y - 2);
			printf(" |\\");
			SetConsole(plane.x + 2, plane.y - 2);
			printf("  |\\");
			break;
		}
	}
//每循环擦除上一次动画并绘制本次动画

void PositionJudge() {
	if (plane.x < 1)plane.x = 1;
	if (plane.x > 37)plane.x = 37;
	if (plane.y < 3)plane.y = 3;
	if (plane.y > 61)plane.y = 61;
	}

void MovePlane(int speed) { 
	plane.preX = plane.x, plane.preY = plane.y;
	Clear(plane.preX, plane.preY - 2, 6);
	Clear(plane.preX + 1, plane.preY - 2, 6);
	Clear(plane.preX + 2, plane.preY - 2, 6);
	if (GetAsyncKeyState('W'))plane.x -= speed;
	if (GetAsyncKeyState('S'))plane.x += speed;
	if (GetAsyncKeyState('A'))plane.y -= speed;
	if (GetAsyncKeyState('D'))plane.y += speed;
	PositionJudge();
	if (plane.y == plane.preY)plane.anim = 0;
	else if(plane.y < plane.preY)plane.anim = 1;
	else plane.anim = 2;
	PrintPlane();
	}


void Init() {
	system("mode con cols=130 lines=45");//修改控制台大小防bug
	plane.x = plane.preX = 37;
	plane.y = plane.preY = 33;
	plane.anim = 0;

	consoleX = 21, consoleY = 68;//初始化输出控制台位置(对话框单独函数初始化过位置了
	}

int consolePlaneLeftTime = 10000;
bool ConsolePlane() {
	MovePlane(1);
	Sleep(100);
	consolePlaneLeftTime -= 100;
	if (consolePlaneLeftTime < 0)return 0;
	if (consolePlaneLeftTime < 7000) {
		SetConsole(consoleX + 1, consoleY);
		cout << "通讯记录云同步信号: ";
		ForeYellow(); cout << "一般"; BackgroundBlack();
		
		}
	if (consolePlaneLeftTime < 6400) {
		SetConsole(consoleX + 1, consoleY);
		cout << "通讯记录云同步信号: ";
		ForeGreen(); cout << "良好"; BackgroundBlack();
		}
	return 1;
	}

void Chapter1() { 
	puts("GRIFFIN & KRYUGER Combat Operation System[版本 10.0.19042.1348]");
	puts("(c) GRIFFIN & KRYUGER Corporation。保留所有权利。\n");
	printf("C:\\Users\\Commander>");
	Sleep(3000);
	Print("-", 1000);
	Print("init", 150);
	Print(" ", 1500);
	Print("-MWCS", 150);
	Print(" ", 600);
	Print("access_416", 100);
	Sleep(2500);
	Handle(FALSE);
	Print("\n通讯模块初始化", 60);
	Sleep(500);
	Loading();
	puts("");
	Print("通讯模块加载完毕", 60);
	Print("...", 500);
	Sleep(1000);
	for (int i = 0; i < 6; i++)Clear(i, 0, 80);
	SetConsole(0, 0);
	Handle(TRUE);
	Sleep(3000);
	Handle(FALSE);
	DrawGandK(1, 79);
	Sleep(1000);
	AnimDialogue(10, 66);
	AnimMap(20, 40, 66, 30);
	SetConsole(20, 66); printf("|");
	BackgroundWhite();
	printf(" ▅  C:\\COS\\System32\\cmd.exe                                 ");
	BackgroundBlack();
	printf("|");
	PrintDialogue("格琳娜", "微波通讯系统(MWCS)启动,在你的系统上按下空格进行通讯。", 60);
	//没写分行 这句差不多是单句最长了
	PrintConsole(1, "通讯记录云同步信号: 测速中", 60, false);
	Sleep(1000);
	PrintConsole(1, "通讯记录云同步信号: ", 0, false);
	ForeGreen(); cout << "良好"; BackgroundBlack();
	Sleep(400);
	PrintDialogue("格琳娜", "进行身份认证,", 60);
	PrintDialogue("格琳娜", "格里芬直属404小队通讯员,格琳娜。", 60);
	PrintDialogue("指挥官", "404小队飞行系统操作员,代号“指挥官”。", 60);
	PrintConsole(2, " >声纹代码认证成功", 60, true);
	SetConsole(consoleX + 1, consoleY);
	cout << "通讯记录云同步信号: ";
	ForeYellow(); cout << "一般"; BackgroundBlack();
	Sleep(600);
	SetConsole(consoleX + 1, consoleY);
	cout << "通讯记录云同步信号: ";
	ForeGreen(); cout << "良好"; BackgroundBlack();
	Sleep(400);
	PrintConsole(2, " >飞行系统接入中", 60, true);
	PrintDialogue("指挥官", "正在接入飞行系统。", 60);
	PrintDialogue("指挥官", "怎么样小格,休息够了么?", 60);
	PrintConsole(2, " >飞行系统连接成功", 60, true);
	PrintDialogue("格琳娜", "接入成功,各模块开始自检。", 60);
	PrintConsole(2, " >模块自检中", 60, false);

	PrintDialogue("格琳娜", "完 全 没 有 休 息 够 !", 100);
	SetConsole(consoleX + 1, consoleY);
	cout << "通讯记录云同步信号: ";
	ForeYellow(); cout << "一般"; BackgroundBlack();
	Sleep(600);
	SetConsole(consoleX + 1, consoleY);
	cout << "通讯记录云同步信号: ";
	ForeGreen(); cout << "良好"; BackgroundBlack();
	Sleep(400);
	PrintDialogue("格琳娜", "天天加班演习演习演习,然后还得熬夜写报告书。", 60);
	PrintDialogue("格琳娜", "老板也不发点加班费意思一下。", 60);
	PrintDialogue("格琳娜", "再这么下去我要离职了啊,天天都掉头发。", 60);
	PrintDialogue("指挥官", "好啦好啦,现在军方和铁血的局势很紧张。", 60);
	PrintDialogue("指挥官", "格里芬又一直和军方有合作,咱任务总会变多的。", 60);
	PrintDialogue("格琳娜", "这我当然知道!", 60);
	PrintDialogue("指挥官", "(苦笑)", 60);
	PrintDialogue("格琳娜", "...希望能和平解决吧。铁血那边也有我很好的朋友。", 60);
	PrintDialogue("指挥官", "......嗯。", 60);
	PrintConsole(2, " >模块自检完成", 60, true);
	PrintConsole(3, " >正在初始化", 60, true);
	PrintDialogue("格琳娜", "各模块自检完毕,开始初始化。现在颁布演习任务,", 60);

	PrintDialogue("格琳娜", "404小队将在演习中对抗敌机以测试格里芬最新原型机的性能,", 60);
	PrintDialogue("格琳娜", "敌机为军方制造的一批仿真铁血机型,", 60);
	PrintDialogue("格琳娜", "以下为敌机清单...", 60);
	PrintConsole(5, "任务目标:歼灭敌机", 60, false);
	PrintConsole(6, "敌方机型:", 30, false);
	PrintConsole(7, "Scarecrow", 30, false);
	PrintConsole(8, "Executioner", 30, false);
	PrintConsole(9, "Hunter", 30, false);
	PrintConsole(10, "Disruptor", 30, false);
	PrintConsole(11, "Destroyer", 30, false);
	PrintConsole(12, "Alchemist", 30, true);

	PrintDialogue("指挥官", "收到。", 60);
	PrintDialogue("格琳娜", "格里芬的新原型机啊...", 60);
	PrintDialogue("格琳娜", "再不加工资的话,咱给它开走拿去卖了。", 60);
	PrintDialogue("指挥官", "哈小格,你知道通讯记录是会实时同步到格里芬云端的吧。", 60);
	PrintDialogue("格琳娜", "我当然知道。", 60);
	PrintDialogue("格琳娜", "嘿嘿老板不给加班费拿人手短,他不会说我什么的。", 60);
	PrintDialogue("格琳娜", "不开玩笑了,我看了下清单,这批铁血机型做得很逼真啊。", 60);
	PrintDialogue("指挥官", "是的。", 60);

	PrintConsole(12, " ", 60, false);
	PrintConsole(11, " ", 60, false);
	PrintConsole(10, " ", 60, false);
	PrintConsole(9, " ", 60, false);
	PrintConsole(8, " ", 60, false);
	PrintConsole(7, " ", 60, false);
	PrintConsole(6, " ", 60, false);
	PrintConsole(5, " ", 60, true);
	PrintConsole(3, " >初始化完成", 60, true);
	PrintConsole(4, " >加载操作模块", 60, true);
	PrintDialogue("格琳娜", "好,初始化完成,正在加载操作模块。", 60);
	PrintConsole(4, " >操作模块加载完成", 60, true);
	PrintDialogue("格琳娜", "加载完成,映射到你的系统上,使用WASD控制原型机。", 60);
	SetConsole(0, 0);
	AnimMap(0, 40, 0, 32);//行0-19 20 21-40

	while (ConsolePlane());
	plane.anim = 0;//最后把飞机姿态摆正
	plane.preX = plane.x, plane.preY = plane.y;
	Clear(plane.preX, plane.preY - 2, 6);
	Clear(plane.preX + 1, plane.preY - 2, 6);
	Clear(plane.preX + 2, plane.preY - 2, 6);
	PrintPlane();

	PrintDialogue("格琳娜", "操作模块工作正常,即将载入视觉模块。", 60);
	PrintConsole(5, " >加载视觉模块", 60, true);
	PrintDialogue("格琳娜", "指挥官,准备好了吗?", 60);
	PrintDialogue("指挥官", "呼,", 120);
	Print("准备好了。", 60);
	Sleep(1000);
	PrintConsole(5, " >视觉模块加载完成", 60, false);
	BackgroundWhite();
	REP(i, 0, 45) {
		SetConsole(i, 0);
		REP(j, 0, 129) {
			cout << " ";
			}
		Sleep(20);
		}
	}

/// <summary>
/// 下面是图形界面部分
/// </summary>

int runTime;//异步计时器

IMAGE img_background;//背景图 850 * 1700
IMAGE img_backbackground;//1280 * 720 底图
IMAGE img_gundam[2];//单图 70 * 85
IMAGE img_rush[2];//同上
IMAGE img_idle[3];

IMAGE img_dialoguebox;//338 * 163
IMAGE img_GriLogo;//368 * 460
IMAGE img_CMD;//337 * 307

IMAGE img_bullet[2];//我方子弹

IMAGE img_white;
IMAGE img_rushEnemy[2];//撞击敌人 60 * 60
IMAGE img_SGEnemy[2];//散弹敌人 内鬼, 80 * 65

IMAGE img_explode[2];

IMAGE img_followBullet[2];//50 * 50
IMAGE img_enemyBullet[2];//35 * 60

IMAGE img_heliEnemy[2];//55 * 67


void LoadResource() { 
	loadimage(&img_background, _T("./image/background/Background.jpg"));
	loadimage(&img_backbackground, _T("./image/background/backbackground4.png"));

	loadimage(&img_dialoguebox, _T("./image/UI/dialoguebox.png"));
	loadimage(&img_GriLogo, _T("./image/UI/GriLogo.png"));
	loadimage(&img_CMD, _T("./image/UI/cmd1.png"));

	loadimage(&img_gundam[0], _T("./image/player/Gundamxor2.jpg"));
	loadimage(&img_gundam[1], _T("./image/player/Gundam.png"));

	loadimage(&img_rush[0], _T("./image/player/rushxor.jpg"));
	loadimage(&img_rush[1], _T("./image/player/rush2.png"));
	
	loadimage(&img_idle[0], _T("./image/player/Idlexor.jpg"));
	loadimage(&img_idle[1], _T("./image/player/Idle.png"));
	loadimage(&img_idle[2], _T("./image/player/Idledark1.png"));

	loadimage(&img_bullet[0], _T("./image/Item/bulletxor.jpg"));
	loadimage(&img_bullet[1], _T("./image/Item/bullet.jpg"));

	loadimage(&img_white, _T("./image/background/white.jpeg"));

	loadimage(&img_enemyBullet[0], _T("./image/Item/eneBulletxor1.jpg"));
	loadimage(&img_enemyBullet[1], _T("./image/Item/eneBullet1.jpg"));

	loadimage(&img_followBullet[0], _T("./image/Item/followBulletxor.jpg"));
	loadimage(&img_followBullet[1], _T("./image/Item/followBullet.jpg"));

	loadimage(&img_rushEnemy[0], _T("./image/enemy/rushEnemyxor.jpg"));
	loadimage(&img_rushEnemy[1], _T("./image/enemy/rushEnemy.jpg"));

	loadimage(&img_SGEnemy[0], _T("./image/enemy/SGEnemyxor.JPG"));
	loadimage(&img_SGEnemy[1], _T("./image/enemy/SGEnemy.JPG"));

	loadimage(&img_heliEnemy[0], _T("./image/enemy/heliEnemyxor.JPG"));
	loadimage(&img_heliEnemy[1], _T("./image/enemy/heliEnemy.JPG"));

	loadimage(&img_explode[0], _T("./image/Item/expxor.jpg"));
	loadimage(&img_explode[1], _T("./image/Item/exp.jpg"));
	}
//载入图片资源

int lastUpdateBackground, backgroundY = 981;
void PrintBackground(int t) { 
	if (runTime - lastUpdateBackground > t && backgroundY > 0) {
		backgroundY--;
		lastUpdateBackground = runTime;
		}
	putimage(59, 0, 850, 720, &img_background, 0, backgroundY);
	}
//每隔t ms刷新一次背景

int lastSingle = -9999, singleCD = 4;//之前是3, 调试改成1
wchar_t dialogue[100];
int singleX, singleY, pos, lenChar;
bool singleFinish;
void DrawSingle() {
	if (runTime - lastSingle < singleCD || singleFinish)return;
	lastSingle = runTime;
	outtextxy(singleX, singleY, dialogue[pos]);
	if (dialogue[pos] >= 8000) singleX += 17;
	else singleX += 10;
	if (singleX > 1230)singleY += 20, singleX = 925;
	pos++;
	if (pos == lenChar)singleFinish = true;
	}
//输出单字

struct DialogueGroup {
	wchar_t speaker[10];
	wchar_t content[100];
	}dialogues[300];//应该没300句话吧。。
int indexDialogue, numDialogue;




void LoadDialogue(const wchar_t temp_speaker[], const wchar_t temp_dialogue[]) {
	outtextxy(925, 255, temp_speaker);
	singleX = 925, singleY = 295;
	lenChar = wcslen(temp_dialogue);
	REP(i, 0, lenChar - 1) {
		dialogue[i] = temp_dialogue[i];
		}
	pos = 0;
	singleFinish = false;
	}
//载入准备输出下一句对话

bool continueDialogue = 1;
void NextDialogue() {
	if (continueDialogue) {//true的时候可以继续剧情,一句话运行一次
		if (indexDialogue == numDialogue)return;
		putimage(910, 250, &img_dialoguebox);
		LoadDialogue(dialogues[++indexDialogue].speaker, dialogues[indexDialogue].content);
		continueDialogue = false;
		}
	}



struct PlayerG {
	int x, y;
	int anim = 0;
	int rush = 0;
	int speed = 5;
	int opt = -1;//空格操作模式 1对话 0待机 2战斗 -1无法操作
	int hp = 6;
	int lastHitPlayer = -9999, hitPlayerCD = 100;
	int lastCollide = -9999, colliderCD = 50;
	int animHit;//受击动画
	}player;

struct Bullet {
	int x, y;
	bool alive;
	int speedY, speedX;
	}bullet[40];

int enemyWidth[5] = { 60, 80, 55 };
int enemyHeight[5] = { 60, 65, 67 };
int enemyHp[5] = { 5, 12, 8 };
int enemySkillCD[5] = { 100, 100 , 100};
int numEnemy;
struct Enemy {
	int x, y;
	int type;//0冲撞 1刷新盾的SG(被撞击受大量伤害)
	int hp;
	bool alive;
	int width, height;
	int animHit;
	int speedX, speedY;
	bool skill;
	int lastSkillTime = -9999;
	int skillCD;
	int shootCD;
	int stopY;
	}enemy[40];

struct EnemyBullet {
	int type;//2普通 1追踪
	int x, y;
	int hitX, hitY;//碰撞点
	bool alive;
	int speedX, speedY;
	}eBullet[210];

int lastRushAnim, animRush = 0;
void DrawPlayer(){
	
	if (!player.animHit) {
		putimage(player.x + 59, player.y, 70, 85, &img_gundam[0], (player.anim + 2) * 70, 0, NOTSRCERASE);//绘制高达本体
		putimage(player.x + 59, player.y, 70, 85, &img_gundam[1], (player.anim + 2) * 70, 0, SRCINVERT);
		}
	else {
		player.animHit = (player.animHit + 1) % 160;
		int deltaX = 7 * pow(-1, player.animHit);
		putimage(player.x + 59 + deltaX, player.y, 70, 85, &img_gundam[0], (player.anim + 2) * 70, 0, NOTSRCERASE);
		putimage(player.x + 59 + deltaX, player.y, 70, 85, &img_white, (player.anim + 2) * 70, 0, SRCINVERT);
		}
	int t;//喷射闪烁时间
	if (player.rush == -1)t = 10;//惩罚闪烁变慢
	else t = 5;

	if (runTime - lastRushAnim > t) { 
		animRush = (animRush + 70) % 140;
		lastRushAnim = runTime;
		}
	if (player.rush == 1) {//冲刺
		putimage(player.x + 59, player.y, 70, 85, &img_rush[0], animRush, 0, NOTSRCERASE);//绘制火焰动画
		putimage(player.x + 59, player.y, 70, 85, &img_rush[1], animRush, 0, SRCINVERT);
		}
	else if(player.rush == 0){//正常
		putimage(player.x + 1 + 59, player.y - 6, 70, 85, &img_idle[0], animRush, 0, NOTSRCERASE);//绘制火焰动画
		putimage(player.x + 1 + 59, player.y - 6, 70, 85, &img_idle[1], animRush, 0, SRCINVERT);
		}
	else {//惩罚
		putimage(player.x + 1 + 59, player.y - 6, 70, 85, &img_idle[0], animRush, 0, NOTSRCERASE);
		putimage(player.x + 1 + 59, player.y - 6, 70, 85, &img_idle[2], animRush, 0, SRCINVERT);
		}
	}
//绘制高达 t为火焰喷射循环时间

void DrawBullet() { 
	REP(i, 0, 39) {
		if (bullet[i].alive) { 
			putimage(bullet[i].x + 59, bullet[i].y, &img_bullet[0], NOTSRCERASE);
			putimage(bullet[i].x + 59, bullet[i].y, &img_bullet[1], SRCINVERT);
			}
		}
	}

void DrawEnemy() {
	REP(i, 0, 39) {
		if (!enemy[i].alive)continue;
		if (enemy[i].type == 0) {
			if (enemy[i].animHit) {
				enemy[i].animHit = (enemy[i].animHit + 1) % 40;
				putimage(enemy[i].x + 59, enemy[i].y, &img_rushEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, 60, 60, &img_white, 0, 0, SRCINVERT);
				}
			else {
				putimage(enemy[i].x + 59, enemy[i].y, &img_rushEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, &img_rushEnemy[1], SRCINVERT);
				}
			}
		else if (enemy[i].type == 1) {
			if (enemy[i].animHit) {
				enemy[i].animHit = (enemy[i].animHit + 1) % 40;
				putimage(enemy[i].x + 59, enemy[i].y, &img_SGEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, 80, 65, &img_white, 0, 0, SRCINVERT);
				}
			else {
				putimage(enemy[i].x + 59, enemy[i].y, &img_SGEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, &img_SGEnemy[1], SRCINVERT);
				}
			}
		else if (enemy[i].type == 2) {
			if (enemy[i].animHit) {
				enemy[i].animHit = (enemy[i].animHit + 1) % 40;
				putimage(enemy[i].x + 59, enemy[i].y, &img_heliEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, 55, 67, &img_white, 0, 0, SRCINVERT);
				}
			else {
				putimage(enemy[i].x + 59, enemy[i].y, &img_heliEnemy[0], NOTSRCERASE);
				putimage(enemy[i].x + 59, enemy[i].y, &img_heliEnemy[1], SRCINVERT);
				}
			}
		}
	}

void DrawEnemyBullet() {
	REP(i, 0, 209) {
		if (eBullet[i].alive) {
			if (eBullet[i].type == 2) {
				putimage(eBullet[i].x + 59, eBullet[i].y, &img_enemyBullet[0], NOTSRCERASE);
				putimage(eBullet[i].x + 59, eBullet[i].y, &img_enemyBullet[1], SRCERASE);
				}
			else {
				putimage(eBullet[i].x + 59, eBullet[i].y, &img_followBullet[0], NOTSRCERASE);
				putimage(eBullet[i].x + 59, eBullet[i].y, &img_followBullet[1], SRCERASE);
				}
			}
		}
	}

struct Exp {
	int x, y;//爆炸中心
	int indexAnim;//播放帧数共六帧
	}explode[40];

void DrawExplode() {
	REP(i, 0, 39) {
		if (explode[i].indexAnim) {
			int expX = explode[i].x - 50, expY = explode[i].y - 50;
			int anim = (explode[i].indexAnim + 2) / 3;//放慢三倍播放
			expX = max(50, expX);
			expX = min(800, expX);//处理边界
			putimage(expX + 59, expY, 100, 100, &img_explode[0], (anim - 1) * 100, 0, NOTSRCERASE);
			putimage(expX + 59, expY, 100, 100, &img_explode[1], (anim - 1) * 100, 0, SRCINVERT);
			explode[i].indexAnim = (explode[i].indexAnim + 1) % 190;
			}
		}
	}

void CreatExplode(int x, int y) {
	REP(i, 0, 39) {
		if (!explode[i].indexAnim) {
			explode[i].indexAnim = 1;
			explode[i].x = x, explode[i].y = y;
			break;
			}
		}
	}

void GundamPositionJudge() { 
	if (player.x < 0)player.x = 0;
	if (player.y < 0)player.y = 0;
	if (player.x + 70 > 850)player.x = 850 - 70;
	if (player.y + 85 > 720)player.y = 720 - 85;
	}


int rushCD = 999999999, rushLastTime = 500, rushPunishTime = 250;
int lastRushTime = -9999, lastRushPunishTime = -9999;
int punishReady, punishing;
void StartRush() {
	if (runTime - lastRushTime < rushCD) {
		//printf("CD----%d%%\n", (runTime - lastRushTime) * 100 / rushCD);
		return;//还在CD
		}
	lastRushTime = runTime;//开冲!
	player.speed = 7;
	player.rush = 1;
	punishReady = 1;
	}

bool Collider(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {//对敌机j的碰撞检测
	return max(x1, x3) <= min(x2, x4) && max(y1, y3) <= min(y2, y4);
	}
//矩形碰撞检测

void ChangeEnemyHp(int i, int x) {
	enemy[i].hp -= x;
	enemy[i].animHit = 1;
	if (enemy[i].hp <= 0) {
		mciSendString(_T("play exp from 0"), NULL, 0, NULL);
		enemy[i].alive = false, numEnemy--;
		if (enemy[i].type == 1)player.hp = 6;//回满hp
		CreatExplode(enemy[i].x + enemy[i].width / 2, enemy[i].y + enemy[i].height / 2);
		}
	}
//编号为i的敌机减少x点生命值

void CreatEBullet(int type, int x, int y, int speedX, int speedY) {
	REP(i, 0, 209) {
		if (!eBullet[i].alive) {
			eBullet[i].alive = true;
			eBullet[i].x = x, eBullet[i].y = y;//在判断类别函数中再调整
			eBullet[i].speedX = speedX, eBullet[i].speedY = speedY;
			eBullet[i].type = type;
			if (eBullet[i].type == 1) {
				eBullet[i].x += 13;
				eBullet[i].y += 15;
				eBullet[i].hitX = eBullet[i].x + 25;
				eBullet[i].hitY = eBullet[i].y + 25;
				}
			else if(eBullet[i].type == 2){
				eBullet[i].x += 13;
				eBullet[i].y += 17;
				eBullet[i].hitX = eBullet[i].x + 18;
				eBullet[i].hitY = eBullet[i].y + 18;
				}
			break;
			}
		}
	}
//生成敌人子弹

bool isChecking;
void Check() {
	GundamPositionJudge();//检查位置合法性
	if (runTime - lastRushTime > rushLastTime && punishReady) { //检查结束冲刺状态
		player.speed = 3;
		player.rush = -1;
		lastRushPunishTime = runTime;
		punishing = 1;
		punishReady = 0;
		}

	if (runTime - lastRushPunishTime > rushPunishTime && punishing) {//检查结束惩罚
		punishing = 0;
		player.speed = 5;
		player.rush = 0;
		}
	REP(i, 0, 39) { //子弹相关
		if (bullet[i].alive) { 
			bullet[i].x += bullet[i].speedX;
			bullet[i].y += bullet[i].speedY;
			if (bullet[i].y < -30 || bullet[i].x < -4 || bullet[i].x > 831) { bullet[i].alive = false; continue; }
			REP(j, 0, 39) {
				if (!enemy[j].alive)continue;
				int hitX = bullet[i].x + 11, hitY = bullet[i].y + 8;
				if (Collider(hitX, hitY, hitX, hitY, enemy[j].x, enemy[j].y, enemy[j].x + enemy[j].width, enemy[j].y + enemy[j].height)) {
					//这里拿hit点代替了hit矩形
					ChangeEnemyHp(j, 1);
					bullet[i].alive = false;
					}
				if (!bullet[i].alive)break;
				}
			if (!bullet[i].alive)continue;//判断下是否消耗完了

			REP(j, 0, 209) {
				if (!eBullet[j].alive) continue;
				int hitX = bullet[i].x + 11, hitY = bullet[i].y + 8;
				if ((hitX - eBullet[j].hitX) * (hitX - eBullet[j].hitX) + (hitY - eBullet[j].hitY) * (hitY - eBullet[j].hitY) <= 400) {
					bullet[i].alive = false;
					eBullet[j].alive = false;
					break;
					}
				}
			}
		}
	
	REP(i, 0, 39) {//敌机相关
		if (enemy[i].alive) {
			enemy[i].x += enemy[i].speedX;//更新位置
			enemy[i].y += enemy[i].speedY;
			if (enemy[i].y > enemy[i].stopY)enemy[i].y = enemy[i].stopY;
			if (runTime > player.lastCollide + player.colliderCD) {
				if (Collider(player.x + 25, player.y + 20, player.x + 45, player.y + 70, enemy[i].x, enemy[i].y, enemy[i].x + enemy[i].width, enemy[i].y + enemy[i].height)) {
					player.lastCollide = runTime;
					player.hp --;
					if(player.rush)ChangeEnemyHp(i, 2);
					else ChangeEnemyHp(i, 1);
					if (enemy[i].type == 1) {//内鬼机型
						if (player.rush)ChangeEnemyHp(i, 4);//2+4=6
						else ChangeEnemyHp(i, 2);//1+2=3
						}
					player.animHit = 1;
					}
				}

			//出边界死亡
			if (enemy[i].y > 720) { enemy[i].alive = false; numEnemy--; }
			if (enemy[i].x <= 0)enemy[i].speedX *= -1;
			if (enemy[i].x + enemy[i].width >= 850)enemy[i].speedX *= -1;
			//先这么写左右转向吧

			if (enemy[i].skill && runTime > enemy[i].lastSkillTime + enemy[i].skillCD) {
				enemy[i].lastSkillTime = runTime;//发动技能
				if (enemy[i].type == 1) {//跟踪导弹
					int deltaX = (player.x + 35) - enemy[i].x, speedX, speedY;
					int deltaY = (player.y + 35) - enemy[i].y;
					int delta2 = sqrt(deltaX * deltaX + deltaY * deltaY);
					if (delta2 != 0) {//防RE
						speedX = 3 * deltaX / delta2;
						speedY = 3 * deltaY / delta2;
						}
					else speedX = 0, speedY = 3;
					CreatEBullet(enemy[i].type, enemy[i].x, enemy[i].y, speedX, speedY);
					}
				else if(enemy[i].type == 2)enemy[i].shootCD = 1;//散弹
				else {//冲刺机型
					CreatEBullet(2, enemy[i].x + 4, enemy[i].y + 5, 0, 6);
					}
				}
			if (enemy[i].type == 2 && enemy[i].shootCD) {//散弹
				if (enemy[i].shootCD % 5 == 0) {
					int speedX = (rand() % 4) , speedY = 3;
					static int shootDir = 17;
					shootDir *= -1;
					if (shootDir < 0)speedX *= -1;
					CreatEBullet(enemy[i].type, enemy[i].x + shootDir, enemy[i].y, speedX, speedY);
					}
				enemy[i].shootCD++;	
				if (enemy[i].shootCD == 30)enemy[i].shootCD = 0;
				}
			}
		}

	REP(i, 0, 209) {//敌方子弹相关
		if (!eBullet[i].alive)continue;
		if (eBullet[i].type == 1) {
			if (((eBullet[i].hitX - (player.x + 35)) * (eBullet[i].hitX - (player.x + 35)) + (eBullet[i].hitY - (player.y + 35)) * (eBullet[i].hitY - (player.y + 35))) <= 40000) {
				int deltaX = (player.x + 35) - eBullet[i].hitX;
				int deltaY = (player.y + 35) - eBullet[i].hitY;
				int delta2 = sqrt(deltaX * deltaX + deltaY * deltaY);
				if (delta2 != 0) {//防RE
					eBullet[i].speedX = 3 * deltaX / delta2;
					eBullet[i].speedY = 3 * deltaY / delta2;
					}
				}
			}
		eBullet[i].x += eBullet[i].speedX, eBullet[i].y += eBullet[i].speedY;
		if (eBullet[i].type == 1)//更新撞击点
			eBullet[i].hitX = eBullet[i].x + 25, eBullet[i].hitY = eBullet[i].y + 25;
		else if (eBullet[i].type == 2)
			eBullet[i].hitX = eBullet[i].x + 18, eBullet[i].hitY = eBullet[i].y + 18;

		if (runTime > player.lastHitPlayer + player.hitPlayerCD) {
			if (Collider(player.x + 15, player.y + 20, player.x + 60, player.y + 70, eBullet[i].hitX, eBullet[i].hitY, eBullet[i].hitX, eBullet[i].hitY)) {
				player.lastHitPlayer = runTime;
				player.hp--;
				eBullet[i].alive = false;
				player.animHit = 1;
				}
			}

		if (eBullet[i].y > 720 || eBullet[i].y < -10)eBullet[i].alive = false;
		if (eBullet[i].type == 1) {//判断一下左右边界
			if(eBullet[i].hitX < 5 || eBullet[i].x > 815)eBullet[i].alive = false;
			}
		else if (eBullet[i].type == 2) {
			if(eBullet[i].hitX < 10 || eBullet[i].hitX > 851)eBullet[i].alive = false;
			}
		}

	}
//检查位置合法、检查状态更新等

void CreatBullet(int x, int y, bool isplayer, int speedX) {
	static int lastCreatBulletTime = -999, creatBulletCD = 5;//太快重复bug
	REP(i, 0, 39) { 
		if (!bullet[i].alive && runTime - lastCreatBulletTime > creatBulletCD) {
			lastCreatBulletTime = runTime;
			bullet[i].x = x + 21, bullet[i].y = y;
			bullet[i].speedX = speedX;
			if(isplayer)
				bullet[i].speedY = -7;
			bullet[i].alive = true;
			break;
			}
		}
	}
//生成子弹(isplayer没用了hh)


int CreatEnemy(int type, int x, int y, int speedX, int speedY, bool skill, int stopY) {
	if (x < 0 || x + enemyWidth[type] > 850)return -1;
	REP(i, 0, 39) {
		if (enemy[i].alive)continue;
		numEnemy++;
		enemy[i].alive = 1;
		enemy[i].type = type;
		enemy[i].width = enemyWidth[type];
		enemy[i].height = enemyHeight[type];
		enemy[i].x = x, enemy[i].y = y;
		enemy[i].hp = enemyHp[type];
		enemy[i].animHit = 0;
		enemy[i].speedX = speedX, enemy[i].speedY = speedY;
		enemy[i].skill = skill;
		enemy[i].skillCD = enemySkillCD[type];
		enemy[i].lastSkillTime = -9999;
		enemy[i].animHit = 0;
		enemy[i].stopY = stopY;
		return i;
		}
	}

int animValue, bulletDegree, degreeValue;
void MoveGundam(int speed) { 
	if (player.opt == -1)return;
	bool flag1 = false, flag2 = 1;
	static int cntBack = 0;
	if (GetAsyncKeyState('W'))player.y -= speed;
	if (GetAsyncKeyState('S'))player.y += speed;
	if (GetAsyncKeyState('A')) {
		player.x -= speed;
		animValue--;
		flag1 ^= 1;
		}
	if (GetAsyncKeyState('J')) {
		degreeValue--;
		flag2 ^= 1;
		}
	if (GetAsyncKeyState('D')) {
		player.x += speed;
		animValue++;
		flag1 ^= 1;
		}
	if (GetAsyncKeyState('K')) {
		degreeValue++;
		flag2 ^= 1;
		}
	if (GetAsyncKeyState('Q')) {
		StartRush();
		}
	if (GetAsyncKeyState(VK_SPACE)) {
		if (player.opt == 1 && singleFinish) {
			continueDialogue = true;
			}
		else if (player.opt == 2) {//战斗模式 
			CreatBullet(player.x, player.y, true, bulletDegree);
			}
		}
	if (!flag1) {//AD没按或者全按,复位
		if (animValue > 0)animValue--;
		else if (animValue < 0)animValue++;
		}
	if (animValue <= -5)animValue = -5, player.anim = -2;
	else if (animValue < 0)player.anim = -1;
	else if (animValue == 0)player.anim = 0;
	else if (animValue >= 5)animValue = 5, player.anim = 2;
	else player.anim = 1;

	if (degreeValue == -3)bulletDegree--, degreeValue = 0;
	if (degreeValue ==  3)bulletDegree++, degreeValue = 0;

	cntBack += flag2;
	if (cntBack == 3) {
		if (bulletDegree < 0)bulletDegree++;
		else if (bulletDegree > 0)bulletDegree--;
		cntBack = 0;
		}

	if (bulletDegree < -5)bulletDegree = -5;
	if (bulletDegree >  5)bulletDegree = 5;

	}
//高达移动函数


int tongxun = 1, caozuo = 1, zhandou = 1;
//UI界面的一些参数



int stage = -7;
void ContinueStage() {
	//printf("stage=%d\n", stage);
	switch (stage) {
		case -7:
			//stage += 6;//进入调试模式
			stage += 7;//进入游戏
			break;
		case -1://调试模式
			if (1) {
				player.opt = 2;
				isChecking = true;
				rushCD = 2000;
				stage = 150;
				indexDialogue = 30;
				}
			break;
		case 0:
			player.opt = 1;
			player.x = 400, player.y = 720;//卡住
			if (1) {
				static int bgm0 = 1;
				if (bgm0) {
					puts("ok");
					mciSendString(_T("play bgm1"), NULL, 0, NULL);
					bgm0 = 0;
					}
				}
			if (indexDialogue == 2) {
				player.opt = 0;
				stage += 5;
				}
			break;
		case 5:
			if (player.y > 720 - 85)player.y--;
			else if (player.y == 720 - 85) {
				player.opt = 1;
				isChecking = true;
				stage+= 5;
				}
			break;
		case 10:
			if (indexDialogue < 4)return;//到第三句前不触发
			if (indexDialogue == 4) { 
				player.opt = 0;//对话禁止
				bulletDegree = 0;
				rushCD = 2000;//CD 999999 -> 2000 就是开启这个功能
				if (player.rush) {
					player.opt = 1;
					continueDialogue = true;
					stage+= 10;
					}
				}
			break;
		case 20:
			if (indexDialogue < 11)return;
			if (indexDialogue == 11) {
				player.opt = 2;//战斗模式
				static int stageTime0 = runTime;
				REP(i, 0, 39) {
					if (bullet[i].alive && runTime - stageTime0 > 250) {//发射了子弹,玩够250
						//player.opt = 1;
						continueDialogue = true;
						stage+= 10;
						break;
						}
					}
				}
			break;
		case 30:
			static int stageTime1 = runTime;//玩一玩子弹变相
			if (runTime - stageTime1 > 250) {
				player.opt = 1;
				continueDialogue = true;
				stage+= 5;
				}
			break;
		case 35://闪避系统演示
			if (indexDialogue < 14)return;
			if (indexDialogue == 14) {
				player.opt = -1;
				animValue = 0;
				player.anim = 0;
				static bool flagCreat1 = false;
				if (!flagCreat1) {
					CreatEnemy(0, player.x + 3, -20, 0, 1, false, 999);//造一个出来装一下闪避系统
					enemy[0].hp = 9999999;
					flagCreat1 = true;
					}
				if (numEnemy == 0) {
					continueDialogue = true;
					player.opt = 1;//对话模式
					stage += 1;
					}
				}
			break;
		case 36:
			if (indexDialogue == 16) {//生成敌机
				static int flag36 = 1;
				if (flag36)CreatEnemy(1, 400, -80, 0, 1, false, 999), flag36 = 0;
				
				stage++;
				}
			break;
		case 37:
			if (enemy[0].y > 180)enemy[0].y = 180;
			if (indexDialogue == 17) {
				player.opt = 0;//无法射击
				if (enemy[0].y > 180)enemy[0].y = 180;
				if (numEnemy == 0) {
					continueDialogue = true;
					player.opt = 1;//对话
					stage += 3;
					}
				}
			break;
		case 40:
			if (indexDialogue == 21) {
				static int bgm40 = 1;
				if (bgm40) {
					mciSendString(_T("stop bgm1"), NULL, 0, NULL);
					mciSendString(_T("close bgm1"), NULL, 0, NULL);
					mciSendString(_T("play bgm2"), NULL, 0, NULL);
					bgm40 = 0;
					}
				player.opt = 2;
				REP(i, 0, 4) {
					CreatEnemy(0, i * 85, -60, 0, 4, false, 999);//左5冲刺
					}
				stage+= 10;
				}
			break;
		case 50:
			if (numEnemy == 0)stage+=10;
			break;
		case 60:
			if (1) {
				static int flag60 = 1;
				if (flag60) {
					REP(i, 5, 9)
						CreatEnemy(0, i * 85, -60, 0, 4, false, 999);//右5冲刺
					flag60 = 0;
					}
				if (numEnemy == 0)stage += 10;
				}
			break;
		case 70:
			if (1) {
				static int flag70 = 1, flag701 = 1, runTime70 = runTime;
				if (flag70) {
					REP(i, 0, 4)
						CreatEnemy(0, i * 85, -60, 0, 4, false, 999);//冲刺
					flag70 = 0;
					}
				if (flag701 && runTime > runTime70 + 15) {
					runTime70 = runTime;
					REP(i, 2, 3)
						CreatEnemy(0, i * 85 - 40, -60, 0, 2, true, 100);
					flag701 = 0;
					}
				if (runTime70 + 200 < runTime)stage += 10;
				}
			break;
		case 80:
			if (1) {
				static int flag80 = 1, flag801 = 1, runTime80 = runTime;
				if (flag80) {
					REP(i, 5, 9)
						CreatEnemy(0, i * 85, -60, 0, 4, false, 999);//冲刺
					flag80 = 0;
					}
				if (flag801 && runTime > runTime80 + 15) {
					runTime80 = runTime;
						REP(i, 6, 7)
						CreatEnemy(0, i * 85 + 40, -60, 0, 2, true, 100);
					flag801 = 0;
					}
				if (runTime80 + 250 < runTime)stage += 5, continueDialogue = true;
				}
			break;
		case 85:
			if (1) {
				static int runTime85 = runTime;
				if (runTime > runTime85 + 250)
					stage += 5;
				}
			break;
		case 90:
			if (1) {
				static int num90 = 12, runTime90 = runTime;
				if (num90 && runTime > runTime90 + 50) {//三重击
					num90--;
					runTime90 = runTime;
					CreatEnemy(0, player.x + 3, -60, 0, 5, false, 999);
					CreatEnemy(0, player.x + 63 + 90, -60, 0, 5, false, 999);
					CreatEnemy(0, player.x - 57 - 90, -60, 0, 5, false, 999);
					}
				if (!num90 && numEnemy == 0)stage += 5, continueDialogue = true;
				}
			break;
		case 95:
			if (1) {
				static int runTime95 = runTime;
				if (runTime > runTime95 + 250)
					stage += 5;
				}
			break;
		case 100:
			if (1) {
				static int flag100 = 1, runTime100 = runTime;
				if (flag100) {
					int index = CreatEnemy(1, 405, -60, 0, 2, true, 150);
					enemy[index].lastSkillTime = runTime - 120;
					index = CreatEnemy(1, 405 + 300, -60, 0, 2, true, 100);
					enemy[index].lastSkillTime = runTime - 120;
					index = CreatEnemy(1, 405 - 300, -60, 0, 2, true, 100);
					enemy[index].lastSkillTime = runTime - 120;
					flag100 = 0;
					}
				if (numEnemy == 0) {
					continueDialogue = true;
					player.opt = 1;
					stage += 10;
					}  
				}
			break;
		case 110:
			if (indexDialogue == 29) {
				static int flag110 = 1;
				player.opt = 2;
				if (flag110) {
					CreatEnemy(2, 405, -60, 0, 2, true, 170);
					CreatEnemy(2, 405 + 300, -60, 0, 2, true, 100);
					CreatEnemy(2, 405 - 300, -60, 0, 2, true, 100);
					flag110 = 0;
					}
				if (numEnemy == 0)continueDialogue = true, stage += 10;
				}
			break;
		case 120:
			if (1) {
				static int runTime120 = runTime;
				if (runTime > runTime120 + 250)
					stage += 10;
				}
			break;
		case 130:
			if (1) {
				static int f130 = 1, f131 = 1, f132 = 1;
				static int runTime130 = runTime;
				if (f130) {
					CreatEnemy(0, 395, -60, 0, 4, false, 999);//   /|\   //
					CreatEnemy(0, 395, -60,-1, 4, false, 999);
					CreatEnemy(0, 395, -60, 1, 4, false, 999);

					CreatEnemy(2, 425 - enemyWidth[2] / 2, -100, 0, 1, true, 999);
					CreatEnemy(2, 325 - enemyWidth[2] / 2, -100, 0, 1, true, 999);
					CreatEnemy(2, 525 - enemyWidth[2] / 2, -100, 0, 1, true, 999);
					f130 = 0;
					}
				if (f132 && runTime > runTime130 + 160) {
					runTime130 = runTime;
					CreatEnemy(0, 395, -60, 0, 4, false, 999);//   /|\   //
					CreatEnemy(0, 395, -60, -4, 4, false, 999);
					CreatEnemy(0, 395, -60, 4, 4, false, 999);
					f132 = 0;
					}
				if (f131 && !numEnemy)runTime130 = runTime, f131 = 0;
				if (!f131 && runTime > runTime130 + 150)stage += 10;
				}
			break;
		case 140:
			if (1) {
				static int f140 = 1, f141 = 1, f142 = 1, f143 = 1;
				static int runTime140 = runTime;
				if (f140) {
					CreatEnemy(0, 295, -60, 0, 4, false, 999);
					CreatEnemy(0, 295, -60, -1, 4, false, 999);
					CreatEnemy(0, 295, -60, 1, 4, false, 999);

					CreatEnemy(1, 325 - enemyWidth[1] / 2, -100, 0, 1, true, 999);

					CreatEnemy(0, 495, -60, 0, 4, false, 999);
					CreatEnemy(0, 495, -60, -1, 4, false, 999);
					CreatEnemy(0, 495, -60, 1, 4, false, 999);

					CreatEnemy(1, 525 - enemyWidth[1] / 2, -100, 0, 1, true, 999);

					f140 = 0;
					}
				if (f143 && !numEnemy) {
					runTime140 = runTime;
					f143 = 0;
					}
				if (!f143 && runTime > runTime140 + 150)stage += 10;
				}
			break;
		case 150:
			if (1) {
				static int f150 = 1, n151 = 12, f152 = 1, runTime150;
				if (f150) {
					CreatEnemy(2, 425 - enemyWidth[2] / 2, -100, 0, 2, true, 120);
					CreatEnemy(1, 325 - enemyWidth[1] / 2, -100, 0, 1, true, 999);
					CreatEnemy(1, 525 - enemyWidth[1] / 2, -100, 0, 1, true, 999);
					f150 = 0;
					}
				if (n151 && runTime150 + 50 < runTime) {
					n151--;
					runTime150 = runTime;
					CreatEnemy(0, player.x + 3, -60, 0, 5, false, 999);
					CreatEnemy(0, player.x + 63 + 90, -60, 0, 5, false, 999);
					CreatEnemy(0, player.x - 57 - 90, -60, 0, 5, false, 999);
					}
				if (f152 && !numEnemy)f152 = 0, runTime150 = runTime;
				if (!f152 && runTime > runTime150 + 150)continueDialogue = true, stage += 5, player.opt = 1;
				}
			break;
		case 155:
			if (indexDialogue == 34) {
				player.opt = 2;
				tongxun = 0;
				static int f155 = 1;
				if (f155) {//给一个内鬼回回血
					CreatEnemy(1, 452 - enemyWidth[1] / 2, -60, 0, 2, true, 120);
					f155 = 0;
					}
				if (!numEnemy)stage += 5;
			}
			break;
		case 160:
			if (1) {
				static int f160 = 1, n161 = 0, runTime160 = runTime;
				if (n161 <= 10 && runTime > runTime160 + 50) {
					runTime160 = runTime;
					CreatEnemy(0, 395, -60, 0, 4, false, 999);
					CreatEnemy(0, 395, -60,-n161, 4, false, 999);
					CreatEnemy(0, 395, -60, n161, 4, false, 999);
					n161++;
					}
				if (n161 > 10 && runTime > runTime160 + 150) {
					player.opt = 1;
					tongxun = -1;
					continueDialogue = true;
					stage += 10;
					}
				}
			break;
		case 170:
			if (indexDialogue == 49) {
				player.opt = 2;
				}
			break;
		}
	}
//剧情演出和推进都在这了


	void WriteDialogue() {
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  视觉模块运作正常,正在加载运动模块。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  格里芬新型原型机“机兵”具有超强的瞬时机动能力,映射到你的系统上按下Q以进入机动模式,可以大幅增加移动速度。需要注意的是,机动模式结束后机兵会局部过载,移动速度受损一段时间。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  运动模块加载完毕,正在上线。") };//3
		dialogues[++numDialogue] = { _T(""), _T("   —— 按下Q键启动机动模式 ——") };//4
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  机动模式运作正常。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  其冷却时间和过载时间可以在右下角的控制台实时监控,") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  请合理利用“机兵”的机动功能。") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  收到。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  正在加载武器模块。") };//9
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  加载成功,机兵由通讯模式切换至战斗模式,指挥官在飞行系统上按下空格发射子弹,J/K调整发射角度。") };//9
		dialogues[++numDialogue] = { _T(""), _T("    —— 按下空格发射子弹 ——") };//11
		dialogues[++numDialogue] = { _T(""), _T("   —— 按下J/K调整发射角度 ——") };//12
		dialogues[++numDialogue] = { _T("指挥官"), _T("  武器系统运作正常。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  敌人的每一次攻击对机兵都是致命的。为此,机兵搭载了16Lab开发的自动闪避系统,在闪避时还可以对敌机造成伤害。机动状态时自动闪避造成的伤害加倍。") };//14
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  指挥官可以在右下角查看自动闪避系统的耐久度。除此之外,击落一些特殊机型的敌机可以回复自动闪避系统的耐久值。") };//15
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  自动闪避系统特异性地对此类机型造成4倍伤害,机动状态时造成6倍巨额伤害,请灵活使用这一特性。") };//16
		dialogues[++numDialogue] = { _T(""), _T("—利用机动(Q)及自动闪避系统击落敌机—") };//17
		dialogues[++numDialogue] = { _T("指挥官"), _T("  嗯,信息和任务情报一致。全部模块正以满功率运行。准备好大干一场了吗小格?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  打完收工早点下班!让军方看看我们的厉害吧。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  第四季度第二十三次演习任务,代号“紧急除颤”,现在开始。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  敌机来袭!") };//21
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  雷达检测到前方大量铁血三重击方阵,请注意规避。") };//22
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  根据监测系统,前方出现配备电子追踪能量弹的敌机,遭遇时请尽快处理。击毁此类机型可以恢复全部闪避耐久。") };//23
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  检测到大型机接近,推测是铁血重型武装直升机。") };//24
		dialogues[++numDialogue] = { _T("指挥官"), _T("  了解。") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  ...刚接到任务的时候我就觉得奇怪,这种规模的演习需要用到重型武装机么?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  我也觉得奇怪...嘛,谁叫你是格里芬的王牌呢!") };
		dialogues[++numDialogue] = { _T(""), _T("         检测到机敌来袭") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  嗯。小格,准备战斗。") };//29
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  检测到大量混编机型接近,请做好战斗准备。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  不愧是指挥官!根据任务列表,第四季度第二十三次演习任务结...") };//31
		dialogues[++numDialogue] = { _T(""), _T("         检测到机敌来袭") };//32
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  ! ?  ") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  小格,准备战斗!") };//34
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  为什么联系不上军方?......通讯被干扰了?") };//35
		dialogues[++numDialogue] = { _T("指挥官"), _T("  能联系格里芬总部么?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  联系不了,常规通讯手段全部被干扰了。不对啊,有谁能在演习场地部署屏蔽设备啊?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  ......军方?") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  ! 你现在在哪?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  我?") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  依据规定,通讯员不能告知这...") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  格琳娜!你现在在哪?!") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  我...我现在在军方基地设的格里芬临时指挥部。") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  把防爆门锁好...再加密,军方不可能搞错演习任务的!敌机太逼真了也有问题...常规通讯被屏蔽了,试试机兵的微波通讯系统,联系格里芬去找你。") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  我...我知道了。军方?......我知道了。启用微波对外通讯...我需要时间。你...") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  我给你争取,只要保证启用之前机兵在线...") };
		dialogues[++numDialogue] = { _T("格琳娜"), _T("  你不要有事!") };
		dialogues[++numDialogue] = { _T("指挥官"), _T("  ......") };
		dialogues[++numDialogue] = { _T(""), _T("         检测到机敌来袭") };//49



		indexDialogue = 0;
		}
	//写入剧情


void InitGraph() {
	initgraph(1280, 720, EW_SHOWCONSOLE);
	LoadResource();
	putimage(0, 0, &img_backbackground);
	WriteDialogue();//加载对话
	player.x = 400, player.y = 720;
	mciSendString(_T("open ./bgm/bgm1.mp3 alias bgm1") , NULL, 0, NULL);
	mciSendString(_T("open ./bgm/bgm2.mp3 alias bgm2"), NULL, 0, NULL); 
	mciSendString(_T("open ./bgm/exp.wav alias exp"), NULL, 0, NULL);
	}
//图形界面(第二章以后)的初始化

void ChangeHpAnim(int realHp) {
	static int thistime = 1;
	thistime ^= 1;
	static int nowShow = 100;
	if (thistime) {
		if (realHp > nowShow)nowShow++;
		else if (realHp < nowShow)nowShow--;
		}
	TCHAR s[10];
	_stprintf_s(s, _T("%d%%"), nowShow);
	outtextxy(1070, 592, s);
	}

void PrintConsoleText() {
	outtextxy(920, 452, _T("通讯记录云同步信号:"));//第一行
	if (tongxun == 1) setcolor(GREEN),outtextxy(1080, 452, _T("良好")); 
	else if (tongxun == 0) setcolor(YELLOW), outtextxy(1080, 452, _T("一般"));
	else setcolor(RED), outtextxy(1080, 452, _T("极差"));
	setcolor(WHITE);

	if(player.opt == 0 || player.opt == -1)outtextxy(1165, 452, _T("<待机模式>"));
	else if (player.opt == 1)outtextxy(1165, 452, _T("<通讯模式>"));
	else if (player.opt == 2)outtextxy(1165, 452, _T("<战斗模式>"));


	outtextxy(920, 472, _T("  >操作模块:"));//第二行
	if (caozuo == 1)setcolor(GREEN), outtextxy(1020, 472, _T("ONLINE"));
	else setcolor(RED), outtextxy(1020, 472, _T("OFFLINE"));
	setcolor(WHITE);

	outtextxy(920, 492, _T("  >视觉模块:"));//第三行不变了
	setcolor(GREEN), outtextxy(1020, 492, _T("ONLINE"));setcolor(WHITE);

	if (indexDialogue >= 1) {//运动模块
		if (indexDialogue < 3) {
			outtextxy(920, 512, _T("  >运动模块:"));//第四行
			setcolor(RGB(255, 215, 0));
			outtextxy(1020, 512, _T("LOADING"));
			static int lastPointTime = -999, numPoint = -1;
			if (runTime - lastPointTime > 30) {
				lastPointTime = runTime;
				numPoint = (numPoint + 1) % 4;
				}
			if (numPoint == 0)outtextxy(1080, 512, _T(""));
			else if (numPoint == 1)outtextxy(1080, 512, _T("."));
			else if (numPoint == 2)outtextxy(1080, 512, _T(".."));
			else if (numPoint == 3)outtextxy(1080, 512, _T("..."));
			setcolor(WHITE);
			}
		else {
			outtextxy(920, 512, _T("  >运动模块:"));//第四行
			if (rushCD == 2000)setcolor(GREEN), outtextxy(1020, 512, _T("ONLINE"));
			else setcolor(RED), outtextxy(1020, 512, _T("OFFLINE"));
			setcolor(WHITE);
			outtextxy(920, 548, _T("     I"));
			outtextxy(943, 532, _T("---- 机动模式:"));
			outtextxy(920, 542, _T("     I"));
			outtextxy(920, 532, _T("     I"));
			outtextxy(943, 552, _T("---- 局部过载:"));

			if (rushCD != 2000) outtextxy(1040, 532, _T("N/A")), outtextxy(1040, 552, _T("N/A"));
			else {
				TCHAR s[10];
				int x = (runTime - lastRushTime) * 100 / rushCD;
				_stprintf_s(s, _T("%d%%"), x);
				if (x >= 100)setcolor(RGB(0, 191, 255)), outtextxy(1040, 532, _T("READY")), setcolor(WHITE);
				else if (x >= 25)outtextxy(1040, 532, s);
				else setcolor(RGB(0, 191, 255)), outtextxy(1040, 532, s), setcolor(WHITE);

				x = (runTime - lastRushPunishTime) * 100 / rushPunishTime;
				_stprintf_s(s, _T("%d%%"), x);
				if (x >= 100)outtextxy(1040, 552, _T("N/A"));
				else setcolor(RGB(255, 215, 0)), outtextxy(1040, 552, s), setcolor(WHITE);
				}
			}
		}
	
	if (indexDialogue >= 9) { 
		outtextxy(920, 572, _T("  >战斗模块:"));
		if (indexDialogue == 9) {
			setcolor(RGB(255, 215, 0));
			outtextxy(1020, 572, _T("LOADING"));
			static int lastPointTime1 = -999, numPoint = -1;
			if (runTime - lastPointTime1 > 30) {
				lastPointTime1 = runTime;
				numPoint = (numPoint + 1) % 4;
				}
			if (numPoint == 0)outtextxy(1080, 572, _T(""));
			else if (numPoint == 1)outtextxy(1080, 572, _T("."));
			else if (numPoint == 2)outtextxy(1080, 572, _T(".."));
			else if (numPoint == 3)outtextxy(1080, 572, _T("..."));
			setcolor(WHITE);
			}
		else {
			if (zhandou == 1)setcolor(GREEN), outtextxy(1020, 572, _T("ONLINE"));
			else setcolor(RED), outtextxy(1020, 572, _T("OFFLINE"));
			setcolor(WHITE);
			}
		setcolor(WHITE);
		outtextxy(920, 588, _T("     I"));
		outtextxy(943, 592, _T("---- 闪避系统耐久:"));
		int x = player.hp;
		if (x >= 5)setcolor(GREEN);
		else if (x >= 3)setcolor(RGB(255, 215, 0));
		else setcolor(RED);
		ChangeHpAnim(x * 100 / 6);
		setcolor(WHITE);
		}
	}



void DrawUI() {
	putimage(971, -5, 368, 250, &img_GriLogo, 0, 0);
	putimage(910, 432, &img_CMD);
	NextDialogue();//是否载入下一句对话
	DrawSingle();//检测是否有新对话,进行绘制
	PrintConsoleText();
	}
//绘制右侧UI

void GameDraw() {
	PrintBackground(30);
	
	static int slow = 0;
	slow++;
	if (slow == 7) {
		MoveGundam(player.speed);
		if(isChecking)Check();
		DrawUI();
		ContinueStage();
		runTime++;
		slow = 0;
		}
	
	
	DrawEnemy();
	DrawPlayer();
	DrawEnemyBullet();
	DrawBullet();
	DrawExplode();
	}
//总绘制函数

void Chapter2() { 
	InitGraph();
	BeginBatchDraw();//双缓冲绘图
	while (1) { 
		GameDraw();
		FlushBatchDraw();
		
		Sleep(1);
		}
	EndBatchDraw();
	}


int main() { 
	Init();
	_getch();

	Chapter1();
	Chapter2();

	//Handle(FALSE);
	//test1();
	

	getchar();
	return 0;
	}
posted @ 2022-09-02 12:28  Tony_Double_Sky  阅读(42)  评论(0编辑  收藏  举报