
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Nue_AnimeLib.txt";
	
	tex_enemy=filedir~"Nue_Main.png";
	tex_spellbg=filedir~"Nue_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=480;
		SetLife(1500);
		SetTimer(77);
		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+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("正体不明「未確認幻想飛行円盤」",32);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		SetAction(ACT_SHOT_A,60*77);
		let wt=130;
		let lifelimit=700;
		loop
		{
			local
			{
				let sx=[GetX+120,GetX-120];
				let sy=GetY+20;
				ascent(a in 0..2)
				{
					let gra=135;
					if(GetEnemyLife<lifelimit){gra=129;}
					let speed=0.8;
					let angle=atan2(GetPlayerY-sy,GetPlayerX-GetX);
					let rot=0.3*r;
					SetShot(sx[a],sy,speed,angle,rot,gra);
					r=-r;
				}
			}
	//		wait(wt);
			local
			{
				let sx=[GetX+70,GetX-70];
				let sy=GetY-80;
				ascent(a in 0..2)
				{
					let gra=135;
					if(GetEnemyLife<lifelimit){gra=129;}
					let speed=0.7;
					let angle=atan2(GetPlayerY-sy,GetPlayerX-GetX);
					let rot=-0.3*r;
					SetShot(sx[a],sy,speed,angle,rot,gra);
					r=-r;
				}
			}
			if(GetEnemyLife<lifelimit)
			{
				local
				{
					let sx=[GetX+160,GetX-160];
					let sy=GetY-120;
					ascent(a in 0..2)
					{
						let gra=129;
						let speed=0.6;
						let angle=atan2(GetPlayerY-sy,GetPlayerX-GetX);
						let rot=0.3*r;
						SetShot(sx[a],sy,speed,angle,rot,gra);
						r=-r;
					}
				}
				wt=90;
			}
			wait(wt*2);
			r=-r;
		}
		
		task SetShot(let bx,let by,let spd,let ag,let ip,let gra)
		{
			let rot=0;
			let leng=1;
			let way=18;
			let endflg=false;
			State;
			
			local
			{
				let delay=20;
				ascent(a in 0..way)
				{
					ShotObject((360/way)*a,gra,delay);
				}
			}
			
			task State
			{
				wait(20);
				loop
				{
					if(bx<minX-leng||bx>maxX+leng||by<minY-leng||by>maxY+leng){break;}
					bx+=spd*cos(ag);
					by+=spd*sin(ag);
					rot+=ip;
					if(leng<300){leng+=0.7;}
					yield;
				}
				endflg=true;
			}
			
			task ShotObject(
			let i,
			let gra,
			let delay)
			{
				let flame=0;
				let o=Obj_Create(OBJ_SHOT);
				Obj_SetSpeed(o,0);
				Obj_SetAngle(o,0);
				ObjShot_SetGraphic(o,gra);
				ObjShot_SetDelay(o,delay);
				ObjShot_SetBombResist(o,true);
				Obj_SetAutoDelete(o,false);
				
				while(!Obj_BeDeleted(o))
				{
					Obj_SetX(o,bx+leng*cos(i+rot));
					Obj_SetY(o,by+leng*sin(i+rot));
					Obj_SetAngle(o,atan2(by-Obj_GetY(o),bx-Obj_GetX(o))+90);
					/*
					if(leng>40)
					{
						let lg=(2*3.15*leng)/way;
						let angle=Obj_GetAngle(o)-(180/way);
						let width=15;
						let gra=191;
						SetLaserObject(Obj_GetX(o),Obj_GetY(o),lg,width,angle,96,gra,100,1);
					}
					*/
					if(endflg){Obj_Delete(o);}
					flame++;
					yield;
				}
			}
		}
	}
	
}