
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Komachi_AnimeLib.txt";
	
	tex_enemy=filedir~"Komachi_Main.png";
	tex_spellbg=filedir~"Komachi_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	@Initialize
	{
		point=520;
		SetLife(1600);
		SetTimer(69);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	

	
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+150,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("境目「深く険しき江深淵」",75);
		wait(120);
		Sub;
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lmax=-250;
		let lp=rand_int(0,360);
		let lg=140;
		let vag=0;
		loop
		{
			let bx=cenX+60*cos(lp);
			let by=cenY+60+30*sin(lp/2);
			let i=lp*12;
			let lengA=-330;
			while(lengA<=lmax)
			{
				let sxA=GetGapX(bx,lengA,vag);
				let syA=GetGapY(by,lengA,vag);
				
				let lengB=lg+20*cos(lp*2+180);
				let lengC=100;
				
				ascent(a in 0..2)
				{
					let sxB=[GetGapX(sxA,lengB+lengC*cos(i),vag+90),
							 GetGapX(sxA,lengB+lengC*cos(i+180),vag-90)];
					let syB=[GetGapY(syA,lengB+lengC*cos(i),vag+90),
							 GetGapY(syA,lengB+lengC*cos(i+180),vag-90)];
					let angle=[vag+90,vag-90];
					let gra=190;
					let delay=0;
					let del=12;
					SetLaserObject(sxB[a],syB[a],500,50,angle[a],64,gra,delay,del);
				}
				
				i+=10*r;
				lengA+=20;
			}
			wait(6);
			if(lmax<330){lmax+=12;}
			lp++;
			vag+=2*sin(lp*2)*r;
		}
		
		task Sub
		{
			wait(100);
			loop
			{
				let wt=90;
				SetMovePositionHermite(GetPlayerX,cenY-rand(100,150),0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
				wait(wt);
				
				let wt=60;
				SetAction(ACT_CHARGE,wt);
//				SparkEffect(wt,255,92,255,true);
//				PlaySE(se[0]);
				wait(wt);
				SetAction(ACT_SHOT_B,50);
				
//				PlaySE(se[1]);
				SlowEffect(GetX,300);
				wait(4);
//				PlaySE(se[2]);
//				PlaySE(se[3]);
				wait(110);
				
				SetAction(ACT_SHOT_A,50);
				let p=GetAngleToPlayer;
				let s=0;
				loop(15)
				{
					let speed=1+s;
					let angle=p+rand(-1,1);
					let gra=248;
					let delay=0;
					CreateShot01(GetX,GetY,speed,angle,gra,delay);
					
					let speed=2+s/2;
					let wide=60;
					let gra=249;
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						CreateShot01(GetX,GetY,speed,angle,gra,delay);
						angle+=wide;
					}
					wait(2);
					s+=0.3;
				}
				wait(90);
				Sub;
			}
			
			task Sub
			{
				let fam=GetCurrentScriptDirectory~"Komachi_Familier01.txt";
				let r=1;
				loop(4)
				{
					let sx=GetX+rand(0,100)*r;
					let sy=GetY+rand(-60,60);
					CreateEnemyFromFile(fam,sx,sy,0,0,0);
					wait(25);
					r=-r;
				}
			}
		}
	}
	
	task SlowEffect(let sx,let wt)
	{
		let width=0;
		let alpha=16;
		let gra=191;
		
		Draw;
		wait(10);
		PlayerState;
		task PlayerState
		{
			loop(wt)
			{
				if(GetPlayerX>sx-width/4&&GetPlayerX<sx+width/4)
				{
					let vx=0;
					let vy=0;
					let speed=GetPlayerInfo(PLAYER_SPEED_HIGH);
					if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD){speed=GetPlayerInfo(PLAYER_SPEED_LOW);}
					if(GetKeyState(VK_UP)==KEY_HOLD){vy-=speed;}
					if(GetKeyState(VK_DOWN)==KEY_HOLD){vy+=speed;}
					if(GetKeyState(VK_LEFT)==KEY_HOLD){vx-=speed;}
					if(GetKeyState(VK_RIGHT)==KEY_HOLD){vx+=speed;}
					
					if(vx!=0&&vy!=0){vx/=1.4;vy/=1.4;}
					
					SetPlayerX(GetPlayerX-vx/1.5);
					SetPlayerY(GetPlayerY-vy/1.5);
				}
				yield;
			}
		}
		
		task Draw
		{
			let tuning=GetCommonData("Memory_ConfigData");
			let endflg=false;
			let w=20;
			let wdmax=200;
			loop(10)
			{
				SetLaserObject(sx,minY,500,2,90,alpha,gra,0,2);
				yield;
			}
			while(width<wdmax)
			{
				SetLaserObject(sx,minY,500,width,90,alpha,gra,0,2);
				yield;
				width+=wdmax/w;
			}
			let count=0;
			loop(wt-w)
			{
				SetLaserObject(sx,minY,500,width,90,alpha,gra,0,2);
				
				if(!tuning[1])
				{
					if(!(count%25)){Effect1;}
					if(!(count%4)){Effect2;}
				}
				count++;
				yield;
			}
			endflg=true;
			
			task Effect1
			{
				let wd=0;
				let wp=wdmax/5;
				let alpha=5;
				while(wd<wdmax*2&&alpha>0)
				{
					SetLaserObject(sx,minY,500,wd,90,alpha,gra,0,2);
					wd+=wp;
					wp*=0.9;
					alpha-=0.1;
					yield;
				}
			}
			
			task Effect2
			{
				let x=sx+rand(-width/4,width/4);
				let y=maxY;
				let leng=30;
				let speed=rand(2,5);
				let gra=48;
				let alpha=20;
				while(y>minY-leng&&!endflg)
				{
					SetLaserObject(x,y,leng,3,90,alpha,gra,0,2);
					y-=speed;
					yield;
				}
			}
		}
	}
}