#TouhouDanmakufu[Stage]
#Title[Toziko Stage]
#Text[Stage Script !!]

Difficulty : Normal
Version : 1.0
#BackGround[Default]
#PlayLevel[Hard]
#Player[FREE]
#ScriptVersion[2]


script_stage_main
{
	//#include_function ".\boss\drawbg.txt";
	let CSD = GetCurrentScriptDirectory;
	let slide = 0;
	let pointnorm = 100;
	let bg2 = CSD ~ "boss\bg\bg6.png";
	let bg = CSD ~ "bg\bg4.png";
	let fogc = 0;
	let depth_buffer_enable = false;

	LoadGraphic(bg);
	PlayMusic(CSD~"area8.wav");

//---------------------------------------------------------------
// Any Task

//----- Wait for a period
	function Wait(n)
	{
		loop(n) {	yield;	}
	}

//----- Wait until all enemy kill
	function WaitForZeroEnemy()
	{
		while(GetEnemyNum() != 0) {	yield;	}
	}





	task StageTask
	{

	ExpertEx(true,2,4);
	Wait(90);
	loop(5){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 100, GetClipMinY, 0, 0, 0);
	Wait(15);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 200, GetClipMinY, 0, 0, 1);
	Wait(15);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 300, GetClipMinY, 0, 0, 2);
	Wait(15);
	}
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 100, GetClipMinY, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 350, GetClipMinY, 0, 0, 1);
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 150, GetClipMinY, 0, 0, 2);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 300, GetClipMinY, 0, 0, 3);
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", GetCenterX, GetClipMinY, 0, 0, 4);
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMaxX, GetCenterY-100, 0, 0, 0);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMinX, GetCenterY-100, 0, 0, 1);
	Wait(300);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMaxX, GetCenterY-100, 0, 0, 2);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMinX, GetCenterY-100, 0, 0, 3);
	Wait(240);
	loop(35){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetClipMaxX, GetCenterY-rand_int(80,160), 0,0, 0);
	Wait(6);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetClipMinX, GetCenterY-rand_int(80,160), 0,0, 1);
	Wait(6);
	}
	Wait(60);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 100, GetClipMinY, 0, 0, 7);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 350, GetClipMinY, 0, 0, 8);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", GetCenterX, GetClipMinY, 0, 0, 4);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 150, GetClipMinY, 0, 0, 5);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 300, GetClipMinY, 0, 0, 6);
	Wait(360);
	DeleteEnemyShotToItem(ALL);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"akyu.txt",GetClipMaxX+0,GetClipMinY+180,0,0,0);
	WaitForZeroEnemy;
	Wait(60);
	loop(8){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 100, GetClipMinY, 0, 0, 3);
	Wait(12);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 200, GetClipMinY, 0, 0, 4);
	Wait(12);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1b.txt", 300, GetClipMinY, 0, 0, 5);
	Wait(12);
	}
	Wait(180);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 80, GetClipMinY, 0, 0, 9);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 160, GetClipMinY, 0, 0, 10);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 240, GetClipMinY, 0, 0, 11);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 320, GetClipMinY, 0, 0, 12);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 400, GetClipMinY, 0, 0, 13);
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 400, GetClipMinY, 0, 0, 13);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 320, GetClipMinY, 0, 0, 12);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 240, GetClipMinY, 0, 0, 11);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 160, GetClipMinY, 0, 0, 10);
	Wait(20);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1g.txt", 80, GetClipMinY, 0, 0, 9);
	Wait(180);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2a.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	Wait(180);
	loop(40){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetCenterX+rand_int(-180,180), GetClipMinY, 0, 0, 2);
	Wait(8);
	}
	Wait(120);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMaxX, GetCenterY-100, 0, 0, 2);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2a.txt",  GetClipMinX, GetCenterY-100, 0, 0, 1);
	Wait(240);
	loop(45){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetCenterX+rand_int(-180,180), GetClipMinY, 0, 0, 2);
	Wait(8);
	}
	Wait(30);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2a.txt", GetClipMaxX, GetCenterY-150, 0, 0, 2);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2o.txt", GetClipMinX, GetCenterY-150, 0, 0, 3);
	Wait(180);
	loop(40){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetCenterX+rand_int(-180,180), GetClipMinY, 0, 0, 2);
	Wait(8);
	}
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2a.txt",  GetClipMinX, GetCenterY-150, 0, 0, 3);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy2a.txt", GetClipMaxX, GetCenterY-150, 0, 0, 4);
	Wait(180);
	loop(50){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1r.txt", GetCenterX+rand_int(-180,180), GetClipMinY, 0, 0, 2);
	Wait(7);
	}
	Wait(180);
	DeleteEnemyShotToItem(ALL);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"FlanS.txt",GetCenterX, GetClipMinY,0,0,0);
	WaitForZeroEnemy();
	/*
	Wait(60);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy3.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	WaitForZeroEnemy();
	Wait(60);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy3.txt", GetCenterX, GetClipMinY, 0, 0, 0);
	WaitForZeroEnemy();
	Wait(120);
	loop(25){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMaxX, GetCenterY-rand_int(0,200), 0,0, 0);
	Wait(5);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMinX, GetCenterY-rand_int(0,200), 0,0, 1);
	Wait(5);
	while(OnBomb==true){yield;}
	}
	loop(30){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMaxX, GetCenterY-rand_int(0,200), 0,0, 0);
	Wait(4);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMinX, GetCenterY-rand_int(0,200), 0,0, 1);
	Wait(4);
	while(OnBomb==true){yield;}
	}
	loop(40){
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMaxX, GetCenterY-rand_int(0,200), 0,0, 0);
	Wait(3);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"enemy\enemy1y.txt", GetClipMinX, GetCenterY-rand_int(0,200), 0,0, 1);
	Wait(3);
	while(OnBomb==true){yield;}
	}
	WaitForZeroEnemy();
	*/
	Wait(120);
	FadeOutMusic(CSD~"area8.wav",60);
	Wait(120);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"Toziko.txt",GetClipMaxX+0,GetClipMinY+180,0,0,0);
	WaitForZeroEnemy();
	Wait(120);
	ClearStage; 
	yield;
	}


//---------------------------------------------------------------

@Initialize
{
	StageTask();
}


//---------------------------------------------------------------


@MainLoop
{
	        SetNormPoint(pointnorm);
	        if(GetPoint>=100&&pointnorm==100){
	            ExtendPlayer(1);
	            pointnorm = 300;
	        }
	        if(GetPoint>=300&&pointnorm==300){
	            ExtendPlayer(1);
	            pointnorm = 500;
	        }
	        if(GetPoint>=500&&pointnorm==500){
	            ExtendPlayer(1);
	            pointnorm = 1000;
	        }
	yield;
}

//---------------------------------------------------------------

@DrawLoop
	{
	}

//---------------------------------------------------------------

	@BackGround
	{
		SetColor(255, 125*sin((slide/5)%180)+130, 255*sin((slide/5+180)%180));
		SetViewTo(0,0,0);
		SetViewFrom(-150,90,51);

		//WriteZBuffer(true);
		//UseZBuffer(true);
		//SetFog(0,0,255,255,255);

		SetTexture(bg);
		SetGraphicRect(0,0,512,1024+slide);
		SetGraphicScale(1,1);
		SetAlpha(255);
		DrawGraphic3D(0,0,0);
		 slide += 1;
	}

//---------------------------------------------------------------

@Finalize
	{
	}
}
