
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=540;
		SetLife(1540);
		SetTimer(71);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	

	
	
	
	
	task MainThread_Standard{}
	task MainThread_Advanced{}
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+150,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("冥審「五道転輪の最終審判」",90);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		JudgmentLaser;
		wait(40);
		local
		{
			let sx=[cenX+170,cenX-170,cenX+80,cenX-80];
			let sy=[minY+180,minY+180,minY+40,minY+40];
			
			let wt=0;
			ascent(a in 0..4)
			{
				Sub(sx[a],sy[a],r,wt);
				r=-r;
				wt+=70;
			}
		}
		wait(80);
		let i=rand(0,360);
		loop
		{
			SetAction(ACT_SHOT_B,300);
			loop(50)
			{
				let ip=1;
				let L=4;
				loop(L)
				{
					local
					{
						let way=2;
						let speed=1.5;
						let angle=i;
						let gra=70;
						let delay=10;
						while(angle<i+360)
						{
							let v=35;
							let sx=GetX+v*cos(angle);
							let sy=GetY+v*sin(angle);
							SetShot(sx,sy,speed,angle,gra,delay);
							angle+=360/way;
						}
					}
					i+=ip*r;
					wait(1);
				}
				loop(L)
				{
					i+=ip*r;
					wait(1);
				}
			}
			
			let wt=100;
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(140,180),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
			JudgmentLaser;
			wait(100);
		}
		
		
		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 ag=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
						let spd=speed*2;
						if(spd<1){spd=1;}
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spd,ag,251,0);
						judgflg=true;
					}
				}
				if(speed<=maxspeed){speed+=maxspeed/60;}
				yield;
			}
		}
		
		task Sub(let sx,let sy,let r,let wt)
		{
			Judgment(sx,sy,60*77);
			wait(90+wt);
			
			let i=0;
			loop
			{
				let way=6;
				let wide=70;
				
				local
				{
					let speed=[2.5,2.6,2.7,2.8,2.9];
					let angle=i-wide/2;
					let gra=251;
					let delay=0;
					while(angle<=i+wide/2+1)
					{
						let max=1;
						if(GetEnemyLife<1000){max=2;}
						if(GetEnemyLife<600){max=3;}
						if(GetEnemyLife<250){max=5;}
						ascent(a in 0..max)
						{
							CreateShot02(sx,sy,0,angle,speed[a]/100,speed[a],gra,delay);
						}
						angle+=wide/(way-1);
					}
				}
				i+=19*r;
				wait(16);
			}
		}
		
		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;
			}
		}
		
		task JudgmentLaser
		{
			let p=GetAngleToPlayer;
			local
			{
				let wide=0;
				while(wide<=150)
				{
					let sx=GetX;
					let sy=GetY-15;
					let leng=1000;
					let width=14;
					let del=160;
					let delay=40;
					if(wide==0)
					{
						let ag=[p-90,p+90];
						let gra=[41,46];
						ascent(a in 0..2)
						{
							SetLaserObject(sx,sy,leng,width,ag[a],255,gra[a],delay,del);
						}
					}
					else
					{
						let ag=[p-90,p+90];
						let gra=[41,46];
						ascent(a in 0..2)
						{
							let angle=ag[a]-wide/2;
							while(angle<=ag[a]+wide/2+1)
							{
								SetLaserObject(sx,sy,leng,width,angle,255,gra[a],delay,del);
								angle+=wide;
							}
						}
					}
					wide+=30;
					wait(2);
				}
				let leng=0;
				while(leng<500)
				{
					let angle=p;
					let width=50;
					let delay=10;
					let gra=47;
					let del=3;
					SetLaserObject(GetX,GetY,leng,width,angle,255,gra,delay,del);
					yield;
					leng+=10;
				}
				loop(50)
				{
					let angle=p;
					let width=80;
					let delay=0;
					let gra=47;
					let del=10;
					SetLaserObject(GetX,GetY,leng,width,angle,192,gra,delay,del);
					wait(2);
					leng+=10;
				}
			}
		}
	}
	
}