
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Ran_AnimeLib.txt";
	
	tex_enemy=filedir~"Ran_Main.png";
	tex_spellbg=filedir~"Ran_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=420;
		SetLife(1000);
		SetTimer(50);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard{}
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetRoll(100);
		SetSpellCard("金気「魔王天王三年塞がり」",31);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		Sub;
		wait(100);
		loop
		{
			let lp=0;
			loop(3)
			{
				let way=1+lp%2;
				let wide=70;
				
				let p=GetAngleToPlayer;
				let speed=3;
				let gra=51;
				let delay=20;
				if(way==1)
				{
					let angle=p;
					SpecialShot(GetX,GetY,speed,angle,gra,delay);
				}
				else
				{
					let angle=p-wide/2;
					while(angle<=p+wide/2+1)
					{
						SpecialShot(GetX,GetY,speed,angle,gra,delay);
						angle+=wide/(way-1);
					}
				}
				lp++;
				wait(80);
			}
			SetMovePositionHermite(cenX+rand(-80,80),minY+rand(110,140),0,0,0,0,200);
			SetAction(ACT_MOVE,200);
			SetRoll(200);
		}
		
		task SpecialShot(let sx,let sy,let speed,let angle,let gra,let delay)
		{
			let flame=0;
			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);
			
			while(!Obj_BeDeleted(obj))
			{
				DeleteEnemyShotImmediatelyInCircle(SHOT,Obj_GetX(obj),Obj_GetY(obj),32);
				yield;
			}
		}
		
		task Sub
		{
			loop
			{
				ascent(a in 0..4)
				{
					SetShot(a);
				}
			}
			function SetShot(let type)
			{
				let L=60;
				let st_x=[maxX,maxX,minX,minX];
				let st_y=[minY,maxY,maxY,minY];
				let vx=0;
				let vy=0;
				let lmax=maxY-minY;
				if(type==1||type==3)
				{
					lmax=maxX-minX;
					vx=lmax/L;
				}
				else{vy=lmax/L;}
				
				if(type==1||type==2)
				{
					vx=-vx;
					vy=-vy;
				}
				let sx=st_x[type];
				let sy=st_y[type];
				loop(L)
				{
					let angle=[180,270,0,90];
					let speed=[0.8,0.5];
					let gra=135;
					let delay=15;
					ascent(a in 0..length(speed))
					{
						CreateShot02(sx,sy,0,angle[type],speed[a]/100,speed[a],gra,delay);
					}
					sx+=vx;
					sy+=vy;
					wait(1);
				}
			}
		}
	}
	
	task MainThread_Unlimited{}
	
}