task T_Stage7()
{
	LoadSE(se_shot1);
	LoadSE(se_shot2);
	LoadSE(se_destroy);
	LoadSE(se_destroy2);
	LoadSE(se_countdown);
	LoadGraphic(img_bg7_a);
	LoadGraphic(img_bg7_b);
	LoadGraphic(img_bg7_c);
	T_SubEnemyScript7();
	SetCommonData("Back7_State", 0);

	PlayMusic(bgm_stage7);

	Wait(120);

	loop(8){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() + 32, GetClipMinY() - 32, 5.0, 90, 0);
		Wait(10);
	}
	Wait(60);
	loop(8){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() - 32, GetClipMinY() - 32, 5.0, 90, 0);
		Wait(10);
	}
	Wait(60);
	T_ShowTitle();
	Wait(210);

	CreateEnemyFromFile(cd ~ "x7_02.txt", GetCenterX() - 60, GetClipMinY() - 32, 7.0, 90, -1);
	Wait(180);
	CreateEnemyFromFile(cd ~ "x7_02.txt", GetCenterX() - 120, GetClipMinY() - 32, 7.0, 90, -1);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_02.txt", GetCenterX() + 120, GetClipMinY() - 32, 7.0, 90, 1);
	Wait(240);

	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() - 120, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() +  80, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() -  40, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() - 100, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_02.txt", GetCenterX() +  40, GetClipMinY() - 32, 7.0, 90, 1);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() + 130, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() - 130, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(45);
	CreateEnemyFromFile(cd ~ "x7_15.txt", GetCenterX() +   0, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(240);

	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMinX() + 96, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMaxX() - 96, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() - 96, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() - 128, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 128, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 96, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMinX() + 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(20);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMaxX() - 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(300);
	CreateEnemyFromFile(cd ~ "x7_06.txt", GetCenterX(), GetClipMinY() - 32, 7.0, 90, 0);
	Wait(180);

	loop(8){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() - 32, GetClipMinY() - 32, 5.0, 90, 0);
		Wait(10);
	}
	Wait(60);
	loop(8){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() + 32, GetClipMinY() - 32, 5.0, 90, 0);
		Wait(10);
	}
	Wait(210);

	loop(6){
		CreateEnemyFromFile(cd ~ "x7_05_dummy.txt", GetClipMinX() - 32, GetClipMinY() + 100, 6.0, 0, 0);
		Wait(8);
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMinX() - 32, GetClipMinY() + 100, 6.0, 0, 0);
		Wait(8);
	}
	loop(6){
		CreateEnemyFromFile(cd ~ "x7_05_dummy.txt", GetClipMaxX() + 32, GetClipMinY() + 120, 6.0, 180, 0);
		Wait(8);
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMaxX() + 32, GetClipMinY() + 120, 6.0, 180, 0);
		Wait(8);
	}
	loop(6){
		CreateEnemyFromFile(cd ~ "x7_05_dummy.txt", GetClipMinX() - 32, GetClipMinY() + 130, 6.0, 0, 0);
		Wait(8);
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMinX() - 32, GetClipMinY() + 130, 6.0, 0, 0);
		Wait(8);
	}
	loop(6){
		CreateEnemyFromFile(cd ~ "x7_05_dummy.txt", GetClipMaxX() + 32, GetClipMinY() + 90, 6.0, 180, 0);
		Wait(8);
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMaxX() + 32, GetClipMinY() + 90, 6.0, 180, 0);
		Wait(8);
	}
	Wait(150);
	DeleteEnemyShotToItem(ALL);
	CollectItems();
	Wait(60);

	//{XJn
	CreateEnemyBossFromFile(cd ~ "z7a_a_0.txt", GetClipMinX() + 32, GetClipMinY() - 64, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}
	LoadSE(se_shot1);
	LoadSE(se_shot2);

	Wait(120);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetClipMaxX() - 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(30);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetClipMinX() + 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(180);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetClipMaxX() - 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(30);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetClipMinX() + 64, GetClipMinY() - 32, 7.0, 90, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetCenterX(), GetClipMinY() - 32, 6.0, 90, 0);
	Wait(300);

	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_10.txt", GetCenterX() - 130 + i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(15);
	}
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_10.txt", GetCenterX() + 130 - i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(15);
	}
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_10.txt", GetCenterX() - 130 + i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(15);
	}
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_10.txt", GetCenterX() + 130 - i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(15);
	}
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() - 130 + i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(15);
	}
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() + 130 - i * 260 / 6, GetClipMinY() - 32, 3.0, 90, 0);
		Wait(12);
	}
	Wait(300);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetClipMinX() + 32, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(10);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetClipMaxX() - 32, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(240);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetClipMinX() + 64, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(10);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetClipMaxX() - 64, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(360);
	CreateEnemyFromFile(cd ~ "x7_03.txt", GetCenterX(), GetClipMinY() - 32, 6.0, 90, 0);
	Wait(480);

	CreateEnemyFromFile(cd ~ "x7_07.txt", GetCenterX() - 48, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(300);
	CreateEnemyFromFile(cd ~ "x7_07.txt", GetCenterX() + 64, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(30);
	loop(10){
		CreateEnemyFromFile(cd ~ "x7_12.txt", GetClipMinX() - 32, GetClipMinY() + 100, 6.0, 0, 0);
		Wait(15);
	}
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_07.txt", GetCenterX() + 24, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(30);
	SetCommonData("Back7_State", 2);
	T_BG7_MagicCircle();
	loop(10){
		CreateEnemyFromFile(cd ~ "x7_12.txt", GetClipMaxX() + 32, GetClipMinY() + 100, 6.0, 180, 0);
		Wait(15);
	}
	Wait(150);
	Wait(60);
	ascent( let i in 0..7 ){
		CreateEnemyFromFile(cd ~ "x7_08.txt", GetCenterX() - 32 + i * 64 / 6, GetClipMinY() - 32, 7.0, 90, 0);
		Wait(20);
	}
	Wait(240);
	DeleteEnemyShotToItem(ALL);
	CollectItems();
	Wait(60);

	//{XJn
	CreateEnemyBossFromFile(cd ~ "z7b_a_0.txt", GetCenterX() - 96, GetClipMinY() - 64, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}
	CreateEnemyBossFromFile(cd ~ "z7b_e2.txt", GetCenterX(), -600, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}
	Wait(60);
	DeleteMusic(bgm_boss7);
	DeleteGraphic(img_bg7_a);
	DeleteGraphic(img_bg7_b);
	DeleteGraphic(img_bg7_c);
	DeleteSE(se_shot1);
	DeleteSE(se_shot2);
	DeleteSE(se_destroy);
	DeleteSE(se_destroy2);
	ClearStage();
}

let magic_y = 150;

task T_BG7_MagicCircle()
{
	loop(780){
		magic_y += 0.6;
		yield;
	}
}

function BackGround7()
{
	let state = GetCommonDataDefault("Back7_State", 0);

	if( state == 0 ){
		let bg_y = (g_count * 1) % 448;

		SetFog(350, 400, 196, 196, 196);
		SetTexture(img_bg7_a);
		SetAlpha(255);
		SetGraphicRect(0, bg_y, 384, 448 + bg_y);
		SetGraphicAngle(90 + 180, 0, 0);
		DrawGraphic3D(0, 150, 60);
	}
	else if( state == 1 || state == 2 ){
		let bg_y = (g_count * 1) % 448;

		SetFog(320, 400, 32, 32, 32);
		SetTexture(img_bg7_b);
		SetAlpha(255);
		SetGraphicRect(0, bg_y, 384, 448 + bg_y);
		SetGraphicAngle(90 + 180, 0, 0);
		DrawGraphic3D(0, 150, 60);

		if( state == 2 ){
			SetFog(320, 400, 32, 32, 32);
			SetTexture(img_bg7_c);
			SetAlpha(255);
			SetGraphicRect(0, magic_y, 384, 448 + magic_y);
			SetGraphicAngle(90 + 180, 0, 0);
			DrawGraphic3D(0, 150, 60);
		}
	}
}

task T_SubEnemyScript7()
{
	loop{
		if( GetCommonDataDefault("x7_05_sub", 0) == 1 ){
			SetCommonData("x7_05_sub", 0);
			CreateEnemyFromFile(cd ~ "x7_05_sub.txt", GetCommonData("x7_05_sub_x"), GetCommonData("x7_05_sub_y"), 0, 0, 0);
		}
		if( GetCommonDataDefault("x7_09_sub", 0) == 1 ){
			SetCommonData("x7_09_sub", 0);
			CreateEnemyFromFile(cd ~ "x7_09_sub.txt", GetCommonData("x7_09_sub_x"), GetCommonData("x7_09_sub_y"), 0, 0, 0);
		}
		if( GetCommonDataDefault("x7_11_sub", 0) == 1 ){
			SetCommonData("x7_11_sub", 0);
			CreateEnemyFromFile(cd ~ "x7_11_sub.txt", GetCommonData("x7_11_sub_x"), GetCommonData("x7_11_sub_y"), 0, 0, 0);
		}
		if( GetCommonDataDefault("x7_12_sub", 0) == 1 ){
			SetCommonData("x7_12_sub", 0);
			CreateEnemyFromFile(cd ~ "x7_12_sub.txt", GetCommonData("x7_12_sub_x"), GetCommonData("x7_12_sub_y"), 0, 0, 0);
		}
		yield;
	}
}
