
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Yuka_AnimeLib.txt";
	
	tex_enemy=filedir~"Yuka_Main.png";
	tex_spellbg=filedir~"Yuka_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	@Initialize
	{
		point=300;
		SetLife(800);
		SetTimer(47);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+80,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("燐華「廣野に散り逝く四花」",18);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			SetAction(ACT_SHOT_B,100);
			let sp=0;
			loop(2)
			{
				let way=4;
				let speed=4+sp;
				let p=GetAngleToPlayer+45;
				ascent(a in 0..way)
				{
					let angle=p;
					while(angle<p+360)
					{
						SetShot(GetX,GetY+20,speed,angle,191,r);
						angle+=360/way;
					}
				}
				wait(20);
				sp+=-2;
				r=-r;
			}
			wait(180);
			SetAction(ACT_SHOT_A,90);
			wait(90);
			SetMove(cenX+rand(-100,100),minY+rand(90,100),80);
			wait(80);
			r=-r;
			task SetShot(let sx,let sy,let shotspeed,let shotangle,let shotgra,let r)
			{
				let flg=0;
				Sub;
				let count=0;
				let limit=180;
				loop
				{
					let del=50;
					let size=20;
					if(count%2){SetLaserEffect(sx,sy,size*(shotspeed/3),size,shotangle,shotgra,del);}
					sx+=shotspeed*cos(shotangle);
					sy+=shotspeed*sin(shotangle);
					shotangle+=360/limit*r;
					if(count>=limit)
					{
						if(sx<=minX||sx>=maxX||sy<=minY||sy>=maxY){break;}
						shotspeed+=0.05;
					}
					count++;
					yield;
				}
				flg=1;
				task Sub
				{
					while(!flg)
					{
						let col=(shotgra-1)%8;
						let speed=[2.9,3];
						let angle=shotangle+180;
						let gra=81+col;
						let delay=0;
						ascent(a in 0..length(speed))
						{
							CreateShot02(sx,sy,0,angle,speed[a]/240,speed[a],gra,delay);
						}
						wait(5);
					}
				}
			}
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+90,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("燐華「廣野に咲く四花」",19);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			let px=GetPlayerX;
			let py=GetPlayerY;
			let p=GetAngleToPlayer;
			SetAction(ACT_SHOT_B,100);
			let sp=0;
			let lp=0;
			loop(2)
			{
				let way=4;
				let speed=5+sp;
				let gra=[41,46];
				ascent(a in 0..way)
				{
					let angle=p;
					while(angle<p+360)
					{
						SetShot(GetX,GetY+20,speed,angle,gra[lp%length(gra)],r);
						angle+=360/way;
					}
				}
				wait(60);
				sp+=-3;
				lp++;
				r=-r;
			}
			wait(120);
			SetTargeting(px,py,0.5,120,0);
			wait(60);
			SetAction(ACT_SHOT_A,90);
			wait(90);
			SetMove(cenX+rand(-100,100),minY+rand(90,100),140);
			wait(220);
			r=-r;
			task SetShot(let sx,let sy,let shotspeed,let shotangle,let shotgra,let r)
			{
				let flg=0;
				let count=0;
				let limit=300;
				let ag=4.5;
				Sub;
				loop
				{
					let del=40;
					let size=30;
					if(count%2){SetLaserEffect(sx,sy,size*(shotspeed/3),size,shotangle,shotgra,del);}
					sx+=shotspeed*cos(shotangle);
					sy+=shotspeed*sin(shotangle);
					if(count>=limit)
					{
						if(sx<=minX||sx>=maxX||sy<=minY||sy>=maxY){break;}
						shotspeed+=0.2;
					}
					else
					{
						shotangle+=ag*r;
						if(ag>2.4){ag-=0.1;}
					}
					count++;
					yield;
				}
				flg=1;
				task Sub
				{
					let lp=0;
					while(!flg)
					{
						let col=(shotgra-1)%8;
						let speed=[3];
						let angle=shotangle-75*r;
						let gra=81+col;
						let delay=0;
						ascent(a in 0..length(speed))
						{
							CreateShot02(sx,sy,0,angle,speed[a]/240,speed[a],gra,delay);
						}
						
						if(count<limit){wait(3);}
						else{wait(1);}
						lp++;
					}
				}
			}
		}
	}
	
	
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+130,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("悠久「幻想に映る瞬」",20);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		
		SetAction(ACT_SHOT_A,200);
		let p=rand(0,360);
		loop(2)
		{
			let way=3;
			
			let speed=1.5;
			let angle=p;
			while(angle<p+360)
			{
				SetShot(GetX,GetY,speed,angle);
				angle+=360/way;
			}
			p+=360/way/2;
			wait(60);
		}
		wait(90);
		loop
		{
			SetAction(ACT_SHOT_B,400);
			loop(2)
			{
				let leng=0;
				let vy=0;
				loop(7)
				{
					let px=GetPlayerX;
					let py=GetPlayerY;
					loop(4)
					{
						let way=20;
						let sx=[GetX+leng,GetX-leng];
						let sy=GetY+20-vy;
						let speed=2.5;
						let gra=81;
						let delay=10;
						ascent(a in 0..2)
						{
							let p=atan2(py-sy,px-sx[a]);
							let angle=p;
							while(angle<p+360)
							{
								CreateShot01(sx[a],sy,speed,angle,gra,delay);
								angle+=360/way;
							}
						}
						wait(3);
					}
					leng+=20;
					vy+=10;
				}
				wait(30);
			}
			SetMove(cenX+rand(-100,100),minY+rand(120,140),140);
			wait(180);
			
		}
		
		task SetShot(let sx,let sy,let speed,let angle)
		{
			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,47);//ball_m_a_purple
			ObjShot_SetDelay(obj,0);
			ObjShot_SetBombResist(obj,true);
			let basespeed=speed;
			let count=0;
			while(speed>0.1)
			{
				if(Obj_GetX(obj)<minX&&(angle>90||angle<-90)){angle=180-angle;}
				if(Obj_GetX(obj)>maxX&&(angle<90||angle>-90)){angle=180-angle;}
				if(Obj_GetY(obj)>maxY&&angle>0){angle=-angle;}
				if(Obj_GetY(obj)<minY&&angle<0){angle=-angle;}
				
				if(angle>=180){angle+=-360;}
				if(angle<-180){angle+=360;}
				
				Obj_SetAngle(obj,angle);
				
				if(!(count%2)){SetDelayEffect(Obj_GetX(obj),Obj_GetY(obj),22,15);}
				
				if(count>130)
				{
					speed/=1.05;
					Obj_SetSpeed(obj,speed);
				}
				
				count++;
				yield;
			}
			Obj_SetSpeed(obj,0);
			Laser;
			let px=GetPlayerX;let py=GetPlayerY;

			wait(160);
			SetShot(Obj_GetX(obj),Obj_GetY(obj),basespeed,angle);
			local
			{
				let sp=0;
				let way=6;
				let wide=1;
				while(wide<(360/way))
				{
					let speed=4.5-sp;
					let p=atan2(py-Obj_GetY(obj),px-Obj_GetX(obj));
					let ag=p;
					while(ag<p+360)
					{
						let angle=ag-wide/2;
						while(angle<=ag+wide/2+0.1)
						{
							SetShotDirectionType(ABSOLUTE);
							CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
							SetShotDataA(1,0,speed,angle,0,-speed/20,0,87);
							SetShotDirectionType(PLAYER);
							SetShotDataA(1,60,NULL,0,0,0.05,2,NULL);
							FireShot(1);
							
							angle+=wide;
						}
						ag+=360/way;
					}
					sp+=0.6;
					wide+=12;
				}
				SetShotDirectionType(ABSOLUTE);
			}
			Obj_Delete(obj);
			task Laser
			{
				SetTargeting(Obj_GetX(obj),Obj_GetY(obj),0.5,160,2);
				let way=3;
				let p=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));//+(rand_int(-1,1)*10);
				let langle=p;
				let width=15;
				let gra=191;
				let delay=105;
				let del=160;
				while(langle<p+360)
				{
					SetLaserObject(Obj_GetX(obj),Obj_GetY(obj),1000,width,langle,240,gra,delay,del);
					langle+=360/way;
				}
				wait(100);
				let gra=127;
				let langle=p;
				while(langle<p+360)
				{
					CreateLaser01(Obj_GetX(obj),Obj_GetY(obj),20,langle,450,width*2,gra,0);
					langle+=360/way;
				}
			}
		}
	}
	
}
