
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Sakuya_AnimeLib.txt";
	
	tex_enemy=filedir~"Sakuya_Main.png";
	tex_spellbg=filedir~"Sakuya_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	boss_bgposx=cenX-90;
	boss_bgposy=cenY+30;
	
	@Initialize
	{
		point=480;
		SetLife(1000);
		SetTimer(60);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+170,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("斬離「ディストーションスクウェア」",68);
		wait(120);
		let r=-1;
		loop
		{
			SetAction(ACT_SHOT_B,90);
			local
			{
				let st=rand_int(0,3);
				let sx=[minX,maxX];
				let sy=minY;
				let speed=12;
				let gra=175;
				let delay=10;
				ascent(a in 0..2)
				{
					let p=atan2((cenY+rand(-20,20))-sy,cenX-sx[a]);
					let angle=p;
					CreateShot01(sx[a],sy,speed,angle,gra,delay);
					let leng=1800;
					let width=12;
					let graB=23;
					CreateLaser01(sx[a],sy,speed,angle,leng,width,graB,delay);
					Sub(sx[a],sy,speed,angle,st);
					r=-r;
				}
				
				task Sub(let sx,let sy,let spd,let ag,let st)
				{
					let wt=4;
					let count=st;
					loop
					{
						if(!(count%wt))
						{
							SetShot(sx,sy,count)
						}
						if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
						sx+=spd*cos(ag);
						sy+=spd*sin(ag);
						count++;
						yield;
					}
					task SetShot(let sx,let sy,let w)
					{
						local
						{
							let leng=500;
							let width=20;
							let alpha=192;
							let gra=17;
							let delay=30;
							let del=25;
							let angle=-90;
							while(angle<=90+1)
							{
								SetLaserObject(sx,sy,leng,width,angle,alpha,gra,delay,del);
								angle+=180;
							}
						}
						wait(120-w);
						local
						{
							let angle=-90;
							let gra=105;
							let delay=0;
							while(angle<=90+1)
							{
								let speed=12;
								while(speed>=0.5)
								{
									CreateShotA(1,sx,sy,delay);
									SetShotDataA(1,0,0,angle,0,speed/40,speed,gra);
									FireShot(1);
									speed/=1.4;
								}
								angle+=180;
							}
						}
					}
				}
			}
			wait(90);
			Concentration01(30);
			wait(30);
			local
			{
				let wt=40;
				MotionBlurEx(SHOT,wt,120,ADD);
				TimeStop(wt,1,0,1);
				Slow(1);
				wait(wt);
				Slow(0);
			}
			SetAction(ACT_SHOT_A,180);
			local
			{
				let i=0;
				let sp=0;
				loop(90)
				{
					let way=3;
					let speed=[5+sp,10];
					let angle=i;
					let gra=174;
					let delay=10;
					while(angle<i+360)
					{
						let v=30;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetShotDirectionType(ABSOLUTE);
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,speed[0],angle,0,-speed[0]/40,0,gra);
						SetShotDataA(1,30,NULL,NULL,8,-speed[0]/40,0,gra);
						SetShotDirectionType(PLAYER);
						SetShotDataA(1,30+360/8,NULL,0,0,speed[1]/50,speed[1],gra);
						FireShot(1);
						angle+=360/way;
					}
					wait(2);
					i+=7*r;
					sp+=0.05;
				}
			}
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(160,180),0,0,0,0,100);
			SetAction(ACT_MOVE,100);
			wait(150);
			r=-r;
		}
		
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}