
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Aya_AnimeLib.txt";
	
	tex_enemy=filedir~"Aya_Main.png";
	tex_spellbg=filedir~"Aya_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=420;
		SetLife(600);
		SetTimer(55);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard{}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("瞬撃「カマイタチの一閃」",71);
		wait(100);
		Sub;
		SetAction(ACT_SHOT_A,60);
		Concentration01(60);
		wait(60);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_B,100);
			let lp=0;
			loop(3)
			{
				let px=[GetPlayerX,minX-GetPlayerX,maxX+(maxX-GetPlayerX)];
				let py=GetPlayerY;
				
				let p=atan2(py-GetY,px[lp%length(px)]-GetX);
				let speed=9;
				let angle=p;
				let leng=500;
				let width=24;
				let gra=43;
				let delay=0;
				ReflectLaser(GetX,GetY,speed,angle,leng,width,gra,delay);
				
				lp++;
				wait(40);
			
			}
			SetMovePositionHermite(cenX+rand(-70,70),minY+rand(110,140),0,0,0,0,70);
			wait(40);
		}
		
		task Sub
		{
			wait(120);
			let lp=0;
			loop
			{
				local
				{
					let p=GetAngleToPlayer+180*lp;
					let way=11;
					let speed=[2.5,1.5];
					let angle=p;
					let gra=31;
					let delay=10;
					while(angle<p+360)
					{
						let v=20;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						ascent(a in 0..length(speed))
						{
							CreateShot01(sx,sy,speed[a],angle,gra,delay);
						}
						angle+=360/way;
					}
				}
				lp++;
				wait(20);
				if(lp%8==0)
				{
					let p=GetAngleToPlayer;
					let wide=20;
					let way=9;
					let speed=2;
					let ag=p;
					let gra=116;
					let delay=0;
					while(ag<p+360)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							CreateShot01(GetX,GetY,speed,angle,gra,delay);
							angle+=2;
						}
						ag+=360/way;
					}
				}
			}
		}
		
		task ReflectLaser(let sx,let sy,let speed,let angle,let leng,let width,let gra,let delay)
		{
			CreateLaser01(sx,sy,speed,angle,leng,width,gra,delay);
			wait(10+leng/10/speed);
			while(angle<0){angle+=360;}
			if(angle>=360){angle%=360;}
			let p=angle;
			loop
			{
				if     (sx>maxX){sx=maxX-1;p=180-angle;break;}
				else if(sx<minX){sx=minX+1;p=180-angle;break;}
				else if(sy>maxY){return;}
				else if(sy<minY){sy=minY+1;p=-angle;break;}
				
				sx+=speed*cos(angle);
				sy+=speed*sin(angle);
				yield;
			}
			CreateLaser01(sx,sy,speed*1.5,p,leng,width,gra,delay);
		}
	}
	
	
	
	
	task MainThread_Unlimited{}
	
}