
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Eiki_AnimeLib.txt";
	
	tex_enemy=filedir~"Eiki_Main.png";
	tex_spellbg=filedir~"Eiki_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	@Initialize
	{
		point=450;
		SetLife(1000);
		SetTimer(59);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	

	
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	
	task MainThread_Unlimited
	{
		yield;
		SetShotAutoDeleteClip(64,64,64,64);
		SetMovePositionHermite(cenX,minY+100,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("中有「陰陽の揺らぐ途」",81);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let i=0;
		let ip=0;
		SetAction(ACT_SHOT_B,60*60);
		Sub;
		loop
		{
			local
			{
				let way=6;
				let speed=4.5;
				let angle=i;
				let gra=63;
				let delay=8;
				while(angle<i+360)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					SetShot(sx,sy,speed,angle,gra,delay);
					angle+=360/way;
				}
			}
			local
			{
				let p=-i/2;
				let way=4;
				let speed=1.5;
				let angle=p;
				let gra=64;
				let delay=15;
				while(angle<p+360)
				{
					let v=360;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					SetShot(sx,sy,speed,angle+180*r,gra,delay);
					angle+=360/way;
				}
			}
			if(ip<1.5){ip+=0.03;}
			i+=ip*r;
			wait(4);
		}
		
		task Sub
		{
			wait(60);
			let p=rand(0,360);
			loop
			{
				local
				{
					let way=12;
					
					let lp=0;
					let angle=p;
					while(angle<p+360)
					{
						let v=[150,270];
						let sx=GetX+v[lp%2]*cos(angle);
						let sy=GetY+v[lp%2]*sin(angle);
						Judgment(sx,sy,200);
						angle+=360/way;
						lp++;
					}
					p+=(360/way)/2*r;
				}
				wait(200);
			}
		}
		
		task SetShot(let sx,let sy,let maxspeed,let angle,let gra,let delay)
		{
			let judgflg=false;
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetX(obj,sx);
			Obj_SetY(obj,sy);
			Obj_SetSpeed(obj,0);
			Obj_SetAngle(obj,angle);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			
			let speed=0;
			while(!Obj_BeDeleted(obj))
			{
				
				Obj_SetSpeed(obj,speed);
				
				if(!judgflg)
				{
					if(GetEnemyShotCountEx(Obj_GetX(obj),Obj_GetY(obj),32,253))
					{
						let ag=angle+rand(-8,8);
						let spd=0.5;
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spd,ag,251,0);
						judgflg=true;
						Obj_Delete(obj);
					}
				}
				if(speed<=maxspeed){speed+=maxspeed/120;}
				yield;
			}
		}
		
		task Judgment(let sx,let sy,let wt)
		{
			let count=0;
			let alpha=5;
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetX(obj,sx);
			Obj_SetY(obj,sy);
			Obj_SetSpeed(obj,0);
			Obj_SetAngle(obj,0);
			ObjShot_SetGraphic(obj,253);
			ObjShot_SetDelay(obj,0);
			Obj_SetCollisionToPlayer(obj,false);
			ObjShot_SetBombResist(obj,true);
			
			while(!Obj_BeDeleted(obj))
			{
				Obj_SetAlpha(obj,alpha);
				if(count>wt)
				{
					alpha-=6;
					if(alpha<5){Obj_Delete(obj);}
				}
				else
				{
					if(alpha<192){alpha+=6;}
				}
				count++;
				yield;
			}
		}
	}
	
	
}