
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Suika_AnimeLib.txt";
	
	tex_enemy=filedir~"Suika_Main.png";
	
	@Initialize
	{
		SetLife(4500);
		SetTimer(61);
		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,120);
			local
			{
				let p=90+rand(70,110)*r;
				ascent(a in 0..2)
				{
					let speed=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[a],delay);
					SetShot(obj,wt,a);
					p+=180;
					wait(20);
				}
				wait(60);
			}
			wait(50);
			let wt=120;
			SetMovePositionHermite(cenX+rand(-60,60),minY+rand(120,150),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			loop(4)
			{
				let wide=90;
				let way=7;
				let ag=GetAngleToPlayer;
				let gra=83;
				let delay=10;
				while(ag<GetAngleToPlayer+360)
				{
					let v=[25,60];
					ascent(a in 0..2)
					{
						let sx=GetX+v[a]*cos(ag);
						let sy=GetY+v[a]*sin(ag);
						let px=GetPlayerX;
						let py=GetPlayerY;
						let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
						
						let speed=GetGapLength(px,py,sx,sy)/60;
						let angle=p-wide/2;
						while(angle<=p+wide/2+1)
						{
							CreateShot01(sx,sy,speed,angle,gra,delay);
							angle+=wide/(way-1);
						}
					}
					ag+=18;
				}
				wait(60);
			}
			r=-r;
		}
		
		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=rand(0,360);
					let spd=4.5;
					let gra=70;
					let delay=20;
					if(type)
					{
						gra=65;
						r=-r;
					}
					while(spd>=1)
					{
						let angle=p;
						while(angle<p+360)
						{
							let speed=[spd,spd*0.5];
							ascent(a in 0..2)
							{
								CreateShot02(sx,sy,0,angle,speed[a]/90,speed[a],gra,delay);
							}
							angle+=360/way;
						}
						p+=4*r;
						spd/=1.15;
					}
				}
				
				Obj_Delete(obj);
			}
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+150,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,90);
			local
			{
				let p=90+rand(70,110)*r;
				ascent(a in 0..2)
				{
					let speed=5;
					let angle=p;
					let gra=[46,41];
					let delay=0;
					let wt=70;
					let obj=CreateShot02(GetX,GetY,speed,angle,-speed/wt,0,gra[a],delay);
					SetShot(obj,wt,a);
					p+=180;
					wait(20);
				}
				wait(60);
			}
			wait(50);
			let wt=150;
			SetMovePositionHermite(cenX+rand(-60,60),minY+rand(130,160),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			loop(3)
			{
				let wide=100;
				let way=5;
				let ag=GetAngleToPlayer;
				let gra=83;
				let delay=10;
				while(ag<GetAngleToPlayer+360)
				{
					let v=[15,40];
					ascent(a in 0..2)
					{
						let sx=GetX+v[a]*cos(ag);
						let sy=GetY+v[a]*sin(ag);
						let px=GetGapX(GetX,160,GetAngleToPlayer);
						let py=GetGapY(GetY,160,GetAngleToPlayer);
						let p=atan2(py-sy,px-sx);
						
						let speed=GetGapLength(px,py,sx,sy)/60;
						let angle=p-wide/2;
						while(angle<=p+wide/2+1)
						{
							CreateShot01(sx,sy,speed,angle,gra,delay);
							angle+=wide/(way-1);
						}
					}
					ag+=18;
				}
				wait(60);
			}
		}
		
		task SetShot(let obj,let wt,let type)
		{
			loop(wt)
			{
				let sx=Obj_GetX(obj);
				if(sx<=minX||sx>=maxX){break;}
				yield;
			}
			if(!Obj_BeDeleted(obj))
			{
				local
				{
					let way=40;
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let p=rand(0,360);
					let gra=30;
					let delay=20;
					if(type)
					{
						gra=25;
						r=-r;
					}
					let angle=p;
					while(angle<p+360)
					{
						let speed=[4,3,2.2,1.4];
						ascent(a in 0..length(speed))
						{
							CreateShot02(sx,sy,0,angle,speed[a]/140,speed[a],gra,delay);
						}
						angle+=360/way;
					}
				}
				
				Obj_Delete(obj);
			}
		}
	}
	
	
	task MainThread_Unlimited{}
	
}