#東方弾幕風[Stage]
#Title[命蓮寺観光（仮）]
#Text[]
#Image[]
#BackGround[]
#ScriptVersion[2]

script_stage_main{
	#include_function ".\lib\setting_stage.txt"
	#include_function ".\lib\lib_se.txt"

	let csd = GetCurrentScriptDirectory;

	let csd = GetCurrentScriptDirectory;
	let Img_bg1 = csd ~ "img/yuka.png";
	
	let BG_KYORI = 0;
	let BG_GAIN = 2;

	@Initialize(){
		LoadGraphic(csd ~ "\img\faily_blue.png");
		LoadGraphic(csd ~ "\img\faily_green.png");
		LoadGraphic(csd ~ "\img\faily_red.png");
		
		LoadGraphic(Img_bg1);

		LoadSE(SE_THUNDER);
		LoadSE(SE_SHA);
		LoadSE(SE_DON19);
		LoadSE(SE_SHOT);
		LoadSE(SE_SHOT2);
		LoadSE(SE_SHOT3);
		LoadSE(SE_BELL);
		LoadSE(SE_LASER);
		LoadSE(SE_LASER2);
		LoadSE(SE_KOBUSI);
		LoadSE(SE_WARP);
		LoadSE(SE_WATER);
		LoadSE(SE_WATER2);
		LoadSE(SE_KITEKI);
		LoadSE(SE_POWER);
		LoadSE(SE_BOMB);
		LoadSE(SE_BOMB2);

		//BGM
		PlayMusic(csd ~ "\bgm\bgm00");

		Tmain;
	}

	@MainLoop(){
		BG_KYORI += BG_GAIN;
		yield;
	}

	@Finalize(){
		DeleteGraphic(GetCurrentScriptDirectory() ~ "\img\faily_blue.png");
		DeleteGraphic(GetCurrentScriptDirectory() ~ "\img\faily_green.png");

		DeleteSE(SE_SHOT);
		DeleteSE(SE_BELL);
	}

	@BackGround {
		SetTexture(Img_bg1);
		SetFog(500, 800, 0, 0, 0);
		SetGraphicAngle(-90, 0, 0);
		SetGraphicRect(0, 0 + BG_KYORI, 550, 800 + BG_KYORI);
		DrawGraphic3D(0, 0, 0);
	}

//-------------------------------------------------------
	task Tmain{
		yield;
		doutyuu1;
//		doutyuu_test;

		WaitForZeroEnemy();
		ClearStage();
	}

	function WaitForZeroEnemy(){
		while( GetEnemyNum() != 0 ){ yield; }
	}
	
	//道中　ぬえまで
	sub doutyuu1
	{
		
		wait(120);
		loop(5)
		{
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMinX-10, GetClipMinY+80 , 0, 0, 0);
			wait(30);
		}
		wait(60);
		loop(5)
		{
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMaxX+10, GetClipMinY+80 , 0, 0, 0);
			wait(30);
		}
		wait(60);
		loop(5)
		{
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMinX-10, GetClipMinY+80 , 0, 0, 0);
			wait(15);
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMaxX+10, GetClipMinY+80 , 0, 0, 0);
		}
		wait(120);
		
		//ぬえ登場
		CreateEnemyFromFile( csd ~ "nue01.txt", GetClipMaxX+60, GetClipMinY+30 , 0, 0, 0);

		WaitForZeroEnemy();
		wait(30);

		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX-60, GetClipMinY-80 , 0, 0, 0);
		wait(120);
		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX+100, GetClipMinY-60 , 0, 0, 0);
		wait(120);
		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX, GetClipMinY-60 , 0, 0, 0);
		wait(60);
		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX-120, GetClipMinY-100 , 0, 0, 0);
		wait(60);
		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX+60, GetClipMinY-100 , 0, 0, 0);
		wait(60);
		CreateEnemyFromFile( csd ~ "Enemy02.txt", GetCenterX-30, GetClipMinY-60 , 0, 0, 0);
		wait(120);
		loop(2)
		{
			loop(6)
			{
				CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMinX-10, GetClipMinY+80 , 0, 0, 1);
				wait(30);
			}
			loop(6)
			{
				CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMaxX+10, GetClipMinY+80 , 0, 0, 1);
				wait(30);
			}
		}
		wait(300);
		DeleteEnemyShot(ALL);
		DeleteAllEnemyWithoutBoss();
		
		BG_GAIN = 1;	//背景速度変更
		
		//一輪さん
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"_itirin.txt",GetCenterX+50,0,0,0,0);
		WaitForZeroEnemy();

		BG_GAIN = 2;	//背景速度変更

		wait(180);

		//ぬえ登場その２
		CreateEnemyFromFile( csd ~ "nue02.txt", GetClipMaxX+60, GetClipMinY+30 , 0, 0, 0);

		wait(1080);
		DeleteEnemyShot(ALL);
		DeleteAllEnemyWithoutBoss();

		BG_GAIN = 1;	//背景速度変更

		//ムラサ
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"_murasa.txt",GetCenterX+50,0,0,0,0);
		WaitForZeroEnemy();

		BG_GAIN = 2;	//背景速度変更

		wait(180);


		ougi_left(10, 80);
		wait(180);
		ougi_right(10, 80);
		wait(240);
		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy01.txt", GetClipMinX+40, GetClipMaxY+120+n*2 , 0, 0, 3);
			wait(30);
			CreateEnemyFromFile( csd ~ "enemy01.txt", GetClipMaxX-40, GetClipMaxY+120+n*2 , 0, 0, 3);
			wait(30);
		}
		ougi_left(5, 40);
		ougi_right(5, 40);

		wait(360);

		//ぬえ登場その３（仮）
		CreateEnemyFromFile( csd ~ "nue03.txt", GetClipMaxX+60, GetClipMinY+30 , 0, 0, 0);
		wait(1320);

		BG_GAIN = 3;	//背景速度変更

		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX+20+rand(30,100), GetClipMinY-60 , 0, 0, 2);
		wait(180);

		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX-20-rand(30,100), GetClipMinY-60 , 0, 0, 2);
		wait(240);

		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy04.txt", GetCenterX-n*30-1, GetClipMinY-50+n*10 , 0, 0, 0);
			wait(30);
		}
		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy04.txt", GetCenterX-n*30-1, GetClipMinY-50+n*10 , 0, 0, 0);
			wait(30);
		}
		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX+20+rand(30,100), GetClipMinY-60 , 0, 0, 2);


		WaitForZeroEnemy();

		BG_GAIN = 2;	//背景速度変更
		wait(100);
		BG_GAIN = 1;	//背景速度変更
		wait(50);

		//ナズ寅
		DeleteEnemyShot(ALL);
		DeleteAllEnemyWithoutBoss();
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"_nazutora.txt",GetCenterX+50,0,0,0,0);
		WaitForZeroEnemy();

		BG_GAIN = 2;	//背景速度変更

		wait(180);


		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy03.txt", GetClipMaxX+20, GetClipMinY+150 , 0, 0, 2);
			wait(32);
		}
		loop(3)
		{
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMinX-10, GetClipMinY+70 , 0, 0, 2);
			wait(30);
		}
		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy03.txt", GetClipMinX-20, GetClipMinY+150 , 0, 0, 2);
			wait(32);
		}
		loop(3)
		{
			CreateEnemyFromFile( csd ~ "Enemy01.txt", GetClipMaxX+10, GetClipMinY+70 , 0, 0, 2);
			wait(30);
		}
		ascent(let n in 0 .. 5)
		{
			CreateEnemyFromFile( csd ~ "enemy03.txt", GetClipMaxX+20, GetClipMinY+150 , 0, 0, 2);
			wait(32);
		}
		wait(360);

		BG_GAIN = 3;	//背景速度変更

		//ミーク妖精
		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX, GetClipMinY-80 , 0, 0, 1);

		wait(840);
		DeleteEnemyShot(ALL);
		DeleteAllEnemyWithoutBoss();

		BG_GAIN = 2;	//背景速度変更

		//一輪さんその２
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"_itirin2.txt",GetCenterX+50,0,0,0,0);
		WaitForZeroEnemy();

		BG_GAIN = 1;	//背景速度変更
		wait(200);
		BG_GAIN = 0.5;	//背景速度変更
		wait(100);
		BG_GAIN = 0;	//背景速度変更


		//白蓮さん
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"_byaku.txt",GetCenterX+50,0,0,0,0);
		
	}
	

	//道中テスト用
	task doutyuu_test
	{
		//ぬえ登場その３（仮）
		CreateEnemyFromFile( csd ~ "nue03.txt", GetClipMaxX+60, GetClipMinY+30 , 0, 0, 0);
		wait(1320);


		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX+20+rand(30,100), GetClipMinY-60 , 0, 0, 2);
		wait(180);

		CreateEnemyFromFile( csd ~ "enemy02.txt", GetCenterX-20-rand(30,100), GetClipMinY-60 , 0, 0, 2);
		wait(240);


	}


	task ougi_left(tmp, y)
	{
		ascent(let n in 0 .. tmp)
		{
			CreateEnemyFromFile( csd ~ "enemy03.txt", GetClipMinX-20, GetClipMinY+y+(n%3+int(n/3))*30 , 0, 0, 3);
			wait (40);
		}
	}
	task ougi_right(tmp, y)
	{
		ascent(let n in 0 .. tmp)
		{
			CreateEnemyFromFile( csd ~ "enemy03.txt", GetClipMaxX+20, GetClipMinY+y+(n%3+int(n/3))*30 , 0, 0, 4);
			wait (40);
		}
	}
}