
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=480;
		SetLife(700);
		SetTimer(55);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("瞑斬剣「楼観から弾をも断つ心の眼」",57);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		Sub;
		wait(90);
		loop
		{
			let bx=GetX;
			let by=GetY;
			let px=cenX+rand(-100,100);
			let py=cenY+rand(-100,100);
			SetTargeting(px,py,0.5,90,1);
			local
			{
				let wt=30;
				SetAction(ACT_CHARGE,wt);
				MotionBlurEx(SHOT,wt,120,ADD);
				Slow(1);
				Concentration01(wt);
				wait(wt);
				Slow(0);
				let p=atan2(py-by,px-bx);
				SetAction(ACT_SLASH_V,60);
//				if(lp%2==0){SetShot(bx,by,p);}
//				else{ShotDeleteSlash(bx,by,p);}
				SetShot(bx,by,p);
				wait(5);
				SetAction(ACT_SLASH_H,60);
				SetShot(px,py,p+rand(70,110));
//				if(lp%2==0){ShotDeleteSlash(px,py,p+rand(70,110));}
//				else{SetShot(px,py,p+rand(70,110));}
			}
			
			task ShotDeleteSlash(let sx,let sy,let ag)
			{
				let spd=15;
				loop
				{
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
				}
				ag+=180;
				let leng=580;
				SlashEffect(sx,sy,ag,leng,50);
				sx+=spd*cos(ag);
				sy+=spd*sin(ag);
				loop
				{
					DeleteEnemyShotImmediatelyInCircle(SHOT,sx,sy,40);
					CherryEffect(sx,sy);
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
				}
			}
			
			task SetShot(let sx,let sy,let ag)
			{
				let spd=15;
				let leng=580;
				loop
				{
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
				}
				ag+=180;
				SlashEffect(sx,sy,ag,leng,70);
				let sp=15;
				let l=0;
				while(l<leng)
				{
					DeleteEnemyShotImmediatelyInCircle(SHOT,sx,sy,30);
					loop(4){CherryEffect(sx,sy);}
					Shot(sx,sy);
					sx+=sp*cos(ag);
					sy+=sp*sin(ag);
					l+=sp;
					wait(1);
				}
				task Shot(let sx,let sy)
				{
					wait(20);
					if(GetGapLength(GetPlayerX,GetPlayerY,sx,sy)>=50)
					{
						let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
						let speed=2;
						let angle=p;
						let gra=120;
						let delay=15;
						CreateShot02(sx,sy,0,angle,speed/120,speed,gra,delay);
					}
				}
			}
			
			wait(90);
			SetMovePositionHermite(cenX+rand(-90,90),minY+rand(110,140),0,0,0,0,100);
			SetAction(ACT_MOVE,100);
			wait(90);
			lp++;
		}
		
		task Sub
		{
			Concentration01(30);
			let bx=GetX;
			let by=GetY;
			let i=0;
			let lp=0;
			let v=0;
			loop
			{
				let sx=bx+v*cos(i);
				let sy=by+(v/2)*sin(i/2);
				local
				{
					let gra=8;
					let delay=5;
					SetDelayEffect(sx,sy,gra,delay);
				}
				
				if(lp%50==0)
				{
					local
					{
						let way=120;
						let speed=0.9;
						let angle=0;
						let gra=119;
						let delay=0;
						while(angle<360)
						{
							CreateShot02(sx,sy,0,angle,speed/100,speed,gra,delay);
							angle+=360/way;
						}
					}
				}
				if(v<150){v+=0.5;}
				i+=1;
				lp++;
				wait(1);
			}
		}
		
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+60,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("無刃剣「魂魄一閃流れ」",58);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let px=GetPlayerX;
			let py=GetPlayerY;
			SetTargeting(px,py,0.5,100,0);
			local
			{
				let p=atan2(py-GetY,px-GetX);
				let wt=40;
				SetAction(ACT_CHARGE,wt);
				MotionBlurEx(SHOT,wt,120,ADD);
				Slow(1);
				Concentration01(wt);
				wait(wt);
				Slow(0);
				SetAction(ACT_SLASH_V,60);
				let leng=400;
				let mx=GetGapX(GetX,leng,p);
				let my=GetGapY(GetY,leng,p);
				SetMovePositionHermite(mx,my,0,0,0,0,15);
				SetShot(GetX,GetY,p);
			}
			wait(100);
			let mx=cenX+(cenX-GetX);
			if(mx<minX+32){mx=minX+32;}
			if(mx>maxX-32){mx=maxX-32;}
			SetMovePositionHermite(mx,minY+60,0,0,0,0,90);
			SetAction(ACT_MOVE,90);
			wait(220);
			
			task SetShot(let sx,let sy,let ag)
			{
				let spd=10;
				loop
				{
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag-180);
					sy+=spd*sin(ag-180);
				}
				SlashEffect(sx,sy,ag,580,60);
				sx+=spd*cos(ag);
				sy+=spd*sin(ag);
				loop
				{
					CherryEffect(sx,sy);
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
				}
				sx+=80*cos(ag);
				sy+=80*sin(ag);
				Sub;
				wait(30);
				let wide=1;
				while(wide<80)
				{
					let bx=[GetGapX(sx,wide,ag+90),GetGapX(sx,wide,ag-90)];
					let by=[GetGapY(sy,wide,ag+90),GetGapY(sy,wide,ag-90)];
					let angle=ag+180;
					let leng=1000;
					let width=15;
					let gra=47;
					let delay=0;
					let del=50;
					ascent(a in 0..2)
					{
						SetLaser(bx[a],by[a],leng,width,angle,255,gra,delay,del);
					}
					
					wide+=3;
					wait(1);
				}
				
				task Sub
				{
					let wp=40;
					let wide=80;
					loop(12)
					{
						let bx=[GetGapX(sx,wide,ag+90),GetGapX(sx,wide,ag-90)];
						let by=[GetGapY(sy,wide,ag+90),GetGapY(sy,wide,ag-90)];
						let angle=ag+180;
						let leng=1000;
						let width=15;
						let gra=43;
						let delay=100;
						let del=60;
						ascent(a in 0..2)
						{
							SetLaserObject(bx[a],by[a],leng,width,angle,255,gra,delay,del);
							SubShot(bx[a],by[a],angle);
						}
						
						wide+=wp;
						wp/=1.3;
					}
					
					task SubShot(let sx,let sy,let ag)
					{
						wait(30);
						let leng=0;
						while(leng<700)
						{
							sx+=leng*cos(ag);
							sy+=leng*sin(ag);
							
							let speed=1;
							let p=[ag,ag+180];
							let gra=115;
							let delay=10;
							ascent(a in 0..2)
							{
								let angle=p[a]+rand_int(-3,3);
								CreateShot02(sx,sy,0,angle,speed/200,speed,gra,delay);
							}
							leng+=1.5;
						}
					}
				}
			}
		}
		
		task SetLaser(
		let x,
		let y,
		let leng,
		let width,
		let angle,
		let alpha,
		let gra,
		let delay,
		let del
		){
			let count=0;
			let obj=Obj_Create(OBJ_LASER);
			Obj_SetX(obj,x);
			Obj_SetY(obj,y);
			Obj_SetAngle(obj,angle);
			Obj_SetAlpha(obj,alpha);
			ObjLaser_SetLength(obj,leng);
			ObjLaser_SetWidth(obj,width);
			ObjLaser_SetSource(obj,false);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			Obj_SetAutoDelete(obj,false);
			ObjShot_ToItem(obj,false);
			let lbase=leng;
			while(!Obj_BeDeleted(obj))
			{
				ObjLaser_SetLength(obj,leng);
				if(count==del)
				{
					Obj_Delete(obj);
				}
				leng-=lbase/del;
				count++;
				yield;
			}
		}
	}
	
	
	
	
	task MainThread_Unlimited{}
	
}