
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=420;
		SetLife(840);
		SetTimer(55);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	
	task MainThread_Unlimited
	{
		yield;
		SetShotAutoDeleteClip(120,120,120,120);
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("仏界「五趣六道の走馬灯」",78);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			let px=GetPlayerX;
			let py=GetPlayerY;
			SetTargeting(px,py,0.5,90,0);
			Judgment(px,py,600);
			local
			{
				let rp=1.5*r;
				let way=5;
				ascent(a in 0..way)
				{
					Sub(px,py,(360/way)*a,rp);
				}
			}
			wait(360);
			r=-r;
		}
		
		task Sub(let bx,let by,let rot,let rp)
		{
			let lp=0;
			let leng=0;
			while(leng<180)
			{
				let sx=bx+leng*cos(rot);
				let sy=by+leng*sin(rot);
				SetDelayEffect(sx,sy,6,12);
				if(lp%2&&leng>120)
				{
					let p=atan2(by-sy,bx-sx);
					let speed=1;
					let angle=p;
					let gra=70;
					let delay=10;
					SetShot(sx,sy,speed,angle,gra,delay);
				}
				lp++;
				leng+=1.75;
				rot+=rp;
				yield;
			}
			
			while(absolute(rp)>0.1)
			{
				let sx=bx+leng*cos(rot);
				let sy=by+leng*sin(rot);
				SetDelayEffect(sx,sy,6,12);
				rot+=rp;
				rp*=0.95;
				yield;
			}
			
			let sx=bx+leng*cos(rot);
			let sy=by+leng*sin(rot);
			let p=rand(0,360);
			local
			{
				let way=18;
				let speed=1;
				let angle=p;
				let gra=31;
				let delay=10;
				while(angle<p+360)
				{
					SetShot(sx,sy,speed,angle,gra,delay);
					angle+=360/way;
				}
			}
			let p=GetAngleToPlayer;
			local
			{
				let way=18;
				let speed=6;
				let angle=p;
				let gra=55;
				let delay=0;
				while(angle<p+360)
				{
					SetShot2(GetX,GetY,speed,angle,gra,delay);
					angle+=360/way;
				}
			}
		}
		
		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),40,253))
					{
						let spd=speed*2;
						if(spd<1){spd=1;}
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spd,angle,251,0);
						judgflg=true;
					}
				}
				if(speed<=maxspeed){speed+=maxspeed/120;}
				yield;
			}
		}
		
		task SetShot2(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),40,253))
					{
						loop(15)
						{
							let ag=angle+rand(-10,10);
							let spd=speed/2;
							if(spd<1){spd=1;}
							spd=rand(spd-spd/2,spd+spd/2);
							CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spd,ag,251,0);
						}
						judgflg=true;
					}
				}
				if(speed<=maxspeed){speed+=maxspeed/200;}
				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;
			}
		}
	}
	
}