
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Suika_AnimeLib.txt";
	
	tex_enemy=filedir~"Suika_Main.png";
	tex_spellbg=filedir~"Suika_SpellBG.png";
	
	bg_rect=[0,0,512,768];
	
	@Initialize
	{
		point=550;
		SetLife(1700);
		SetTimer(70);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("実鬼「百万鬼夜行」",88);
		wait(100);
		SetMove;
		Sub1;Sub2;
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let i=rand(0,360);
		let lp=0;
		loop
		{
			let leng=[150,90];
			let speed=[6,7.5];
			let ag=[i,-i];
			let way=[4,3];
			let gra=[78,73];
			
			let max=1;
			if(GetEnemyLife()<=1000){max=2;}
			
			ascent(a in 0..max){SetShot(leng[a],speed[a],ag[a],way[a],gra[a],lp);}
			
			wait(2);
			i+=1.4;
			lp++;
			
			task SetShot(let leng,let spd,let ag,let way,let gra,let lp)
			{
				let a=ag;
				while(ag<360+a)
				{
					let sx=GetX+leng*cos(ag);
					let sy=GetY+leng*sin(ag);
					let speed=[spd,1];
					let angle=ag;
					let delay=30;
					
					let v=3;
					if(lp%(v*2)<v)
					{
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,speed[0],angle,0,-speed[1]/5,speed[1],gra);
						FireShot(1);
					}
					else
					{
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,0,0,0,0,0,gra);
						SetShotKillTime(1,0);
						FireShot(1);
					}
					
					ag+=360/way;
				}
			}
		}
		
		task SetMove
		{
			wait(180);
			loop
			{
				let wt=120;
				SetMovePositionHermite(cenX+rand(-60,60),minY+rand(110,130),0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
				wait(wt*2.5);
			}
		}
		
		task Sub1
		{
			while(GetEnemyLife>=1300){yield;}
			loop
			{
				let way=[40,25];
				let p=GetAngleToPlayer;
				let speedA=[0.5,6];
				let speedB=[2,1];
				let gra=[38,33];
				
				let max=1;
				if(GetEnemyLife<=700){max=2;}
				ascent(a in 0..max)
				{
					let angle=p;
					while(angle<p+360)
					{
						SetShot(speedA[a],speedB[a],angle+(a*((360/way[a])/2)),gra[a]);
						angle+=360/way[a];
					}
				}
				wait(60);
			}
			
			task SetShot(let speedA,let speedB,let angle,let gra)
			{
				let delay=10;
				let r=1;
				if(speedA>speedB){r=-10;}
				CreateShot02(GetX,GetY,speedA,angle,speedB/120*r,speedB,gra,delay);
			}
		}
		
		task Sub2
		{
			while(GetEnemyLife>=350){yield;}
			loop
			{
				let way=30;
				let p=90;
				
				let speed=1.7;
				let angle=p;
				let gra=48;
				let delay=10;
				while(angle<p+360)
				{
					CreateShot01(GetX,GetY,speed,angle+(360/way)/2,gra,delay);
					angle+=360/way;
				}
				wait(30);
			}
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("伝説「鬼ヶ島地獄変」",89);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let lp=0;
			let sp=0;
			let sv=0.2;
			loop(4)
			{
				let way=5;
				if(GetLife<1400){way=7;sv=0.25;}
				if(GetLife<900){way=8;sv=0.35;}
				if(GetLife<500){way=9;sv=0.4;}
				let p=GetAngleToPlayer+((360/way)/2)*lp;
				let speed=4-sp;
				let angle=p;
				while(angle<p+360)
				{
					SetShot(speed,angle);
					angle+=360/way;
				}
				let p=GetAngleToPlayer+((360/way)/2)*(lp+1);
				let ag=p;
				let gra=33;
				let delay=10;
				while(ag<p+360)
				{
					let wide=6;
					let angle=ag-wide/2;
					while(angle<=ag+wide/2+1)
					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						angle+=2;
					}
					ag+=360/way;
				}
				sp+=sv;
				lp++;
				wait(35);
			}
			let wt=140;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(110,130),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(40);
			r=-r;
			task SetShot(let speedbase,let ag)
			{
				let delay=10;
				local
				{
					let speed=speedbase;
					let angle=ag;
					let gra=54;
					CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
				}
				local
				{
					let roundway=18;
					let v=30;
					let gra=25;
					let sp=-90;
					let angleA=ag;
					while(angleA<ag+360)
					{
						let sx=GetX+v*cos(angleA);
						let sy=GetY+v*sin(angleA);
						let px=GetGapX(GetX,speedbase*v,ag);
						let py=GetGapY(GetY,speedbase*v,ag);
						let speed=GetGapLength(px,py,sx,sy)/v;
						let angleB=atan2(py-sy,px-sx);
						CreateShot02(sx,sy,0,angleB,speed/60,speed,gra,delay);
						angleA+=360/roundway;
						sp+=360/roundway;
					}
				}
			}
		}
	}
	
	
	task MainThread_Unlimited{}
	
}