task T_Stage7()
{
	//StO(fobOp)
	let f_crazy = 0;

	let norm1 = 120;
	let norm2 = 430;

	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);
	LoadGraphic(img_magic);
	T_SubEnemyProc7();
	SetCommonData("Back7_State", 0);
	SetShotAutoDeleteClip(24, 24, 24, 24);

	SetNormPoint(norm1);

	Wait(10);
	PlayMusic(bgm_stage7);
	Wait(110);

	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() - 32, GetClipMinY() + 24 + i * 24, 4.0, 15, 0);
		Wait(20);
	}
	Wait(60);
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() + 32, GetClipMinY() + 24 + i * 24, 4.0, 175, 0);
		Wait(20);
	}
	Wait(60);
	ascent( let i in 0..4 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() - 32, GetClipMinY() + 150 - i * 40, 4.0, 15, 0);
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() + 32, GetClipMinY() + 150 - i * 40, 4.0, 175, 0);
		Wait(20);
	}
	CreateEnemyFromFile(cd ~ "x7_02.txt", GetCenterX(), GetClipMinY() - 32, 5.0, 90, 0);
	Wait(360);

	T_ShowTitle();
	Wait(240);

	CreateEnemyFromFile(cd ~ "x7_03.txt", GetClipMinX() + 110, GetClipMinY() - 32, 6.0, 90, 0);
	CreateEnemyFromFile(cd ~ "x7_03.txt", GetClipMaxX() - 110, GetClipMinY() - 32, 6.0, 90, 0);
	Wait(300);
	CreateEnemyFromFile(cd ~ "x7_03.txt", GetCenterX() - 30, GetClipMinY() - 32, 5.0, 90, 0);
	CreateEnemyFromFile(cd ~ "x7_03.txt", GetCenterX() - 30, GetClipMinY() - 32, 8.0, 90, 0);
	Wait(420);

	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() - 120, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() - 40, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 40, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 120, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 80, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() + 0, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(40);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetCenterX() - 80, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(120);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMinX() - 32, GetClipMinY() + 60, 4.0, 0, 0);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMaxX() + 32, GetClipMinY() + 60, 4.0, 180, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMinX() - 32, GetClipMinY() + 120, 4.0, 0, 0);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMaxX() + 32, GetClipMinY() + 120, 4.0, 180, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMinX() - 32, GetClipMinY() + 180, 4.0, 0, 0);
	CreateEnemyFromFile(cd ~ "x7_04.txt", GetClipMaxX() + 32, GetClipMinY() + 180, 4.0, 180, 0);
	Wait(240);

	CreateEnemyFromFile(cd ~ "x7_02.txt", GetClipMinX() + 80, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_02.txt", GetClipMaxX() - 80, GetClipMinY() - 32, 5.0, 90, 0);
	Wait(420);

	DeleteEnemyShotToItem(ALL);
	CollectItems();

	//{XJn
	CreateEnemyBossFromFile(cd ~ "z71_e01.txt", GetClipMinX() - 64, GetClipMaxY() + 128, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}
	if( GetPoint() >= norm1 || f_crazy ){
		CreateEnemyBossFromFile(cd ~ "z71_allh.txt", GetCommonDataDefault("boss_x", 0), GetCommonDataDefault("boss_y", 0), 0, 0, 0);
		SetCommonData("crazy01", 1);
	}
	else{
		CreateEnemyBossFromFile(cd ~ "z71_all.txt", GetCommonDataDefault("boss_x", 0), GetCommonDataDefault("boss_y", 0), 0, 0, 0);
	}
	while( GetEnemyNum() != 0 ){
		yield;
	}
	SetNormPoint(norm2);

	LoadSE(se_shot1);
	LoadSE(se_shot2);
	SetShotAutoDeleteClip(24, 24, 24, 24);
	Wait(120);

	T_EnemySet01();
	Wait(300);
	ascent( let i in 0..3 ){
		CreateEnemyFromFile(cd ~ "x7_06.txt", GetClipMinX() - 16, GetClipMinY() + 160, 0.0, 0, 0);
		CreateEnemyFromFile(cd ~ "x7_06.txt", GetClipMaxX() + 16, GetClipMinY() + 160, 0.0, 0, 0);
		Wait(120);
	}
	Wait(180);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetCenterX() + 60, GetClipMinY() - 32, 3.5, 90, 0);
	Wait(300);
	CreateEnemyFromFile(cd ~ "x7_08.txt", GetCenterX() - 60, GetClipMinY() - 32, 3.5, 90, 0);
	Wait(360);

	CreateEnemyFromFile(cd ~ "x7_09.txt", GetCenterX(), GetClipMinY() - 32, 3.5, 90, 0);
	CreateEnemyFromFile(cd ~ "x7_10.txt", GetClipMinX() - 32, GetClipMinY() + 120, 4.0, 0, 0);
	CreateEnemyFromFile(cd ~ "x7_10.txt", GetClipMaxX() + 32, GetClipMinY() + 120, 4.0, 180, 0);
	Wait(360);
	CreateEnemyFromFile(cd ~ "x7_09.txt", GetCenterX() + 120, GetClipMinY() - 32, 3.5, 90, 0);
	CreateEnemyFromFile(cd ~ "x7_10.txt", GetClipMinX() - 32, GetClipMinY() + 120, 4.0, 0, 0);
	CreateEnemyFromFile(cd ~ "x7_10.txt", GetClipMinX() - 32, GetClipMinY() + 140, 7.0, 0, 0);
	Wait(480);

	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() - 16, GetClipMinY() + 24 + i * 24, 3.0, 15, 0);
	}
	Wait(60);
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() + 16, GetClipMinY() + 24 + i * 24, 3.0, 175, 0);
	}
	Wait(90);
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() + 16, GetClipMaxY() - 24 - i * 24, 3.0, -125, 0);
	}
	Wait(90);
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() - 24 - i * 24, GetClipMinY() - 32, 3.0, 90, 0);
	}
	Wait(90);
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() - 16, GetCenterY() + 20 - i * 24, 3.0, -25, 0);
	}
	Wait(270);

	ascent( let i in 0..12 ){
		CreateEnemyFromFile(cd ~ "x7_06.txt", GetClipMinX() - 16, GetClipMinY() + 120 - i * 10, 0.0, 0, 0);
		CreateEnemyFromFile(cd ~ "x7_06.txt", GetClipMaxX() + 16, GetClipMinY() + 120 - i * 10, 0.0, 0, 0);
		Wait(20);
	}
	Wait(210);
	ascent( let i in 0..8 ){
		CreateEnemyFromFile(cd ~ "x7_07.txt", GetClipMinX() + 60, GetClipMinY() - 16, 0.0, 0, 0);
		CreateEnemyFromFile(cd ~ "x7_07.txt", GetClipMaxX() - 60, GetClipMinY() - 16, 0.0, 0, 0);
		Wait(10);
	}

	Wait(270);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() - 90, GetClipMinY() - 32, 0.0, 0, [1, 0]);
	Wait(120);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() + 90, GetClipMinY() - 32, 0.0, 0, [-1, 0]);
	Wait(120);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() - 120, GetClipMinY() - 32, 0.0, 0, [1, 0]);
	Wait(60);
	T_EnemySet02(GetClipMinX() + 48, GetClipMinY() - 16, 2.0, 90);
	Wait(60);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() + 120, GetClipMinY() - 32, 0.0, 0, [-1, 0]);
	Wait(120);
	T_EnemySet02(GetClipMaxX() - 48, GetClipMinY() - 16, 2.0, 90);
	Wait(120);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() - 60, GetClipMinY() - 32, 0.0, 0, [1, 0]);
	Wait(150);
	CreateEnemyFromFile(cd ~ "x7_11.txt", GetCenterX() + 60, GetClipMinY() - 32, 0.0, 0, [-1, 1]);
	Wait(390);

	ascent( let j in 0..6 ){
		ascent( let i in 0..5 ){
			CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMinX() - 16, GetClipMinY() + 24 + i * 24, 1.5, 0, 0);
			CreateEnemyFromFile(cd ~ "x7_01.txt", GetClipMaxX() + 16, GetClipMinY() + 24 + i * 24, 1.5, 180, 0);
		}
		Wait(40);
	}
	Wait(360);

	DeleteEnemyShotToItem(ALL);
	CollectItems();

	//{XJn
	CreateEnemyBossFromFile(cd ~ "z72_e01.txt", GetClipMinX() - 32, GetClipMinY() + 100, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}
	if( GetPoint() >= norm2 || f_crazy ){
		CreateEnemyBossFromFile(cd ~ "z72_allh.txt", GetCommonDataDefault("boss_x", 0), GetCommonDataDefault("boss_y", 0), 0, 0, 0);
		SetCommonData("crazy02", 1);
	}
	else{
		CreateEnemyBossFromFile(cd ~ "z72_all.txt", GetCommonDataDefault("boss_x", 0), GetCommonDataDefault("boss_y", 0), 0, 0, 0);
	}
	while( GetEnemyNum() != 0 ){
		yield;
	}
	CreateEnemyBossFromFile(cd ~ "z72_e02.txt", GetCenterX(), -600, 0, 0, 0);
	while( GetEnemyNum() != 0 ){
		yield;
	}

	let bonus = GetPlayerLife() * 25000 + GetPlayerBomb() * 5000 + GetPoint() * 300;

	if( GetCommonDataDefault("crazy01", 0) ){
		bonus *= 1.2;
	}
	if( GetCommonDataDefault("crazy02", 0) ){
		bonus *= 2.0;
	}
	SetCommonData("clearbonus", bonus);
	f_bonus = 1;
	loop(100){
		AddScore(GetCommonDataDefault("clearbonus", 0));
		yield;
	}
	while( GetKeyState(VK_SHOT) != KEY_PUSH ){
		yield;
	}
	f_bonus = 0;
	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();
}

