
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Yuka_AnimeLib.txt";
	
	tex_enemy=filedir~"Yuka_Main.png";
	
	@Initialize
	{
		SetLife(3150);
		SetTimer(44);
		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(200);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		Sub;
		let i=rand(0,360);
		SetAction(ACT_SHOT_B,3600);
		loop
		{
			let way=9;
			let speed=4.5;
			let angle=i;
			let gra=20;
			let delay=10;
			while(angle<i+360)
			{
				let v=15;
				let sx=GetX+v*cos(angle);
				let sy=(GetY+20)+v*sin(angle);
				CreateShot02(sx,sy,0,angle,speed/160,speed,gra,delay);
				angle+=360/way;
			}
			i+=15*r;
			wait(7);
		}
		
		task Sub
		{
			wait(80);
			let wt=120;
			let lp=0;
			loop
			{
				let wide=8;
				let way=16;
				let sx=[GetX+80,GetX-80];
				let gra=[25,30];
				let speed=1.2;
				let delay=20;
				let p=atan2(GetPlayerY-GetY,GetPlayerX-sx[lp%2]);
				let angleA=p;
				while(angleA<p+360)
				{
					let angleB=angleA-wide/2;
					while(angleB<=angleA+wide/2+1)
					{
						CreateShot02(sx[lp%2],GetY,0,angleB,speed/60,speed,gra[lp%2],delay);
						angleB+=2;
					}
					angleA+=360/way;
				}
				local
				{
					let leng=60;
					let ag=0;
					while(ag<360)
					{
						let stx=sx[lp%2]+leng*cos(ag);
						let sy=GetY+leng*sin(ag);
						
						let wide=160;
						let way=3;
						
						let p=atan2(GetPlayerY-sy,GetPlayerX-stx);
						let speed=3;
						let angle=p-wide/2;
						let gra=[57,62];
						let delay=6;
						while(angle<=p+wide/2+1)
						{
							CreateShot02(stx,sy,0,angle,speed/80,speed,gra[lp%2],delay);
							angle+=wide/(way-1);
						}
						
						ag+=9;
					}
				}
				lp++;
				wait(wt);
				if(wt>35){wt-=4;}
			}
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(200);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,100);
			local
			{
				let lp=0;
				let speed=3.5;
				let p=rand(0,360);
				loop(10)
				{
					let way=20;
					let limit=60;
					let leng=20;
					let sch=[0.3,-0.3];
					let angle=p;
					let gra=[25,30];
					let delay=10;
					while(angle<p+360)
					{
						let sx=GetX+leng*cos(angle);
						let sy=GetY+leng*sin(angle);
						ascent(a in 0..length(sch))
						{
							SetShot(sx,sy,speed,angle,sch[a],gra[a],delay);
						}
						angle+=360/way;
					}
					speed/=1.2;
				}
				
				task SetShot(let sx,let sy,let speed,let angle,let sch,let gra,let delay)
				{
					let flame=0;
					let leng=0;
					let o=Obj_Create(OBJ_SHOT);
					Obj_SetX(o,sx);
					Obj_SetY(o,sy);
					Obj_SetSpeed(o,0);
					Obj_SetAngle(o,angle);
					ObjShot_SetGraphic(o,gra);
					ObjShot_SetDelay(o,delay);
					Obj_SetAutoDelete(o,false);
					ObjShot_SetBombResist(o,false);
					
					while(!Obj_BeDeleted(o))
					{
						Obj_SetX(o,sx+leng*cos(angle));
						Obj_SetY(o,sy+leng*sin(angle));
						
						if(flame>=delay)
						{
							angle+=sch;
							leng+=speed;
						}
						if(leng>=500){Obj_Delete(o);}
						flame++;
						yield;
					}
				}
			}
			wait(250);
			SetMove(cenX+rand(-100,100),minY+rand(90,110),120);
			wait(150);
			local
			{
				let way=12;
				let p=GetAngleToPlayer;
				let speed=6;
				let gra=115;
				let delay=10;
				while(speed>=3)
				{
					let angle=p;
					while(angle<p+360)
					{
						CreateShotA(1,GetX,GetY,delay);
						SetShotDataA(1,0,speed,angle,0,0,0,gra);
						let cnt=40;
						let wide=85;
						let angleB=angle-wide/2;
						while(angleB<=angle+wide/2+1)
						{
							CreateShotA(2,0,0,delay);
							SetShotDataA(2,0,speed,angleB,0,0,0,gra);
							AddShot(cnt,1,2,0);
							angleB+=wide;
						}
						SetShotKillTime(1,cnt+1);
						FireShot(1);
						angle+=360/way;
					}
					speed/=1.04;
				}
			}
			wait(100);
			r=-r;
		}
	}
	
	
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+140,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(200);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,100);
			local
			{
				let rd=rand_int(2,5);
				let wide=14;
				let way=12;
				
				let p=GetAngleToPlayer+(360/way)/2;
				let speed=12;
				let angleA=p;
				let gra=151;
				let delay=10;
				while(angleA<p+360)
				{
					let angleB=angleA-wide/2;
					while(angleB<=angleA+wide/2+1)
					{
						CreateShotA(1,GetX,GetY,delay);
						SetShotDataA(1,0,speed,angleB,0,0,0,gra);
						let wideB=330;
						let sp=0;
						let rb=1;
						let cnt=rd;
						while(cnt<=100)
						{
							let speedB=2.5-sp;
							let angleC=angleB-(wideB/2)*rb;
							let graB=31;
//							while(angleC<=angleB+wideB/2+1)
//							{
								CreateShotA(2,0,0,0);
								SetShotDataA(2,0,0,angleC,0,speedB/100,speedB,graB);
								AddShot(cnt,1,2,0);
//								angleC+=wideB;
//							}
							cnt+=2;
							sp+=0.11;
							wideB+=15;
							if(wideB<=0){wideB+=360;}
							rb=-rb;
						}
						FireShot(1);
						angleB+=2;
					}
					angleA+=360/way;
				}
			}
			let next=0;
			loop(240)
			{
				yield;
				if(GetEnemyShotCount<10){next=1;break;}
			}
			if(!next)
			{
				SetMove(cenX+rand(-100,100),minY+rand(120,135),100);
				wait(150);
//				loop(160){yield;if(GetEnemyShotCount<10){break;}}
			}
			wait(30);
		}
	}
	
}