
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Suika_AnimeLib.txt";
	
	tex_enemy=filedir~"Suika_Main.png";
	
	@Initialize
	{
		SetLife(5000);
		SetTimer(58);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+140,0,0,0,0,200);
		SetAction(ACT_MOVE,200);
		wait(200);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,120);
			let p=GetAngleToPlayer+90*r;
			let sp=0;
			loop(18)
			{
				let speed=4-sp;
				let ag=[p,p+180];
				let gra=[46,41];
				let wt=80;
				let delay=10;
				ascent(a in 0..2)
				{
					let angle=ag[a];
					let obj=CreateShot02(GetX,GetY,speed,angle,-speed/wt,0,gra[a],delay);
					SetShot(obj,wt,a);
				}
				sp+=0.1;
				p+=16*r;
				wait(5);
				
			}
			wait(200);
			local
			{
				let way=30;
				let p=rand(0,360);
				let speed=5;
				let gra=39;
				let delay=15;
				while(speed>=1)
				{
					let angle=p;
					while(angle<p+360)
					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						angle+=360/way;
					}
					p+=(360/way)/2;
					speed/=1.2;
				}
			}
			let wt=140;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(120,160),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
		}
		task SetShot(let obj,let wt,let type)
		{
			wait(wt);
			if(!Obj_BeDeleted(obj))
			{
				local
				{
					let way=12;
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
					let speed=2.5;
					let gra=14;
					let delay=20;
					if(type)
					{
						way=19;
						speed=1.5;
						p=0;
						gra=9;
					}
					
					let angle=p;
					while(angle<p+360)
					{
						CreateShot02(sx,sy,0,angle,speed/90,speed,gra,delay);
						angle+=360/way;
					}
				}
				
				Obj_Delete(obj);
			}
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,200);
		SetAction(ACT_MOVE,200);
		wait(200);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let p=90-rand(70,120)*r;
			let sp=0;
			loop(12)
			{
				let speed=1;
				let angle=p;
				let gra=46;
				let delay=12;
				
				let obj=CreateShot02(GetX,GetY,speed*4,angle,-speed/20,speed,gra,delay);
				SetShot(obj,sp);
				wait(4);
				sp+=0.12;
				p+=17*r;
			}
			wait(260);
			let wt=140;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(100,130),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			let lp=0;
			loop(3)
			{
				let way=15;
				let p=GetAngleToPlayer+((360/way)/2)*lp;
				
				let speed=1.8;
				let angle=p;
				let gra=55;
				let delay=10;
				while(angle<p+360)
				{
					CreateShot02(GetX,GetY,speed*2.5,angle,-speed/20,speed,gra,delay);
					angle+=360/way;
				}
				lp++;
				wait(70);
			}
			r=-r;
		}
		
		task SetShot(let obj,let sp)
		{
			Sub;
			wait(25);
			if(!Obj_BeDeleted(obj))
			{
				local
				{
					let way=22;
					let p=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
					let speed=2.5+sp;
					let gra=14;
					let delay=20;
					let angle=p;
					while(angle<p+360)
					{
						let v=15;
						let sx=Obj_GetX(obj)+v*cos(angle);
						let sy=Obj_GetY(obj)+v*sin(angle);
						CreateShot02(sx,sy,0,angle,speed/90,speed,gra,delay);
						angle+=360/way;
					}
				}
			}
			let r=1;
			if(rand_int(0,1)){r=-r;}
			wait(30);
			while(!Obj_BeDeleted(obj))
			{
				if(GetGapLength(GetPlayerX,GetPlayerY,Obj_GetX(obj),Obj_GetY(obj))<60){break;}
				let p=Obj_GetAngle(obj)+rand(150,180)*r;
				let way=2;
				let wide=20;
				let sx=Obj_GetX(obj);
				let sy=Obj_GetY(obj);
				let angle=p-wide/2;
				let gra=70;
				let delay=20;
				while(angle<=p+wide/2+1)
				{
					let speed=[1,1.1];
					ascent(a in 0..length(speed))
					{
						CreateShot02(sx,sy,0,angle,speed[a]/60,speed[a],gra,delay);
					}
					angle+=wide/(way-1);
				}
				
				let way=5;
				let p=atan2(GetPlayerY-sy,GetPlayerX-sx)+(360/way)*rand_int(0,way);
				let angle=p;
				let gra=6;
				let delay=0;
				local
				{
					let speed=1.5;
					CreateShot02(sx,sy,-speed/2,angle,speed/260,speed,gra,delay);
				}
				
				r=-r;
				wait(10);
			}
			
			task Sub
			{
				while(!Obj_BeDeleted(obj))
				{
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=Obj_GetAngle(obj)+rand_int(-2,2);
					let speed=0.8;
					let angle=p;
					let gra=86;
					let delay=10;
					CreateShot02(sx,sy,0,angle,speed/100,speed,gra,delay);
					wait(5);
				}
			}
		}
	}
	
	
	task MainThread_Unlimited{}
	
}