function BackGround7()
{
	let state = GetCommonDataDefault("Back7_State", 0);
	let bg_y = (g_count * 1) % 448;

	SetTexture(img_bg7_a);
	SetAlpha(255);
	SetGraphicRect(0, bg_y, 384, 448 + bg_y);
	SetGraphicAngle(90 + 180, 0, 0);
	DrawGraphic3D(0, 150, 60);

	SetTexture(img_bg7_c);
	SetGraphicAngle(0, 0, 0);
	SetAlpha(192);
	SetGraphicRect(0, 0, 384, 448);
	DrawGraphic(GetCenterX(), GetCenterY());

	let cl_y = (g_count * 2) % 448;

	SetTexture(img_bg7_b);
	SetGraphicAngle(0, 0, 0);
	SetAlpha(255);
	SetGraphicRect(0, 448 - cl_y, 384, 448);
	DrawGraphic(GetCenterX(), GetClipMinY() + cl_y / 2);
	SetGraphicRect(0, 0, 384, 448 - cl_y);
	DrawGraphic(GetCenterX(), GetCenterY() + cl_y / 2);
}

task T_SubEnemyProc7()
{
	loop{
		ascent( let i in 0..100 ){
			let label = ToString(i);
			if( GetCommonDataDefault("sub_state" ~ label, 0) == 1 ){
				SetCommonData("sub_state" ~ label, 2);

				let x = GetCommonData("sub_x" ~ label);
				let y = GetCommonData("sub_y" ~ label);
				let type = GetCommonData("sub_type" ~ label);

				if( type == 0 ){
					CreateEnemyFromFile(cd ~ "x7_08_sub.txt", x, y, 0.0, 0, i);
				}
				else if( type == 1 ){
					CreateEnemyFromFile(cd ~ "x7_09_sub.txt", x, y, 0.0, 0, i);
				}
			}
		}
		yield;
	}
}

task T_EnemySet01()
{
	ascent( let i in 0..20 ){
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMinX() - 32, GetClipMinY() + 20, 0.0, 0, 0);
		Wait(15);
		CreateEnemyFromFile(cd ~ "x7_05.txt", GetClipMaxX() + 32, GetClipMinY() + 20, 0.0, 180, 0);
		Wait(15);
	}
}

task T_EnemySet02(x, y, v, angle)
{
	ascent( let i in 0..6 ){
		CreateEnemyFromFile(cd ~ "x7_12.txt", x, y, v, angle, i * 2);
		Wait(15);
	}
}
