#include_function".\GameData\StageData\Stage2_BG.txt";

area2_standby=true;

function Stage2
{
	let enemycurrent=GetCurrentScriptDirectory~".\GameData\EnemyData\";
	let enemy=[enemycurrent~"Zako\Stage2\Enemy021.txt",
			   enemycurrent~"Zako\Stage2\Enemy022.txt",
			   enemycurrent~"Zako\Stage2\Enemy023.txt",
			   enemycurrent~"Zako\Stage2\Enemy024.txt",
			   enemycurrent~"Zako\Stage2\Enemy025.txt",
			   enemycurrent~"Zako\Stage2\Enemy026.txt"];
	let boss=[enemycurrent~"Boss\Yuka\Yuka1_Plural.txt",
			  enemycurrent~"Boss\Yuka\Yuka1_Plural2.txt"];
	
	Stage2_Const(STAGEBG_INIT);
	
	wait(100);
	
	StageTelop(2);
	SetMusic(bgm[0],BGM_PLAY);
	
	SetBGPosition;
	Part1;
	Part2;
	
	Result;
	
	Stage2_Const(STAGEBG_DEST);
	
	yield;
	
	function Part2
	{
		/*
		//stagepart=4;
		CreateEnemyBossFromFile(boss[1],cenX,minY,0,0,0);
		//zako06(cenX,4);
		loop{yield;}
		//*/
		local
		{
			let y=[70,120,60,150,20,50];
			let s=0;
			ascent(a in 0..4)
			{
				zako01(maxX,y[a],2.5+s,160);
				s+=0.6;
				wait(9);
			}
		}
		local
		{
			let r=1;
			loop(2)
			{
				let x=[60,20,80,150,100];
				let s=0;
				ascent(a in 0..5)
				{
					zako01(cenX+x[a]*r,minY,2+s,90+10*r);
					s+=0.3;
					wait(9);
				}
				r=-r;
			}
		}
		local
		{
			let y=[70,120,60,150,20,50];
			let s=0;
			ascent(a in 0..4)
			{
				zako01(minX,y[a],2.5+s,20);
				s+=0.6;
				wait(9);
			}
		}
		wait(120);
		zako05(cenX+50,3,0);
		zako05(cenX-50,3,0);
		wait(250);
		loop(10)
		{
			zako03(cenX+90,minY,4.5,90);
			zako03(cenX-90,minY,4.5,90);
			wait(8);
		}
		wait(80);
		zako02(cenX,4.2);
		wait(250);
		zako04(cenX-100,4);
		wait(120);
		zako04(cenX+100,4);
		wait(250);
		loop(9)
		{
			zako03(cenX+10,minY,4.5,90);
			wait(8);
		}
		zako06(cenX-70,3);
		zako06(cenX-120,4);
		loop(9)
		{
			zako03(cenX+30,minY,5,90);
			wait(8);
		}
		wait(80);
		zako02(cenX+90,3.5);
		wait(100);
		loop(9)
		{
			zako03(maxX,cenY-90,4.5,190);
			wait(8);
		}
		loop(9)
		{
			zako03(maxX,cenY-120,5,190);
			wait(8);
		}
		zako06(cenX+70,3);
		zako06(cenX+120,4);
		
		stagepart=3;
		wait(160);
		
		zako05(cenX,4.5,1);
		wait(160);
		local
		{
			let r=-1;
			loop(2)
			{
				let y=[70,120,60,150,20,50];
				let s=0;
				ascent(a in 0..6)
				{
					zako01(cenX-(maxX-cenX)*r,100+y[a],7.2-s,90-110*r);
					s+=0.5;
					wait(6);
				}
				r=-r;
			}
		}
		zako04(cenX-40,1.5);
		zako04(cenX+40,1.5);
		wait(240);
		zako06(cenX-60,3);
		zako06(cenX-90,4);
		zako06(cenX-120,4.5);
		wait(160);
		zako06(cenX+60,3);
		zako06(cenX+90,4);
		zako06(cenX+120,4.5);
		wait(180);
		local
		{
			let r=1;
			loop(2)
			{
				let y=[70,120,60,150,20,50];
				let s=0;
				ascent(a in 0..6)
				{
					zako01(cenX-(maxX-cenX)*r,y[a],6.5-s,90-70*r);
					s+=0.6;
					wait(9);
				}
				wait(20);
				r=-r;
			}
		}
		wait(90);
		zako02(cenX-50,3.5);
		zako02(cenX+50,3.5);
		wait(160);
		zako06(cenX+90,4.5);
		zako06(cenX-90,4.5);
		wait(120);
		zako06(cenX+120,4);
		zako06(cenX-120,4);
		stagepart=4;
		wait(120);
		loop(9)
		{
			zako03(maxX,cenY-120,4.5,190);
			zako03(minX,cenY-120,4.5,-10);
			wait(8);
		}
		loop(9)
		{
			zako03(cenX+120,minY,4.5,120);
			zako03(cenX-120,minY,4.5,60);
			wait(8);
		}
		zako02(cenX,4.5);
		wait(90);
		SetMusic(bgm[0],BGM_FADEOUT_5);
		Warning;
		wait(180);
		frame_rflg=true;
		wait(80);
		CreateEnemyBossFromFile(boss[1],cenX,minY,0,0,0);
		wait(100);
		memory_flg[1]=true;
		SetMusic(bgm[1],BGM_PLAY);
		waitzero;
		frame_rflg=false;
		SetMusic(bgm[1],BGM_FADEOUT_10);
		wait(240);
	}
	
	
	
	
	function Part1
	{
		
		wait(135);
		
		local
		{
			let r=1;
			loop(2)
			{
				let y=[70,120,60,150,20,50];
				let s=0;
				ascent(a in 0..6)
				{
					zako01(cenX-(maxX-cenX)*r,y[a],2.5+s,90-70*r);
					s+=0.6;
					wait(9);
				}
				wait(12);
				r=-r;
			}
		}
		wait(120);
		zako02(cenX,3);
		wait(250);
		loop(7)
		{
			zako03(minX,140,4,0);
			wait(7);
		}
		loop(7)
		{
			zako03(maxX,140,4,180);
			wait(7);
		}
		wait(100);
		zako04(cenX-70,3);
		wait(70);
		local
		{
			let x=[60,20,80,150,100];
			let s=0;
			ascent(a in 0..5)
			{
				zako01(cenX+x[a],minY,2+s,100);
				s+=0.3;
				wait(8);
			}
		}
		wait(30);
		loop(12)
		{
			zako03(cenX+2,minY,4.5,90);
			wait(8);
		}
		wait(90);
		zako02(cenX-100,2);
		wait(140);
		loop(12)
		{
			zako03(cenX-2,minY,4.5,90);
			wait(8);
		}
		wait(40);
		zako04(cenX+80,3);
		wait(40);
		zako04(cenX-80,3);
		wait(80);
		local
		{
			let x=[-60,20,80,-10,40,-50,0,100,-100];
			let s=0;
			ascent(a in 0..9)
			{
				zako01(cenX+x[a],minY,2+s,90);
				s+=0.2;
				wait(7);
			}
		}
		wait(70);
		zako04(cenX,3.4);
		wait(150);
		loop(9)
		{
			zako03(minX,minY,5,70);
			wait(6);
		}
		loop(9)
		{
			zako03(maxX,minY,5,110);
			wait(6);
		}
		wait(200);
		
		local
		{
			let r=1;
			loop(2)
			{
				let y=[70,120,60,150,20,50];
				let s=0;
				ascent(a in 0..6)
				{
					zako01(cenX-(maxX-cenX)*r,100+y[a],7.2-s,90-110*r);
					s+=0.5;
					wait(8);
				}
				r=-r;
			}
		}
		wait(200);
		zako02(cenX-100,3.5);
		zako04(cenX+120,2);
		wait(110);
		loop(9)
		{
			zako03(minX,cenY-60,5,-10);
			wait(6);
		}
		loop(9)
		{
			zako03(cenX+10,minY,5,90);
			wait(6);
		}
		wait(40);
		zako02(cenX+100,3.5);
		zako04(cenX-120,2);
		wait(110);

		loop(9)
		{
			zako03(maxX,cenY-60,5,190);
			wait(6);
		}
		loop(9)
		{
			zako03(cenX-10,minY,5,90);
			wait(6);
		}		
		wait(120);
		zako02(cenX-40,3);
		zako02(cenX+40,3);
		wait(120);
		loop(10)
		{
			zako03(cenX+60,minY,4.5,90);
			zako03(cenX-60,minY,4.5,90);
			wait(7);
		}
		loop(10)
		{
			zako03(minX,150,5,0);
			zako03(maxX,150,5,180);
			wait(7);
		}
		stagepart=1;
		wait(340);
		//*/
		CreateEnemyBossFromFile(boss[0],cenX,minY,0,0,0);
		waitzero;
		stagepart=2;
	}
	
	task SetBGPosition
	{
		while(stagepart==0){yield;}
		while(bg_eye_lookat[2]>-1000)
		{
			bg_eye_lookat[2]=bg_eye_lookat[2]-4;
			yield;
		}
		while(stagepart==1){yield;}
		while(bg_eye_viewfrom[2]>-90)
		{
			bg_eye_viewfrom[2]=bg_eye_viewfrom[2]-0.5;
			yield;
		}
		while(stagepart==2){yield;}
		while(bg_eye_lookat[2]<0)
		{
			bg_eye_lookat[2]=bg_eye_lookat[2]+2;
			yield;
		}
		while(stagepart==3){yield;}
		while(bg_fog_perspectiveclip[1]<1900)
		{
			bg_fog_perspectiveclip[1]=bg_fog_perspectiveclip[1]+1;
			yield;
		}
	}
	
	function zako01(let x,let y,let spd,let ag){CreateEnemyFromFile(enemy[0],x,y,spd,ag,0);}
	function zako02(let x,let spd){CreateEnemyFromFile(enemy[1],x,minY,spd,90,0);}
	function zako03(let x,let y,let spd,let ag){CreateEnemyFromFile(enemy[2],x,y,spd,ag,0);}
	function zako04(let x,let spd){CreateEnemyFromFile(enemy[3],x,minY,spd,90,0);}
	function zako05(let x,let spd,let arg){CreateEnemyFromFile(enemy[4],x,minY,spd,90,arg);}
	function zako06(let x,let spd){CreateEnemyFromFile(enemy[5],x,minY,spd,90,0);}
}