
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=420;
		SetLife(900);
		SetTimer(57);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		let r=1;
		if(rand_int(0,1)){r=-r;}
		SetMovePositionHermite(cenX+90*r,minY+80,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("超弦「Ｄ・ブレーンワールド」",64);
		wait(120);
		loop
		{
			SetAction(ACT_SHOT_B,60);
			let p=GetAngleToPlayer;
			local
			{
				let wide=10;
				let way=20;
				let speed=1.5;
				let ag=p;
				let gra=173;
				let delay=10;
				while(ag<p+360)
				{
					let angle=ag-wide/2;
					while(angle<=ag+wide/2+1)
					{
						let v=30;
						let sx=GetX+v*cos(angle);
						let sy=GetY+v*sin(angle);
						SetWarpShot(sx,sy,speed,angle,gra,delay);
						angle+=1;
					}
					ag+=360/way;
				}
			}
			wait(180);
			local
			{
				let way=20;
				let angle=p;
				let gra=169;
				let delay=20;
				while(angle<p+360)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					let speed=4.5;
					while(speed>2.5)
					{
						SetWarpShot(sx,sy,speed,angle,gra,delay);
						speed/=1.1;
					}
					angle+=360/way;
				}
			}

			wait(170);
			let wt=120;
			SetMovePosition02(cenX+rand(-80,-110)*r,minY+rand(150,170),wt);
			SetAction(ACT_MOVE,wt);
			local
			{
				let L=20;
				let p=GetAngleToPlayer;
				loop(L)
				{
					let way=4;
					let wide=200;
					
					let angle=p-wide/2;
					let gra=175;
					let delay=10;
					while(angle<=p+wide/2+1)
					{
						let speed=2.5;
						SetWarpShot(GetX,GetY,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
				//	p-=(360/L)*r;
					wait(wt/L);
				}
			}
			wait(240);
			r=-r;
		}
		
		task SetWarpShot(
		let x,
		let y,
		let speed,
		let angle,
		let gra,
		let delay
		){
			angle=angle%360;
			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);
			let flg=false;
			while(!Obj_BeDeleted(o))
			{
				x=Obj_GetX(o);
				y=Obj_GetY(o);
				
				if((x<minX||x>maxX||y<minY||y>maxY)&&!flg)
				{
					let sx=x;
					let sy=y;
					let ag=angle;
					if(x<minX)
					{
						sx=maxX;
						sy=cenY+(cenY-y);
					}
					if(x>maxX)
					{
						sx=minX;
						sy=cenY+(cenY-y);
					}
					if(y<minY)
					{
						sx=cenX+(cenX-x);
						sy=maxY;
					}
					if(y>maxY)
					{
						sx=cenX+(cenX-x);
						sy=minY;
					}
					CreateShot01(sx,sy,speed,ag,gra,delay);
					flg=true;
				}
				
				yield;
			}
		}
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}