
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=480;
		SetLife(440);
		SetTimer(50);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetSpellCard("地天「兜跋毘沙門天」",42);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			local
			{
				let sx=cenX+(maxX-cenX+80)*r;
				let sy=cenY-60;
				SetMoveH(sx,sy,100);
				wait(100);
				loop(8)
				{
					yield;
					let wt=50;
					let sx=cenX-(maxX-cenX+80)*r;
					let sy=cenY-50+rand(-60,60);
					SetMove(sx,sy,wt);
					
					let px=GetPlayerX;
					let py=GetPlayerY+20;
					let w=1;
					let lg=0;
					loop(wt/w)
					{
						let p=atan2(py-GetY,px-GetX);
						let sx=GetX;
						let sy=GetY;
						let sl=GetGapLength(sx,sy,px,py);
						let speed=[sl/120,sl/130];
						let gra=115;
						let delay=5;
						ascent(s in 0..length(speed))
						{
							let angle=p;
							CreateShotA(1,sx,sy,delay);
							SetShotDataA(1,0,0,angle,0,0,0,gra);
							SetShotDataA(1,10+wt-lg,NULL,NULL,0,speed[s]/60,speed[s],NULL);
							FireShot(1);
						}
						if(!(lg%3))
						{
							let way=6;
							let speed=1.5;
							let angle=0;
							let gra=114;
							let delay=0;
							while(angle<360)
							{
								CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
								angle+=360/way;
							}
						}
						wait(w);
						lg+=w;
					}
					r=-r;
				}
				SetMoveH(cenX,cenY-120,80);
				wait(80);
			}
			local
			{
				SetAction(ACT_SHOT_A,60);
				let p=GetAngleToPlayer;
				let sp=0;
				loop(20)
				{
					let wide=70;
					let way=9;
					
					let speed=6-sp;
					let angleA=p;
					let gra=74;
					let delay=10;
					while(angleA<p+360)
					{
						let angleB=angleA-wide/2;
						while(angleB<=angleA+wide/2+1)
						{
							CreateShot02(GetX,GetY,0,angleB,speed/60,speed,gra,delay);
							angleB+=wide/(way-1);
						}
						angleA+=120;
					}
					wait(2);
					sp+=0.28;
				}
			}
			wait(100);
		}
		
		function SetMoveH(let x,let y,let wait)
		{
			SetMovePositionHermite(x,y,0,0,0,0,wait);
			SetAction(ACT_MOVE,wait);SetRoll(wait);
		}
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}