
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=360;
		SetLife(900);
		SetTimer(57);
		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("乖離「マインドオーバーマター」",60);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let warptime=0;
		loop
		{
			SetAction(ACT_SHOT_A,60);
			local
			{
				let lp=0;
				let leng=-200;
				let ag=rand(190,200);
				while(leng<200)
				{
					let way=30;
					let sx=GetGapX(GetX,leng,ag);
					let sy=GetGapY(GetY,leng,ag);
					let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
					let speed=[2.5,1.5];
					let angle=p;
					let gra=[172,171];
					let delay=5;
					while(angle<p+360)
					{
						SetWarpShot(sx,sy,speed[lp%length(speed)],angle,gra[lp%length(gra)],delay);
						angle+=360/way;
					}
					leng+=15;
					lp++;
					wait(1);
				}
				Concentration01(30);
				wait(30);
				ShotTimeWarp(40);
			}
			wait(90);
			SetAction(ACT_SHOT_B,60);
			local
			{
				let i=0;
				let sp=0;
				loop(4)
				{
					let p=GetAngleToPlayer+i;
					let way=18;
					let wide=6;
					
					let speed=2-sp;
					let angleA=p;
					let gra=169;
					let delay=10;
					while(angleA<p+360)
					{
						let angleB=angleA-wide/2;
						while(angleB<=angleA+wide/2+1)
						{
							let v=30;
							let sx=GetX+v*cos(angleB);
							let sy=GetY+v*sin(angleB);
							SetWarpShot(sx,sy,speed,angleB,gra,delay);
							angleB+=2;
						}
						angleA+=360/way;
					}
					sp+=0.2;
					i+=360/way/2;
					wait(15);
				}
				loop(2)
				{
					Concentration01(30);
					wait(30);
					ShotTimeWarp(40);
					wait(20);
				}
			}
			wait(30);
			let lp=0;
			loop(2)
			{
				let i=rand(0,360);
				let sp=0;
				let L=15;
				loop(L)
				{
					let way=14;
					let speed=1.4+sp;
					let angle=i;
					let gra=[174,170];
					let delay=10;
					while(angle<i+360)
					{
						let v=30;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetWarpShot(sx,sy,speed,angle,gra[lp%length(gra)],delay);
						angle+=360/way;
					}
					sp+=0.15;
					i+=(360/way)/(L/1.2)*r;
					wait(3);
				}
				Concentration01(30);
				wait(30);
				ShotTimeWarp(40);
				r=-r;
				lp++;
			}
			local
			{
				let way=180;
				let speed=1.6;
				let angle=0;
				let gra=175;
				let delay=10;
				while(angle<360)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					SetWarpShot(sx,sy,speed,angle,gra,delay);
					angle+=360/way;
				}
			}
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(110,130),0,0,0,0,100);
			SetAction(ACT_MOVE,100);
			wait(100);
			r=-r;
		}
		
		function ShotTimeWarp(let wt)
		{
			warptime=wt;
			yield;
			warptime=0;
		}

		task SetWarpShot(
		let x,
		let y,
		let speed,
		let angle,
		let gra,
		let delay
		){
			let count=0;
			let o=Obj_Create(OBJ_SHOT);
			Obj_SetX(o,x);
			Obj_SetY(o,y);
			Obj_SetSpeed(o,speed);
			Obj_SetAngle(o,angle);
			ObjShot_SetGraphic(o,gra);
			ObjShot_SetDelay(o,delay);
			ObjShot_SetBombResist(o,true);
			while(!Obj_BeDeleted(o))
			{
				if(warptime>1)
				{
					Obj_SetX(o,Obj_GetX(o)+(warptime*Obj_GetSpeed(o))*cos(Obj_GetAngle(o)));
					Obj_SetY(o,Obj_GetY(o)+(warptime*Obj_GetSpeed(o))*sin(Obj_GetAngle(o)));
					
				}
				yield;
			}
		}
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}