
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Youmu_AnimeLib.txt";
	
	tex_enemy=filedir~"Youmu_Main.png";
	
	@Initialize
	{
		SetLife(4000);
		SetTimer(50);
		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);
		wait(180);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let p=GetAngleToPlayer;
			let wd=0;
			let i=6;
			let lp=0;
			let leng=120;
			while(leng>-120)
			{
				let bx=GetX+leng*cos(p);
				let by=GetY+leng*sin(p);
				
				let sx=[GetGapX(bx,wd,p+90),GetGapX(bx,wd,p-90)];
				let sy=[GetGapY(by,wd,p+90),GetGapY(by,wd,p-90)];
				
				ascent(a in 0..2)
				{
					let wide=300;
					let way=15+lp%2;
					let speed=[2,1.6];
					let angle=p-wide/2;
					let gra=[26,29];
					let delay=10;
					while(angle<=p+wide/2+1)
					{
						CreateShot02(sx[a],sy[a],0,angle,speed[a]/90,speed[a],gra[a],delay);
						angle+=wide/(way-1);
					}
				}
				
				wd+=i*cos(lp*10);
				i+=0.2;
				leng-=8;
				lp++;
				wait(8);
			}
			wait(40);
			local
			{
				SetAction(ACT_CHARGE,60);
				Concentration01(60);
				wait(60);
				SetAction(ACT_SLASH_H,60);
				let angle=GetAngleToPlayer+180;
				Set(GetX,GetY,angle);
				wait(30);
			}
			
			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+=spd*cos(ag);
				sy+=spd*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);
				}
				sx-=spd*cos(ag);
				sy-=spd*sin(ag);
				wait(30);
				ag+=180;
				let spd=30;
				let count=0;
				let sp=0;
				loop
				{
					local
					{
						let wide=80;
						let way=6;
						let speed=3-sp;
						let angle=ag-wide/2;
						let gra=119;
						let delay=10;
						while(angle<=ag+wide/2+1)
						{
							CreateShot02(sx,sy,0,angle+180,speed/100,speed,gra,delay);
							angle+=wide/(way-1);
						}
						sp+=0.12;
					}
					
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
					count++;
					wait(1);
				}
			}
			let wt=150;
			SetMovePosition02(cenX+rand(-80,80),minY+rand(150,180),wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
			wait(80);
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+140,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(180);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			local
			{
				loop(2)
				{
					wait(20);
					let wt=120;
					SetMovePosition02(cenX+rand(-80,80),minY+rand(150,180),wt);
					SetAction(ACT_MOVE,wt);
					let i=rand(0,360);
					loop(15)
					{
						let way=3;
						
						let speed=5.5;
						let angle=i;
						let gra=179;
						let delay=10;
						while(angle<i+360)
						{
							let v=30;
							let sx=GetX+v*cos(angle);
							let sy=GetY+v*sin(angle);
							SetShot(sx,sy,speed,angle,gra,delay);
							angle+=360/way;
						}
						i+=33.5*r;
						wait(9);
					}
					r=-r;
				}
				task SetShot(let sx,let sy,let spd,let ag,let gra,let delay)
				{
					let wide=0;
					let sp=0;
					loop(6)
					{
						let speed=spd+sp;
						if(wide==0)
						{
							let angle=ag;
							CreateShot01(sx,sy,speed,angle,gra,delay);
						}
						else
						{
							let angle=ag-wide/2;
							while(angle<=ag+wide/2+1)
							{
								CreateShot01(sx,sy,speed,angle,gra,delay);
								angle+=wide;
							}
						}
						sp+=-0.4;
						wide+=4;
					}
				}
			}
			
			local
			{
				let v=rand_int(40,60);
				let i=90+v/2*r;
				let lp=0;
				loop(2)
				{
					SetAction(ACT_CHARGE,10);
					Concentration01(30);
					wait(10);
					SetAction(ACT_SLASH_H,60);
					
					let angle=90+i;
					Set(GetX,GetY,angle,lp);
					i-=v*r;
					lp++;
					wait(40);
				}
				
				task Set(let sx,let sy,let ag,let t)
				{
					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,t);
				}
				task SetShot(let sx,let sy,let ag,let type)
				{
					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(20);
					sx=stx;
					sy=sty;
					let spd=30;
					let count=0;
					loop
					{
						let leng=GetGapLength(sx,sy,GetPlayerX,GetPlayerY);
						let px=GetGapX(sx,leng,atan2(GetPlayerY-sy,GetPlayerX-sx));
						let py=GetGapY(sy,leng/1.2,atan2(GetPlayerY-sy,GetPlayerX-sx));
						local
						{
							let p=atan2(py-sy,px-sx);
							let way=3;
							let wide=100;
							if(type)
							{
								way=4;
								wide=120;
							}
							let speed=5;
							let gra=[114,117];
							let delay=0;
							while(speed>=1.6)
							{
								let angle=p-wide/2;
								while(angle<=p+wide/2+1)
								{
									CreateShot01(sx,sy,speed,angle,gra[type%length(gra)],delay);
									angle+=wide/(way-1);
								}
								speed/=1.2;
							}
							
						}
						
						if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
						sx+=spd*cos(ag);
						sy+=spd*sin(ag);
						count++;
						wait(1);
					}
				}
			}
			wait(70);
			r=-r;
		}
	}
	
	
	
	task MainThread_Unlimited{}
	
}