
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Youmu_AnimeLib.txt";
	
	tex_enemy=filedir~"Youmu_Main.png";
	tex_spellbg=filedir~"Youmu_SpellBG.png";
	
	bg_rect=[0,0,512,768];
	
	@Initialize
	{
		point=420;
		SetLife(900);
		SetTimer(49);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+160,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("幽明剣「冥府を別つ剣閃」",48);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let wt=40;
			SetAction(ACT_CHARGE,wt);
			Concentration01(wt);
			Slow(1);
			MotionBlurEx(SHOT,wt,120,ADD);
			wait(wt);
			Slow(0);
			SetAction(ACT_SLASH_H,30);
			
			let v=rand_int(12,40);
			let i=90+v;
			loop(3)
			{
				let angle=90+i*r;
				Set(GetX,GetY,angle);
				i-=v;
				r=-r;
				wait(3);
			}
			
			task Set(let sx,let sy,let ag)
			{
				loop
				{
					let spd=10;
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
				}
				let angle=ag-180;
				let leng=580;
				SlashEffect(sx,sy,angle,leng,120);
				SetShot(sx,sy,angle);
			}
			task SetShot(let sx,let sy,let ag)
			{
				let spd=15;
				sx+=10*cos(ag);
				sy+=10*sin(ag);
				let stx=sx;
				let sty=sy;
				loop
				{
					CherryEffect(sx,sy);
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
					wait(1);
				}
				wait(60);
				sx=stx;
				sy=sty;
				let spd=10;
				let count=0;
				loop
				{
					local
					{
						let v=2;
						let way=5;
						let i=[ag,ag+(360/way)/3,ag-(360/way)/3];
						let speed=1;
						let angle=i[ceil(count/v)%length(i)];
						let gra=87;
						let delay=5;
						while(angle<i[ceil(count/v)%length(i)]+360)
						{
							CreateShot01(sx,sy,speed,angle,gra,delay);
							angle+=360/way;
						}
						
						let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
						
						let wide=150;
						let speed=2.5;
						let angle=p-wide/2;
						let gra=119;
						while(angle<=p+wide/2+1)
						{
							CreateShot02(sx,sy,0,angle,speed/150,speed,gra,delay);
							angle+=wide/(way-1);
						}
					}
					
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
					count++;
					wait(1);
				}
			}
			wait(140);
			let wt=140;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(150,180),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
			r=-r;
		}
		
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+200,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("断空剣「天衣無縫極」",49);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		local
		{
			let wt=50;
			SetAction(ACT_CHARGE,wt);
			Concentration01(wt);
			MotionBlurEx(SHOT,wt,120,ADD);
			wait(wt);
			SetAction(ACT_SLASH_H,60);
			
			local
			{
				let way=5;
				
				let ag=0;
				let i=-90;
				ascent(a in 0..way)
				{
					let leng=60;
					let sx=GetX+leng*cos(i);
					let sy=GetY+leng*sin(i);
					Set(sx,sy,ag);
					ag+=(360/way);
					i+=(360/way);
				}
			}
		}
		wait(90);
		Sub;
		loop
		{
			let wt=120;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(120,200),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
			
			let wt=50;
			SetAction(ACT_CHARGE,wt);
			Concentration01(wt);
			MotionBlurEx(SHOT,wt,120,ADD);
			wait(wt);
			SetAction(ACT_SLASH_H,60);
			loop(4)
			{
				let sx=GetPlayerX;
				let sy=GetPlayerY;
				let angle=rand(0,360);
				Set(sx,sy,angle);
			}
			wait(60);
		}
		task Sub
		{
			while(GetEnemyLife>400){yield;}
			loop
			{
				let sx=cenX+rand(-150,150);
				let sy=cenY+rand(-150,150);
				loop(2)
				{
					let angle=rand(0,360);
					Set(sx,sy,angle);
				}
				wait(180);
			}
		}
		
		task Set(let sx,let sy,let ag)
		{
			loop
			{
				let spd=10;
				if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
				sx+=spd*cos(ag);
				sy+=spd*sin(ag);
			}
			let angle=ag-180;
			let leng=580;
			SlashEffect(sx,sy,angle,leng,9);
			SetShot(sx,sy,angle);
		}
		
		task SetShot(let sx,let sy,let ag)
		{
			sx+=10*cos(ag);
			sy+=10*sin(ag);
			wait(90);
			local
			{
				let speed=25;
				let angle=ag;
				let leng=32;
				let width=16;
				let gra=127;
				let delay=0;
				while(speed>=1)
				{
					CreateLaser01(sx,sy,speed,angle,leng,width,gra,delay);
					speed/=1.2;
				}
			}
			local
			{
				loop(15)
				{
					CherryEffect(sx,sy);
				}
				
				let way=24;
				let speed=2;
				let angle=ag;
				let gra=87;
				let delay=10;
				while(angle<ag+360)
				{
					CreateShot02(sx,sy,0,angle,speed/120,speed,gra,delay);
					angle+=360/way;
				}
			}
		}
	}
	
	
	
	task MainThread_Unlimited{}
	
}