script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Yuka_AnimeLib.txt";
	
	tex_enemy=filedir~"Yuka_Main.png";
	
	@Initialize
	{
		EnemyInitialize(1);
		SetAnimetion(tex_enemy);
	}
	@MainLoop{yield;}
	
	@Finalize{}
	
	
	task MainThread_Advanced
	{
		yield;
		SetAction(ACT_TURN,42);
		Concentration01(30);
		let px=GetPlayerX;
		let py=GetPlayerY;
		if(enemyargument)
		{
			px=GetX;
			py=GetY+300;
		}
		wait(60);
		LaserMain;
		wait(80);
		Sub;
		wait(60);
		if(!enemyargument)
		{
			let wide=340;
			let p=atan2(py-GetY,px-GetX)+180;
			let speed=3;
			let gra=116;
			let delay=10;
			let angle=p-wide/2;
			while(angle<=p+wide/2+1)
			{
				CreateShot02(GetX,GetY,0,angle,speed/20,speed,gra,delay);
				angle+=1;
			}
		}
		else
		{
			wait(40);
			SetAction(ACT_SHOT_A,100);
			ascent(a in 0..2)
			{
				let way=45;
				let limit=60;
				let leng=20;
				let p=rand(0,360);
				let ag=[p+90,p-90];
				let speed=[1.4,2];
				let sch=[-2,2];
				let angle=ag[a];
				let gra=[33,38];
				let delay=10;
				while(angle<ag[a]+360)
				{
					let sx=GetX+leng*cos(angle);
					let sy=GetY+leng*sin(angle);
					CreateShotA(1,sx,sy,delay);
					SetShotDataA(1,0,0,angle,sch[a],speed[a]/limit,speed[a],gra[a]);
					SetShotDataA(1,limit,NULL,NULL,0,0,0,NULL);
					FireShot(1);
					angle+=360/way;
				}
			}
			wait(100);
		}
		SetAction(ACT_TURN,42);
		wait(30);
		Concentration01(30);
		invincible=true;
		wait(30);
		VanishEnemy;
		
		function Sub
		{
			let wide=30;
			let sp=0;
			loop(65)
			{
				let speed=2.5-sp;
				let p=atan2(py-GetY,px-GetX);
				let angle=p-wide/2;
				let gra=46;
				let delay=10;
				let leng=180;
				let width=12;
				while(angle<=p+wide/2+1)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					CreateLaser01(sx,sy,speed,angle,leng,width,gra,delay);
					angle+=wide;
				}
				wide+=10.5;
				sp+=0.01;
				wait(2);
			}
		}
		
		task LaserMain
		{
			SetAction(ACT_SHOT_B,300);
			let sx=GetX;
			let sy=GetY+20;
			
			SetLaser;
			Laser;
			function SetLaser
			{
				//PlaySE(se[0]);
				let leng=0;
				let max=900;
				let wt=90;
				while(leng<max)
				{
					let width=60;
					let angle=atan2(py-sy,px-sx);
					let gra=247;
					SetLaserObject(sx,sy,leng,width,angle,255,gra,100,2);
					leng+=max/wt;
					yield;
				}
				
			}
			function Laser
			{
//				SetSE;
				let leng=800;
				let wt=150;
				let w=2;
				let p=atan2(py-sy,px-sx);
				let width=120;
				let widthbase=width;
				
				let lp=rand_int(0,8);
				let wdp=0;
				loop(wt/w)
				{
					p=atan2(py-sy,px-sx);
					let wide=width/10;
					let a=0;
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						let sx_=sx+(leng/12)*cos(angle+180);
						let sy_=sy+(leng/12)*sin(angle+180);
						let gbase=121;
						let gra=[gbase+(lp%8),gbase+((lp+4)%8)];
						SetLaserObject(sx_,sy_,leng,widthbase/2,angle,255,gra[a],0,w*5);
						SetLaserObject(sx_,sy_,leng,width,angle,255,gra[a],0,w*3);
						a++;
						angle+=wide;
					}
					SetLaserObject(sx,sy,leng,width,p,255,192,0,w*5);
					wait(w);
					width+=40*cos(wdp);
					lp++;
					wdp+=60;
				}
				
				/*
				task SetSE
				{
					PlaySE(se[2]);
					wait(10);
					PlaySE(se[3]);
				}
				*/
			}
		}
	}
	
	
	task MainThread_Standard{}
	task MainThread_Unlimited{}
}
