
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Yuka_AnimeLib.txt";
	
	tex_enemy=filedir~"Yuka_Main.png";
	tex_spellbg=filedir~"Yuka_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	@Initialize
	{
		point=450;
		SetLife(580);
		SetTimer(50);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+100,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("魔砲「フラワリングマスタースパーク」",24);
		wait(180);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			task ShotMain
			{
				SetAction(ACT_SHOT_B,300);
				let px=GetPlayerX;
				let py=GetPlayerY;
				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=160;
					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++;
						let v=0.7;
						if(px<GetPlayerX){px+=v;}
						if(px>GetPlayerX){px-=v;}
						if(py<GetPlayerY){py+=v;}
						if(py>GetPlayerY){py-=v;}
						wdp+=60;
					}
					
					/*
					task SetSE
					{
						PlaySE(se[2]);
						wait(10);
						PlaySE(se[3]);
					}
					*/
				}
			}
			
			task Sub
			{
				let way=6;
				let p=GetAngleToPlayer+(360/way)/4;
				loop(7)
				{
					loop(1)
					{
						let sp=0;
						let wide=0;
						let L=10;
						loop(L+1)
						{
							let speed=3.4-sp;
							let angle=p;
							let gra=83;
							let delay=10;
							while(angle<p+360)
							{
								WideShot(GetX,GetY+20,speed,angle,wide,gra,delay);
								angle+=360/way;
							}
							wide+=360/way/L;
							sp+=0.28;
						}
					}
					p+=(360/way/2)*r;
					wait(2);
					function WideShot(x,y,spd,ag,wide,gra,delay)
					{
						if(wide==0)
						{
							CreateShot01(x,y,spd,ag,gra,delay);
						}
						else
						{
							let angle=ag-wide/2;
							while(angle<=ag+wide/2+0.5)
							{
								CreateShot01(x,y,spd,angle,gra,delay);
								angle+=wide;
							}
						}
					}
				}
				wait(50);
				local
				{
					let lp=0;
					let speed=3;
					let p=rand(0,360);
					loop(7)
					{
						let way=40;
						let limit=60;
						let leng=20;
						let sch=[4,-4];
						let angle=p;
						let gra=[33,38];
						let delay=10;
						while(angle<p+360)
						{
							let sx=GetX+leng*cos(angle);
							let sy=GetY+leng*sin(angle);
							CreateShotA(1,sx,sy,delay);
							SetShotDataA(1,0,0,angle+90*r,sch[lp%2],speed/limit,speed,gra[lp%2]);
							SetShotDataA(1,limit,NULL,NULL,0,0,0,NULL);
							FireShot(1);
							angle+=360/way;
						}
						wait(1);
						speed/=1.2;
						r=-r;
						lp++;
					}
				}
			}
			
			ShotMain;
			Sub;
			wait(250);
			SetMove(cenX+rand(-100,100),minY+rand(90,110),90);
			wait(150);
			r=-r;
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+90,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("魔砲「デュアルスパーク」",25);
		wait(180);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_TURN,42);
			wait(30);
			Concentration01(30);
			invincible=true;
			wait(60);
			SetX(cenX+120*r);
			SetY(minY+50);
			CreateEnemyFromFile(GetCurrentScriptDirectory~"Yuka1_Familier01.txt",cenX-120*r,GetY,0,0,0);
			SetAction(ACT_TURN,42);
			invincible=false;
			Concentration01(30);
			let px=GetPlayerX;
			let py=GetPlayerY;
			SetTargeting(px,py,0.5,240,0);
			wait(60);
			LaserMain;
			wait(80);
			Sub;
			wait(60);
			local
			{
				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;
				}
			}
			
			SetAction(ACT_TURN,42);
			wait(30);
			Concentration01(30);
			invincible=true;
			wait(60);
			let v=rand_int(105,120);
			SetX(cenX-v*r);
			SetY(minY+100);
			CreateEnemyFromFile(GetCurrentScriptDirectory~"Yuka1_Familier01.txt",cenX+v*r,GetY,0,0,1);
			SetAction(ACT_TURN,42);
			invincible=false;
			Concentration01(30);
			px=GetX;
			py=GetY+300;
			wait(60);
			LaserMain;
			wait(80);
			Sub;
			wait(60);
			local
			{
				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=[2,1.4];
					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);
			}
			
			if(rand_int(0,1)){r=-r;}
			
			
			function Sub
			{
				let wide=30;
				let sp=0;
				loop(65)
				{
					let speed=3.5-sp;
					let p=atan2(py-GetY,px-GetX);
					let angle=p-wide/2;
					let gra=46;
					let delay=10;
					let leng=250;
					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.015;
					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_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("全壊「ジェノサイドスパーク」",26);
		wait(180);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_B,100);
			Sub;
			let way=3;
			let p=GetAngleToPlayer;
			loop(7)
			{
				loop(1)
				{
					let sp=0;
					let wide=0;
					let L=20;
					loop(L+1)
					{
						let speed=4.8-sp;
						let angle=p;
						let gra=83;
						let delay=10;
						while(angle<p+360)
						{
							WideShot(GetX,GetY+20,speed,angle,wide,gra,delay);
							angle+=360/way;
						}
						wide+=360/way/L;
						sp+=4/(L+1);
					}
				}
				p+=(360/way/4)*r;
				wait(10);
				function WideShot(x,y,spd,ag,wide,gra,delay)
				{
					if(wide==0)
					{
						CreateShot01(x,y,spd,ag,gra,delay);
					}
					else
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+0.5)
						{
							CreateShot01(x,y,spd,angle,gra,delay);
							angle+=wide;
						}
					}
				}
			}
			local
			{
				let lp=0;
				let speed=3;
				let p=rand(0,360);
				loop(10)
				{
					let way=24;
					let limit=60;
					let leng=20;
					let sch=[4,-4];
					let angle=p;
					let gra=[33,38];
					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))
						{
							CreateShotA(1,sx,sy,delay);
							SetShotDataA(1,0,0,angle+90*r,sch[a],speed/limit,speed,gra[a]);
							SetShotDataA(1,limit,NULL,NULL,0,0,0,NULL);
							FireShot(1);
						}
						angle+=360/way;
					}
					speed/=1.2;
					r=-r;
				}
			}
			SetAction(ACT_TURN,42);
			wait(30);
			Concentration01(30);
			invincible=true;
			wait(60);
			invincible=false;
			SetX(cenX+120*r);
			SetY(minY-120);
			ShotMain(cenX-120*r,cenY);
			wait(300);
			
			
			SetX(cenX);
			SetY(minY+120);
			SetAction(ACT_TURN,42);
			Concentration01(30);
			wait(120);
			r=-r;
			task Sub
			{
				let wide=30;
				let sp=0;
				loop(84)
				{
					let speed=25;
					let p=90;
					let angle=p-wide/2;
					let gra=43;
					let delay=10;
					let leng=800;
					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+=8;
					wait(1);
				}
			}
			
			task ShotMain(let px,let py)
			{
				SetTargeting(px,py,1.5,100,0);
				let sx=GetX;
				let sy=GetY+20;
				
			//	SetLaser;
				wait(90);
				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=240;
					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++;
						let v=1.7;
						if(px<GetPlayerX){px+=v;}
						if(px>GetPlayerX){px-=v;}
						if(py<GetPlayerY){py+=v;}
						if(py>GetPlayerY){py-=v;}
						wdp+=60;
					}
					
					/*
					task SetSE
					{
						PlaySE(se[2]);
						wait(10);
						PlaySE(se[3]);
					}
					*/
				}
			}
		}
	}
	
}
