
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Chen_AnimeLib.txt";
	
	tex_enemy=filedir~"Chen_Main.png";
	tex_spellbg=filedir~"Chen_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=420;
		SetLife(500);
		SetTimer(50);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+150,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetRoll(100);
		SetSpellCard("怪炎「火車落の袈裟」",36);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			SetAction(ACT_SHOT_B,100);
			local
			{
				let p=90+60*r;
				loop(30)
				{
					let speed=0.1;
					let angle=p;
					let gra=41;
					let delay=10;
					ObjectShot(GetX,GetY,speed,angle,gra,delay);
					p+=8*r;
					wait(2);
				}
			}
			wait(80);
			let p=atan2(GetPlayerY-GetY,GetPlayerX-GetX);
			let mx=GetGapX(GetX,650,p);
			let my=GetGapY(GetY,650,p);
			let wt=180;
			SetTargeting(GetPlayerX,GetPlayerY,0.5,150,1);
			SetMovePositionHermite(mx,my,1500,p+180,0,0,wt);
			SetAction(ACT_MOVE,wt);
			SetRoll(wt);
			let L=20;
			let i=rand(0,360);
			loop(L)
			{
				let way=12;
				let speed=1.5;
				let angle=i;
				let gra=113;
				let delay=10;
				while(angle<i+360)
				{
					let v=30;
					let sx=GetX+v*cos(angle);
					let sy=GetY+v*sin(angle);
					CreateShot02(sx,sy,0,angle+180,speed/100,speed,gra,delay);
					
					if(GetY<400)
					{
						v=20;
						sx=GetX+v*cos(angle);
						sy=GetY+v*sin(angle);
						let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
						let graB=121;
						CreateShot02(sx,sy,0,p,speed/100,speed,graB,delay);
					}
					angle+=360/way;
				}
				i+=(360/way)/2*r;
				wait(floor(wt/L));
			}
			wait(100);
			SetX(cenX+(cenX-GetX));
			SetY(minY-280);
			let wt=180;
			SetMovePositionHermite(cenX,minY+150,500,p+180,0,0,wt);
			SetAction(ACT_MOVE,wt);
			SetRoll(wt);
			wait(220);
			r=-r;
		}
		
		task ObjectShot(let x,let y,let spd,let ag,let gra,let delay)
		{
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetPosition(obj,x,y);
			Obj_SetSpeed(obj,spd);
			Obj_SetAngle(obj,ag);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			ObjShot_ToItem(obj,false);
			Obj_SetAutoDelete(obj,false);
			ObjShot_SetBombResist(obj,true);
			while(x>minX&&x<maxX&&y>minY&&y<maxY)
			{
				x=Obj_GetX(obj);
				y=Obj_GetY(obj);
				
				Obj_SetSpeed(obj,spd);
				spd*=1.04;
				yield;
			}
			local
			{
				let way=40;
				let p=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
				let speed=1;
				let angle=p;
				let gra=65;
				let delay=10;
				while(angle<p+360)
				{
					CreateShot02(x,y,0,angle,speed/200,speed,gra,delay);
					angle+=360/way;
				}
			}
			Obj_Delete(obj);
		}
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}