
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Suika_AnimeLib.txt";
	
	tex_enemy=filedir~"Suika_Main.png";
	tex_spellbg=filedir~"Suika_SpellBG.png";
	
	bg_rect=[0,0,512,768];
	
	@Initialize
	{
		point=420;
		SetLife(900);
		SetTimer(55);
		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("開戦「羅刹国の狼煙」",79);
		wait(100);
		local
		{
			local
			{
				let speed=5;
				let angle=90;
				let gra=56;
				let delay=0;
				Sub(SetBombResistShot(GetX,GetY,speed,angle,gra,delay));
			}
			task Sub(let obj)
			{
				while(!Obj_BeDeleted(obj))
				{
					let v=10;
					let sx=Obj_GetX(obj)+rand(-v,v);
					let sy=Obj_GetY(obj)+rand(-v,v);
					let gra=8;
					let delay=30;
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					SetDelayEffect(sx,sy,gra,delay);
					yield;
				}
				let sx=Obj_GetX(obj);
				let sy=Obj_GetY(obj);
				wait(20);
				local
				{
					let way=24;
					let p=rand(0,360);
					let angle=p;
					let gra=48;
					let delay=10;
					while(angle<p+360)
					{
						let speed=2.5;
						while(speed>=1)
						{
							CreateShot02(sx,sy,0,angle,speed/60,speed,gra,delay);
							speed/=1.2;
						}
						angle+=360/way;
					}
				}
			}
		}
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			local
			{
				let wide=240;
				let way=31;
				let p=GetAngleToPlayer+180;
				let speed=3;
				let gvspeed=0.04;
				let gvangle=p+180;
				let angle=p-wide/2;
				let gra=145;
				let delay=10;
				while(angle<=p+wide/2+1)
				{
					GravityShot(GetX,GetY,speed,angle,gvspeed,gvangle,gra,delay);
					angle+=wide/(way-1);
				}
			}
			lp++;
			if(lp%12==0)
			{
				let wt=120;
				SetMovePositionHermite(cenX+rand(-80,80),minY+rand(110,140),0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
			}
			if(lp%6==0){SubShot;}
			wait(30);
		}
		
		task SubShot
		{
			local
			{
				let speed=2;
				let angle=GetAngleToPlayer;
				let gra=56;
				let delay=0;
				Sub(SetBombResistShot(GetX,GetY,speed,angle,gra,delay));
			}
			task Sub(let obj)
			{
				while(!Obj_BeDeleted(obj))
				{
					let v=10;
					let sx=Obj_GetX(obj)+rand(-v,v);
					let sy=Obj_GetY(obj)+rand(-v,v);
					let gra=8;
					let delay=30;
					if(sx<minX||sx>maxX||sy<minY||sy>maxY){break;}
					SetDelayEffect(sx,sy,gra,delay);
					yield;
				}
				let sx=Obj_GetX(obj);
				let sy=Obj_GetY(obj);
				wait(20);
				local
				{
					let way=4;
					let wide=30;
					let p=0;
					let ag=p;
					let gra=48;
					let delay=10;
					while(ag<p+360)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							let speed=4;
							while(speed>=1.5)
							{
								CreateShot02(sx,sy,0,angle,speed/60,speed,gra,delay);
								speed/=1.2;
							}
							angle+=2;
						}
						ag+=360/way;
					}
				}
			}
		}
	}
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+180,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("火魂「怨念籠められし叢原火」",80);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		SetAction(ACT_SHOT_B,100);
		local
		{
			SubShot(GetAngleToPlayer);
			wait(90);
			SubShot(GetAngleToPlayer+180);
		}
		wait(100);
		loop
		{
			loop(4)
			{
				let px=GetPlayerX;
				let py=GetPlayerY;
				let ag=GetAngleToPlayer;
				let gra=241;
				let delay=10;
				while(ag<GetAngleToPlayer+360)
				{
					let v=[25,60];
					ascent(a in 0..2)
					{
						let sx=GetX+v[a]*cos(ag);
						let sy=GetY+v[a]*sin(ag);
						let p=atan2(py-sy,px-sx);
						
						let speed=3-2*cos(ag-GetAngleToPlayer);
						let angle=p;
						
						CreateShot01(sx,sy,speed,angle,gra,delay);
					}
					ag+=18;
				}
				wait(12);
			}
			let wt=120;
			SetMovePositionHermite(cenX+rand(-60,60),minY+rand(160,190),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			wait(wt);
			wait(60);
		}
		
		task SubShot(let ag)
		{
			local
			{
				let speed=3.5;
				let angle=ag;
				let gra=49;
				let delay=0;
				Sub(SetBombResistShot(GetX,GetY,speed,angle,gra,delay));
			}
			task Sub(let obj)
			{
				Obj_SetAutoDelete(obj,false);
				let speed=Obj_GetSpeed(obj);
				let angle=ag;
				let lp=1;
				while(!Obj_BeDeleted(obj))
				{
					let px=GetPlayerX;
					let py=GetPlayerY;
					let sx=Obj_GetX(obj);
					let sy=Obj_GetY(obj);
					let gra=1;
					let delay=30;
					local
					{
						let toAngle=atan2(py-Obj_GetY(obj),px-Obj_GetX(obj));
						let dangle=6-speed;
						let ret=toAngle-angle;
						if((ret>0&&ret<=180)||(ret<0&&ret<=-180)){angle+=dangle;}
						else if((ret>0&&ret>180)||(ret<0&&ret>-180)){angle+=-dangle;}
						if(angle>=180){angle+=-360;}
						if(angle<-180){angle+=360;}
						Obj_SetAngle(obj,angle);
					}
					Obj_SetSpeed(obj,speed);
					if(lp%2){SetDelayEffect(sx,sy,gra,delay);}
					if(!(lp%60))
					{
						SetShot(sx,sy);
					}
					speed=3-2.5*cos(lp*2);
					lp++;
					yield;
				}
			}
			
			task SetShot(let sx,let sy)
			{
				if(sx<minX||sx>maxX||sy<minY||sy>maxY){return;}
				loop(90)
				{
					let gra=1;
					let delay=6;
					SetDelayEffect(sx,sy,gra,delay);
					yield;
				}
				local
				{
					let p=atan2(GetPlayerY-sy,GetPlayerX-sx);
					let way=3;
					let wide=15;
					let speed=2;
					let ag=p;
					let gra=25;
					let delay=20;
					while(ag<p+360)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+1)
						{
							CreateShot02(sx,sy,0,angle,speed/100,speed,gra,delay);
							angle+=3;
						}
						ag+=360/way;
					}
				}
			}
		}
	}
	
	
	task MainThread_Unlimited{}
	
}