
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=510;
		SetLife(1000);
		SetTimer(62);
		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+100,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("릗렦걏뼖뭷덦묈쀻딏걐",87);
		wait(120);
		let r=-1;
//		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			SetAction(ACT_SHOT_A,120);
			local
			{
				loop(3)
				{
					let sx=cenX+rand(-120,120);
					let sy=cenY+rand(-70,80);
					let wt=240;
					Judgment(sx,sy,wt);
				}
			}
			wait(60);
			let wide=150;
			loop(2)
			{
				let p=GetAngleToPlayer;
				let speed=2;
				let angle=p-wide/2;
				while(angle<=p+wide/2+1)
				{
					Fam(GetX,GetY,speed,angle,r);
					angle+=wide;
					r=-r;
				}
				wide+=70;
				r=-r;
				wait(60);
			}
			wait(50);
			local
			{
				let ag=rand(0,360);
				let way=36;
				let angle=ag;
				let gra=251;
				let delay=10;
				while(angle<ag+360)
				{
					let speed=4.5;
					while(speed>=1)
					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						//SetShot(GetX,GetY,speed,angle,gra,delay);
						speed/=1.3;
					}
					angle+=360/way;
				}
			}
			SetMovePositionHermite(cenX+rand(-70,70),minY+rand(90,120),0,0,0,0,120);
			SetAction(ACT_MOVE,120);
			wait(120);
		}
		
		task Fam(let sx,let sy,let spd,let ag,let r)
		{
			let i=rand(0,360);
			let lp=0;
			loop
			{
				sx+=spd*cos(ag);
				sy+=spd*sin(ag);
				let v=24;
				if(sx<minX-v||sx>maxX+v||sy<minY-v||sy>maxY+v){break;}
				
				local
				{
					let way=2;
					let speed=[1.5,1.2];
					let angle=i;
					let gra=[70,6];
					let delay=6;
					while(angle<i+360)
					{
						SetShot(sx,sy,speed[lp%length(speed)],angle,gra[lp%length(gra)],delay);
						angle+=360/way;
					}
				}
				i+=16*r;
			//	lp++;
				wait(1);
			}
		}
		
		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*1.5;
						if(spd<1){spd=1;}
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),spd,angle,251,0);
						judgflg=true;
					}
				}
				if(speed<=maxspeed){speed+=maxspeed/60;}
				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;
			}
		}
	}
	
}