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

area1_standby=true;

function Stage1
{
	let enemycurrent=GetCurrentScriptDirectory~".\GameData\EnemyData\";
	let enemy=[enemycurrent~"Zako\Stage1\Enemy011.txt",
			   enemycurrent~"Zako\Stage1\Enemy012.txt",
			   enemycurrent~"Zako\Stage1\Enemy013.txt",
			   enemycurrent~"Zako\Stage1\Enemy014.txt",
			   enemycurrent~"Zako\Stage1\Enemy015.txt"];
	let boss=[enemycurrent~"Boss\Daiyousei\Daiyousei_Plural.txt",
			  enemycurrent~"Boss\Aya\Aya_Plural.txt"];
	
	Stage1_Const(STAGEBG_INIT);
	
	wait(110);
	StageTelop(1);
	SetMusic(bgm[0],BGM_PLAY);
	
	Part1;
	Part2;
	
	Result;
	
	Stage1_Const(STAGEBG_DEST);
	
	yield;
	
	function Part2
	{
	/*
		wait(60);
		CreateEnemyBossFromFile(boss[1],cenX,minY-50,0,0,0);
		loop{yield;}
		//*/
		
		zako01(minX,minY+60,3.5,70);
		wait(30);
		zako01(minX,minY+40,5,60);
		wait(90);
		zako01(maxX,minY+60,3.5,110);
		wait(30);
		zako01(maxX,minY+40,5,120);
		wait(170);
		local
		{
			let r=1;
			loop(2)
			{
				loop(7)
				{
					zako04(cenX-120*r,minY,2,90);
					zako04(cenX-100*r,minY,2.4,90);
					wait(10);
				}
				r=-r;
			}
		}
		wait(60);
		zako05(cenX+70,3.5);
		wait(140);
		local
		{
			let x=[90,50,120,70,160,30];
			let s=0;
			ascent(a in 0..length(x)*2)
			{
				zako02(cenX-x[a%length(x)],2.5+s);
				s+=0.2;
				wait(7);
			}
		}
		wait(120);
		zako03(cenX,4);
		wait(120);
		local
		{
			loop(9)
			{
				zako04(cenX+120,minY,2,90);
				zako04(cenX+100,minY,2.3,90);
				zako04(cenX+80,minY,2.6,90);
				wait(12);
			}
		}
		wait(80);
		local
		{
			let x=[90,50,-120,-70,160,30,-20,-150];
			let s=0;
			ascent(a in 0..length(x)*2)
			{
				zako02(cenX+x[a%length(x)]/2,2.5+s);
				s+=0.15;
				wait(7);
			}
		}
		zako05(cenX-100,3.5);
		wait(180);
		zako01(cenX-100,minY,4.3,90);
		zako01(cenX-110,minY,3.5,80);
		wait(90);
		zako03(cenX+80,4);
		wait(170);
		local
		{
			loop(9)
			{
				zako04(cenX-120,minY,2,90);
				zako04(cenX-100,minY,2.3,90);
				zako04(cenX-80,minY,2.6,90);
				wait(12);
			}
		}
		wait(60);
		local
		{
			let x=cenX-120;
			while(x<=cenX+120)
			{
				zako02(x,4.5);
				x+=40;
			}
			wait(30);
			let x=cenX-140;
			while(x<=cenX+140)
			{
				zako02(x,3.5);
				x+=40;
			}
			wait(30);
			let x=cenX-160;
			while(x<=cenX+160)
			{
				zako02(x,2.5);
				x+=40;
			}
		}
		//*/
		wait(180);
		SetMusic(bgm[0],BGM_FADEOUT_5);
		stagepart=1;
		Warning;
		wait(180);
		
		frame_rflg=true;
		SetBGRoll;
		wait(80);
		CreateEnemyBossFromFile(boss[1],cenX,minY-50,0,0,0);
		wait(120);
		memory_flg[0]=true;
		SetMusic(bgm[1],BGM_PLAY);
		waitzero;
		frame_rflg=false;
		SetMusic(bgm[1],BGM_FADEOUT_10);
		wait(240);
	}
	
	function Part1
	{
	
		wait(60);

		zako01(cenX-120,minY,4.2,80);
		zako01(cenX-160,minY,3.2,90);
		wait(70);
		zako01(cenX+120,minY,4.2,100);
		zako01(cenX+160,minY,3.2,90);
		wait(90);
		local
		{
			let sp=0;
			let x=cenX-150;
			while(x<=cenX+150)
			{
				zako02(x,2.5+sp);
				x+=30;
				sp+=0.15;
				wait(10);
			}
		}
		wait(160);
		zako01(cenX,minY,2,91);
		zako01(cenX,minY,2,89);
		wait(60);
		zako03(cenX,3);
		wait(170);
		local
		{
			let x=[90,50,120,70,160,30];
			let s=0;
			ascent(a in 0..length(x))
			{
				zako02(cenX+x[a],3+s);
				s+=0.2;
				wait(10);
			}
			
			s=0;
			ascent(a in 0..length(x))
			{
				zako02(cenX-x[a],3+s);
				s+=0.2;
				wait(10);
			}
		}
		wait(90);
		zako01(cenX-60,minY,2.2,80);
		zako01(cenX-80,minY,3.2,90);
		zako01(cenX+60,minY,2.2,100);
		zako01(cenX+80,minY,3.2,90);
		wait(190);
		zako03(cenX+80,2.5);
		zako03(cenX-80,2.5);
		wait(140);
		loop(12)
		{
			zako04(cenX-120,minY,2.4,90);
			zako04(cenX+120,minY,2.4,90);
			wait(8);
		}
		wait(50);
		local
		{
			let x=cenX-120;
			while(x<=cenX+120)
			{
				zako02(x,4.5);
				x+=40;
			}
			wait(40);
			let x=cenX-140;
			while(x<=cenX+140)
			{
				zako02(x,3.5);
				x+=40;
			}
		}
		wait(200);//*/
		CreateEnemyBossFromFile(boss[0],cenX,minY-50,0,0,0);
		waitzero;
		wait(240);
	}
	
	task SetBGRoll
	{
		let v=0;
		let count=0;
		while(count<187)
		{
			bg_eye_viewfrom[1]=bg_eye_viewfrom[1]+v;
			v+=0.02;
			count++;
			yield;
		}
		
		let vy=0;
		while(stagenum==1)
		{
			bg_vector3[1]=bg_vector3[1]-vy;
			bg_eye_viewfrom[1]=bg_eye_viewfrom[1]+v;
			if(v>0.001){v/=1.01;}
			if(vy<4){vy+=0.05;}
			yield;
		}
	}
	
	
	function zako01(x,y,spd,ag)
	{
		CreateEnemyFromFile(enemy[0],x,y,spd,ag,0);
	}
	
	function zako02(x,spd)
	{
		CreateEnemyFromFile(enemy[1],x,minY,spd,90,0);
	}
	function zako03(x,spd)
	{
		CreateEnemyFromFile(enemy[2],x,minY,spd,90,0);
	}	
	function zako04(x,y,spd,ag)
	{
		CreateEnemyFromFile(enemy[3],x,y,spd,ag,0);
	}
	function zako05(x,spd)
	{
		CreateEnemyFromFile(enemy[4],x,minY,spd,90,0);
	}
}