
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Daiyousei_AnimeLib.txt";
	
	tex_enemy=filedir~"Daiyousei_Main.png";
	tex_spellbg=filedir~"Daiyousei_SpellBG.png";
	
	bg_rect=[0,0,800,600];
	
	@Initialize
	{
		point=420;
		SetLife(660);
		SetTimer(27);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	

	
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("風花「クライスオブグラスフラワー」",0);
		wait(120);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			let p=GetAngleToPlayer+rand(-10,10);
			let i=0;
			let length=40;
			SetAction(ACT_SHOT_A,50);
			loop(30)
			{
				let j=0;
				let speed=5;
				while(speed>=0.8)
				{
					let ag=[p-150+i+j,p+150-i-j];
					let gra=[117,118];
					let delay=[10,10];
					ascent(a in 0..2)
					{
						let sx=GetX()+length*cos(ag[a]);
						let sy=GetY()+length*sin(ag[a]);
						let angle=ag[a];
						CreateShot01(sx,sy,speed,angle,gra[a],delay[a]);
					
					}
					j+=(1+lp/4)*r;
					speed=speed/1.25;
				}
				wait(3);
				i+=10*r;
			}
			lp++;
			loop(1)
			{
				let random=rand(0,360);
				let way=48;
				let speed=2.5;
				let angle=random;
				let gra=32;
				let delay=10;
				while(angle<random+360)
				{
					CreateShot01(GetX,GetY,speed,angle,gra,delay);
					angle+=360/way;
				}
			}
			r=-r;
			wait(20);
			SetMove(cenX+rand(-40,40),minY+rand(110,140),90);
			wait(90);
		}
	}
	
	
	
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("風霜「クライスオブウィンド」",1);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			let p=GetAngleToPlayer+rand(-10,10);
			let i=0;
			let length=40;
			SetAction(ACT_SHOT_A,50);
			loop(2)
			{
				loop(30)
				{
					let ag=p-(150*r)+i;
					let sx=GetX+length*cos(ag);
					let sy=GetY+length*sin(ag);
					let speed=3;
					let angle=ag;
					let gra=[68,69];
					let delay=10;
					let j=0;
					while(speed>=0.6)
					{
						CreateShot01(sx,sy,speed,angle-j,gra[lp%2],delay);
						speed=speed/1.3;
						j+=(2+lp)*r;
					}
					wait(2);
					i+=10*r;
				}
//				wait(20);
				lp++;
				r=-r;
			}
			local
			{
				SetAction(ACT_SHOT_B,90);
				let wide=[100,2];
				let way=6;
				let p=GetAngleToPlayer;
				
				let speed=3;
				let angle=p-wide[0]/2;
				let limit=45;
				let sch=[-3,3];
				let gra=[12,84];
				let delay=20;
				
				while(angle<=p+wide[0]/2)
				{
					ascent(a in 0..2)
					{
						CreateShotA(1,GetX,GetY,delay);
						SetShotDataA(1,0,speed,angle,sch[a],0,0,gra[0]);
						SetShotDataA(1,limit,NULL,NULL,0,-speed/20,-speed*3,gra[0]);
						let i=limit+20;
						while(i<180)
						{
							let ag=angle+sch[a]*limit;
							let angleB=ag-wide[1]/2;
							while(angleB<=ag+wide[1]/2)
							{
								CreateShotA(2,0,0,10);
								SetShotDataA(2,0,-speed,angleB,0,speed/20,speed*4,gra[1]);
								AddShot(i,1,2,0);
								angleB+=wide[1]/2;
							}
							i+=2;
						}
						FireShot(1);
					}
					angle+=wide[0]/(way-1);
				}
			}
			r=-r;
			wait(120);
			SetMove(cenX+rand(-100,100),minY+rand(110,140),120);
			wait(160);
		}
	}
	
	
	task MainThread_Unlimited
	{
		yield;
		SetShotAutoDeleteClip(32,120,32,32);
		SetMovePositionHermite(cenX,minY+80,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("結晶「クライスオブドーンクリスタル」",2);
		wait(120);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			SetAction(ACT_SHOT_B,240);
			let sp=0;
			let p=0;
			loop(5)
			{
				let way=4;
				let angle=p;
				while(angle<p+360)
				{
					let speed=[1,2,3,4,5];
					let sch=3*r;
					let gra=32;
					let delay=0;
					ObjectShot(GetX,GetY,speed[sp],angle,sch,gra,delay);
					angle+=360/way;
				}
				sp++;
				wait(30);
				r=-r;
			}
			wait(140);
			SetMove(cenX+rand(-60,60),minY+rand(90,120),90);
			wait(90);
			lp++;
			r=-r;
		}
		
		
		task ObjectShot(let x,let y,let spd,let ag,let sch,let gra,let delay)
		{
			let obj=Obj_Create(OBJ_SHOT);
			Obj_SetPosition(obj,x,y);
			Obj_SetAngle(obj,ag);
			ObjShot_SetGraphic(obj,gra);
			ObjShot_SetDelay(obj,delay);
			ObjShot_ToItem(obj,false);
			Obj_SetAutoDelete(obj,false);
			ObjShot_SetBombResist(obj,true);
			let leng=0;
			let count=0;
			let limit=[100,240];
			while(!Obj_BeDeleted(obj))
			{
				let sx=x+leng*cos(ag);
				let sy=y+leng*sin(ag);
				Obj_SetPosition(obj,sx,sy);
				Obj_SetAngle(obj,ag);
				
				if(count==limit[0]){SetShot(obj);}
				if(count>=limit[1]){Obj_Delete(obj);}
				
				leng+=spd;
				spd/=1.02;
				ag+=sch;
				count++;
				yield;
			}
			
			task SetShot(let obj)
			{
				let r=1;
				if(sch>0){r=-r;}
				let lp=0;
				while(!Obj_BeDeleted(obj))
				{
					let speed=[2,2.1,2.2,4.2,4.4,4.6];
					let angle=Obj_GetAngle(obj)+170*r;
					let gra=85;
					let delay=10;
					CreateShot02(Obj_GetX(obj),Obj_GetY(obj),0,angle,speed[lp%length(speed)]/20,speed[lp%length(speed)],gra,delay);
					lp++;
					wait(1);
				}
			}
		}
	}
	
}