
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+160,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(160);
		Sub;
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let v=rand_int(40,60);
			let i=90+v/2*r;
			let lp=0;
			loop(2)
			{
				SetAction(ACT_CHARGE,60);
				Concentration01(60);
				wait(60);
				SetAction(ACT_SLASH_H,60);
				
				let angle=90+i;
				Set(GetX,GetY,angle,lp);
				i-=v*r;
				lp++;
				wait(30);
			}
			
			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(60);
				sx=stx;
				sy=sty;
				let spd=30;
				let count=0;
				loop
				{
					local
					{
						let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
						let way=3;
						let wide=90;
						if(type)
						{
							way=4;
							wide=110;
						}
						let speed=1.5;
						let gra=[114,117];
						let delay=0;
						while(speed>=1.2)
						{
							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.1;
						}
						
					}
					
					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);
		}
		task Sub
		{
			let lp=0;
			loop
			{
				loop(5)
				{
					let vx=35;
					let sx=minX+rand(-8,8);
					SetShot(sx,vx,lp%2);
					wait(15);
					let sx=maxX+rand(-8,8);
					SetShot(sx,-vx,(lp+1)%2);
					wait(25);
				}
				lp++;
				wait(35);
			}
			task SetShot(let sx,let vx,let type)
			{
				loop
				{
					let sy=minY;
					let speed=[3,2];
					let angle=90+rand_int(-1,1)*2;
					let gra=[180,116];
					let delay=10;
					CreateShot01(sx,sy,speed[type%length(speed)],angle,gra[type%length(gra)],delay);
					if(sx>maxX+10||sx<minX-10){break;}
					wait(1);
					sx+=vx;
				}
			}
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+140,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		wait(160);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let v=rand_int(40,60);
			let i=90+v/2*r;
			let lp=0;
			local
			{
				SetAction(ACT_CHARGE,60);
				Concentration01(60);
				wait(60);
				SetAction(ACT_SLASH_V,60);
				let angle=GetAngleToPlayer+180;
				Set(GetX,GetY,angle);
				i-=v*r;
				lp++;
				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+=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=30;
				let count=0;
				let sp=0;
				loop
				{
					local
					{
						let wide=45;
						let way=4;
						let speed=3-sp;
						let angle=ag-wide/2;
						let gra=119;
						let delay=10;
						while(angle<=ag+wide/2+1)
						{
							ReflectShot(sx,sy,speed,angle+180,2,true,true,true,false,gra,delay);
							angle+=wide/(way-1);
						}
						sp+=0.1;
					}
					
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					sx+=spd*cos(ag);
					sy+=spd*sin(ag);
					count++;
					wait(1);
				}
			}
			wait(60);
			let wt=120;
			SetMovePosition02(cenX+rand(-80,80),minY+rand(150,180),wt);
			SetAction(ACT_MOVE,wt);
			let L=6;
			loop(L)
			{
				let p=GetAngleToPlayer;
				let v=62*r;
				let i=0;
				let spd=6;
				while(spd>=1.2)
				{
					let speed=[spd,spd/1.4];
					let ag=[p+v-i,p-v+i];
					let gra=[180,116];
					ascent(a in 0..2)
					{
						let angle=ag[a];
						let delay=10;
						CreateShot01(GetX,GetY,speed[a],angle,gra[a],delay);
					}
					spd/=1.2;
					i+=12*r;
				}
				wait(wt/L);
				r=-r;
			}
			wait(70);
			r=-r;
		}
	}
	
	
	
	task MainThread_Unlimited{}
	
}