
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,100);
		SetAction(ACT_MOVE,100);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,480);
			let L=2;
			loop(3)
			{
				let lp=0;
				loop(L)
				{
					let p=90+rand(70,90)*r;
					let speed=rand(2,3);
					let angle=p;
					let gra=[46,41];
					let delay=0;
					let wt=80;
					let obj=CreateShot02(GetX,GetY,speed,angle,-speed/wt,0,gra[lp%length(gra)],delay);
					SetShot(obj,wt,lp%2);
					lp++;
					if(lp%2){r=-r;}
					wait(50-L*4);
				}
				L=ceil(L*2);
				wait(80);
			}
			local
			{
				let lp=0;
				loop(2)
				{
					let p=90+rand(70,90)*r;
					let speed=rand(1,2);
					let angle=p;
					let gra=[46,41];
					let delay=0;
					let wt=80;
					let obj=CreateShot02(GetX,GetY,speed,angle,-speed/wt,0,gra[lp%length(gra)],delay);
					SetShot2(obj,wt,lp%2);
					lp++;
					r=-r;
					wait(60);
				}
			}
			wait(90);
			let wt=120;
			SetMovePositionHermite(cenX+rand(-50,50),minY+rand(120,150),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 wide=15;
					let way=15;
					let roundway=2;
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
					let spd=3.5;
					let gra=30;
					let delay=20;
					if(type)
					{
						wide=120;
						gra=25;
					}
					let ag=p;
					while(ag<p+360)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							let speed=[spd,spd*0.4];
							ascent(a in 0..2)
							{
								CreateShot02(sx,sy,0,angle,speed[a]/90,speed[a],gra,delay);
							}
							angle+=wide/(way-1);
						}
						ag+=360/roundway;
					}
				}
			}
			wait(70);
			let px=GetPlayerX;
			let py=GetPlayerY;
			loop(8)
			{
				if(Obj_BeDeleted(obj)){return;}
				let roundway=2;
				let way=3;
				let wide=70;
				let sx=Obj_GetX(obj);
				let sy=Obj_GetY(obj);
				let p=atan2(py-sy,px-sx);
				let speed=[4.5,3];
				let gra=86;
				let delay=25;
				if(type)
				{
					gra=81;
				}
				let ag=p;
				while(ag<p+360)
				{
					let angle=ag-wide/2;
					while(angle<=ag+wide/2+1)
					{
						ascent(a in 0..length(speed))
						{
							CreateShot02(sx,sy,0,angle,speed[a]/60,speed[a],gra,delay);
						}
						angle+=wide/(way-1);
					}
					ag+=360/roundway;
				}
				wait(4);
			}
			Obj_Delete(obj);
		}
		
		task SetShot2(let obj,let wt,let type)
		{
			wait(wt);
			if(!Obj_BeDeleted(obj))
			{
				local
				{
					let way=25;
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
					let gra=150;
					let delay=20;
					if(type)
					{
						gra=145;
					}
					let speed=4.5;
					while(speed>=1.5)
					{
						let angle=p;
						while(angle<p+360)
						{
							CreateShot02(sx,sy,0,angle,speed/90,speed,gra,delay);
							angle+=360/way;
						}
						speed/=1.2;
						p+=(360/way)/2;
					}
				}
			}
			Obj_Delete(obj);
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(100);
		Sub;
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			local
			{
				let p=90+110*r;
				let speed=1.7;
				let angle=p;
				let gra=[46,41];
				let delay=0;
				
				let obj=CreateShot02(GetX,GetY,speed*3,angle,-speed/15,speed,gra[floor(lp/2)%2],delay);
				
				SetShot(obj,floor(lp/2)%2);
			}
			wait(35);
			lp++;
			r=-r;
		}
		
		task Sub
		{
			wait(60);
			let r=1;
			if(rand_int(0,1)){r=-r;}
			loop
			{
				loop(2)
				{
					let sp=0;
					let p=GetAngleToPlayer-30*r;
					loop(12)
					{
						let speed=2+sp;
						let angle=p;
						let gra=56;
						let delay=10;
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						p+=15*r;
						sp+=0.2;
						wait(2);
					}
					wait(60);
					r=-r;
				}
				let wt=140;
				SetMovePositionHermite(cenX+rand(-80,80),minY+rand(100,130),0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
				wait(wt);
				r=-r;
			}
		}
		
		task SetShot(let obj,let type)
		{
			let wt=10;
			wait(rand_int(0,wt));
			let r=1;
			if(type){r=-r;}
			while(!Obj_BeDeleted(obj))
			{
				local
				{
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=90;//+rand(-5,5);
					let gra=86;
					let delay=10;
					if(type){gra=81;}
					let ag=p;
					while(ag<p+360)
					{
						let wide=24;
						let sp=-0.5*r;
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							let speed=3+sp;
							CreateShot02(sx,sy,0,angle,speed/50,speed,gra,delay);
							angle+=wide;
							sp+=1*r;
						}
						ag+=180;
					}
					wait(wt);
				}
			}
			Obj_Delete(obj);
		}
	}
	
	
	task MainThread_Unlimited{}
	
}