
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Utsuho_AnimeLib.txt";
	
	tex_enemy=filedir~"Utsuho_Main.png";
	tex_spellbg=filedir~"Utsuho_SpellBG.png";
	
	bg_rect=[0,0,800,600];
	
	let f_caution=GetCurrentScriptDirectory~"Utsuho_Caution.txt";
	
	@Initialize
	{
		point=450;
		SetLife(1060);
		SetTimer(57);
		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("防破「アンチバリア・メルトダウン」",56);
		CreateEnemyFromFile(f_caution,cenX,cenY,0,0,0);
		State;
		wait(120);
		task State
		{
			loop
			{
				loop
				{
					if(OnBomb){break;}
					yield;
				}
				loop(80)
				{
					let sx=GetPlayerX;let sy=GetPlayerY;
					let angle=rand(0,360);
					let speed=rand(0,4);
					BreakEffect(sx,sy,speed,angle,2);
				}
				loop
				{
					SetPlayerInvincibility(0);
					if(OnPlayerMissed){break;}
					yield;
				}
				while(OnBomb){yield;}
				yield;
			}
			
			task BreakEffect(let sx,let sy,let speed,let angle,let type)
			{
				let wt=120;
				
				let obj=SetEffectObject(tex_system,5);
				ObjEffect_SetRenderState(obj,ADD);
				SetEffectObjectRect(obj,160+(type%3)*16,0,172+(type%3)*16,16);
				let alpha=255;
				let scale=3;
				let rotx=rand(0,360);let roty=rand(0,360);let rotz=rand(0,360);
				let vx=rand(-10,10);let vy=rand(-10,10);let vz=rand(-10,10);
				while(!Obj_BeDeleted(obj))
				{
					Obj_SetPosition(obj,sx,sy);
					ObjEffect_SetAngle(obj,rotx,roty,rotz);
					ObjEffect_SetScale(obj,scale,scale);
					ascent(a in 0..4){ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);}
					
					sx+=speed*cos(angle);
					sy+=speed*sin(angle);
					alpha-=255/wt;
					scale-=3/wt;
					rotx+=vx;
					roty+=vy;
					rotz+=vz;
					
					if(alpha<0){Obj_Delete(obj);}
					yield;
				}
			}
		}
		let r=1;
		if(rand_int(0,1)){r=-r;}
		Sub;
		let lp=0;
		loop
		{
			local
			{
				let sx=cenX+rand(20,170)*r;
				let sy=minY-70;
				let speed=2.5;
				let angle=GetAngleToPlayer;
				if(angle>140){angle=140;}
				if(angle<50){angle=50;}
				let size=0.75;
				CreateShotFromScript("Sun",sx,sy,speed,angle,240,size);
				Explosion01(sx,sy,2,0.2,120);
			}
			wait(60);
			lp++;
			r=-r;
		}
		
		task Sub
		{
			wait(80);
			loop
			{
				SetAction(ACT_SUN,160);
				loop(5)
				{
					let way=36;
					
					let p=rand(0,360);
					let sy=GetY-35;
					let speed=2;
					let angle=p;
					let gra=43;
					let delay=10;
					while(angle<p+360)
					{
						SetObjectShot(GetX,sy,speed,angle,gra,delay);
						angle+=360/way;
					}
					wait(30);
				}
				wait(20);
				SetMovePositionHermite(cenX+rand(-60,60),minY+rand(110,140),0,0,0,0,100);
				SetAction(ACT_MOVE,100);
				wait(100);
			}
		}
		
		
		task SetObjectShot(let sx,let sy,let speed,let angle,let gra,let delay)
		{
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetX(obj,sx);
			Obj_SetY(obj,sy);
			Obj_SetSpeed(obj,speed);
			Obj_SetAngle(obj,angle);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			ObjShot_SetBombResist(obj,true);
			
			let count=0;
			while(!Obj_BeDeleted(obj))
			{
				count++;
				yield;
			}
		}
	}
	
}
#include_script".\Utsuho_SunShot.txt"
