
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Murasa_AnimeLib.txt";
	
	tex_enemy=filedir~"Murasa_Main.png";
	tex_spellbg=filedir~"Murasa_SpellBG.png";
	let tex_anchor=filedir~"Murasa_Anchor.png";
	bg_rect=[0,0,640,480];
	
	@Initialize
	{
		point=330;
		SetLife(900);
		SetTimer(52);
		EnemyBossInitialize;
		LoadGraphic(tex_anchor);
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;DeleteGraphic(tex_anchor);}
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+80,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("横転「爆沈アンカー」",32);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			let wt=200;
			SetMove(cenX+rand(-100,100),minY+rand(70,100),wt);
			let L=50;
			let i=GetAngleToPlayer;
			let lp=rand_int(0,360);
			let w=0;
			loop(L)
			{
				let way=7;
				
				let speed=3;
				let ag=i;
				let gra=29;
				let delay=10;
				while(ag<i+360)
				{
					let leng=60;
					let sx=GetX+leng*cos(ag+lp);
					let sy=GetY+leng*sin(ag+lp*2);
					let angle=ag;
					CreateShot02(sx,sy,0,angle,speed/100,speed,gra,delay);
					ag+=360/way;
				}
				i-=9*r;
				wait(wt/L);
				w+=wt/L;
				lp++;
			}
			local
			{
				SetAction(ACT_SHOT_B,200);
				Anchor(GetX,GetY);
			}
			wait(400);
			r=-r;
		}
		
		
		task Anchor(let sx,let sy)
		{
			let obj=SetEffectObject(tex_anchor,4);
			SetEffectObjectRect(obj,0,0,128,128);
			ObjEffect_SetRenderState(obj,ADD);
			let angle=0;
			let xscale=0;
			let alpha=192;
			let vanish=0;
			State;
			while(!vanish)
			{
				if(GetGapLength(GetPlayerX,GetPlayerY,sx,sy)<=40&&GetTimeOfPlayerInvincibility==0)
				{
					ShootDownPlayer;
				}
				Obj_SetPosition(obj,sx,sy);
				ObjEffect_SetAngle(obj,0,0,angle+90);
				ObjEffect_SetScale(obj,xscale,1);
				let color=255;
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
				}
				if(xscale<1){xscale+=0.1;}
				yield;
			}
			while(xscale>0)
			{
				Obj_SetPosition(obj,sx,sy);
				ObjEffect_SetAngle(obj,0,0,angle+90);
				ObjEffect_SetScale(obj,xscale,1);
				let color=255;
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,color,color,color);
				}
				xscale-=0.1;
				yield;
			}
			Obj_Delete(obj);
			
			task State
			{
				let v=30;
				let speed=0.2;
				angle=atan2(GetPlayerY-sy,GetPlayerX-sx);
				while(sx>minX+v&&sx<maxX-v&&sy>minY+v&&sy<maxY-v)
				{
					sx+=speed*cos(angle);
					sy+=speed*sin(angle);
					speed*=1.05;
					yield;
				}
				
				local
				{
					let ave=3;
					let v=10;
					let gra=13;
					let delay=5;
					let sx=minX;
					let lp=0;
					while(sx<maxX)
					{
						if(!(lp%ave)){gra=14;}
						else{gra=13;}
						let sy=[minY,maxY];
						let angle=[90,270];
						let rd=rand(-v,v);
						let speed=rand(0,2);
						ascent(a in 0..2)
						{
							CreateShotA(1,sx,sy[a],delay);
							SetShotDataA(1,0,speed,angle[a]+rd,0,-speed/100,0,gra);
							if(!(lp%ave)){SetShotDataA(1,100,NULL,rand(0,360),0,-0.01,-speed-1,gra);}
							else{SetShotDataA(1,100,NULL,NULL,0,-0.01,-speed,gra);}
							
							FireShot(1);
						}
						sx+=3;
						lp++;
					}
					let sy=minY;
					while(sy<maxY)
					{
						if(!(lp%ave)){gra=14;}
						else{gra=13;}
						let sx=[minX,maxX];
						let angle=[0,180];
						let rd=rand(-v,v);
						let speed=rand(0,2);
						ascent(a in 0..2)
						{
							CreateShotA(1,sx[a],sy,delay);
							SetShotDataA(1,0,speed,angle[a]+rd,0,-speed/100,0,gra);
							if(!(lp%ave)){SetShotDataA(1,100,NULL,rand(0,360),0,-0.01,-speed-1,gra);}
							else{SetShotDataA(1,100,NULL,NULL,0,-0.01,-speed,gra);}
							FireShot(1);
						}
						sy+=3;
						lp++;
					}
				}
				local
				{
					let way=48;
					
					let ag=[0,(360/way)/2];
					let speed=[1,0.8];
					let gra=[46,45];
					let delay=30;
					ascent(a in 0..2)
					{
						let angle=ag[a];
						while(angle<ag[a]+360)
						{
							CreateShot02(sx,sy,0,angle,speed[a]/90,speed[a],gra[a],delay);
							angle+=360/way;
						}
					}
				}
				wait(150);
				let rot=atan2(GetY-sy,GetX-sx);
				speed=0.2;
				while(GetGapLength(sx,sy,GetX,GetY)>=40)
				{
					rot=atan2(GetY-sy,GetX-sx);
					sx+=speed*cos(rot);
					sy+=speed*sin(rot);
					speed*=1.03;
					yield;
				}
				vanish=1;
			}
		}
	}
}