#e
#Title[̈]
#Text[@DExtraRs[]
#PlayLevel[Extra]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let imgBoss="script\img\ExRumia.png";

	@Initialize
	{
		MagicCircle(false);
		SetX(GetCenterX);
		SetY(GetClipMinY+120);
		SetLife(1000);
		SetTimer(71);
		SetInvincibility(4320);
		SetDurableSpellCard;

		LoadGraphic(imgBoss);
		LoadGraphic(GetCurrentScriptDirectory~"img\circle.png");
		SetTexture(imgBoss);
		SetGraphicRect(0,0,63,63);
		LoadUserShotData(GetCurrentScriptDirectory~"img\shot_heian.txt");

		CutIn(YOUMU,"̈",0,0,0,0,0);
		PlaySE(GetCurrentScriptDirectory~"se\don19.wav");
		Concentration01(60);
		SetMovePosition02(GetCenterX,-50,60);

		Tmain;
	}

	@MainLoop
	{
		SetCollisionA(GetX,GetY,32);
		SetCollisionB(GetX,GetY,24);
		yield;
	}

	@DrawLoop
	{
		DrawGraphic(GetX,GetY);
	}

	@Finalize
	{
		DeleteGraphic(imgBoss);
	}

	task Tmain
	{
		yield;
		Tcircle(GetX,GetY,90,192,true);
		wait(90);
		Tlaserattack1(40);
		wait(100);
		Tshotattack1(200,12,0);
		let frame=200;
		loop(4)
		{
			wait(frame);
			frame-=20;
			Tlaserattack1(0);
			Tshotattack3(90,GetClipMinX,GetPlayerX,76.8);
			wait(60);
			Tshotattack1(frame,12,0);
		}
		wait(80);
		Tlaserattack2(40);
		wait(40);
		Tlaserattack1(0);
		Tshotattack3(90,GetClipMinX,GetPlayerX,76.8);
		frame=180;
		let s=90;
		loop(2)
		{
			wait(60);
			Tshotattack2(frame,12,0);
			wait(frame);
			frame-=20;
			Tlaserattack2(0);
			Tshotattack3(90+sin(s)*90,GetClipMinY,GetPlayerY,448/6);
			s+=180;
		}
		loop(3)
		{
			wait(60);
			Tshotattack2(140,12,0);
			wait(140);
			Tlaserattack2(0);
			Tshotattack3(90+sin(s)*90,GetClipMinY,GetPlayerY,448/6);
			s+=180;
		}
		wait(60);
		Tshotattack2(140,12,0);
		wait(140);
		Tlaserattack2(0);
		wait(90);
		DeleteEnemyShotToItem(ALL);
		wait(10);
		Tlaserattack1(40);
		Tlaserattack2(40);
		wait(40);
		let i=24;
		loop(6)
		{
			wait(60);
			Tshotattack1(220,i,1);
			Tshotattack2(220,i,1);
			i-=3;
			wait(220);
			Tlaserattack1(0);
			Tlaserattack2(0);
		}
	}

	task Tlaserattack1(delay)
	{
		let x=GetClipMinX;
		PlaySE(GetCurrentScriptDirectory~"se\byoro07.wav");
		loop(6)
		{
			Tlaser(x,GetClipMinY-20,90,delay);
			x+=76.8;
		}
	}

	task Tshotattack1(shotframe,interval,array)
	{
		let x=-44.8;
		let y=-32-rand(0,interval*4);
		let n=0;
		PlaySE(GetCurrentScriptDirectory~"se\arrow01.wav");
		loop(64)
		{
			loop(8)
			{
				Tshot(x,y,atan([0.625,interval/76.8][array]*[+1,-1,-1,+1][n])+[0,0,180,180][n],shotframe,0,interval,array);
				x+=76.8;
			}
			x=-44.8;
			y+=interval;
			n++;
			if(n==4){n=0;}
		}
	}

	task Tlaserattack2(delay)
	{
		let y=GetClipMinY;
		PlaySE(GetCurrentScriptDirectory~"se\byoro07.wav");
		loop(7)
		{
			Tlaser(GetClipMinX-20,y,0,delay);
			y+=448/6;
		}
	}

	task Tshotattack2(shotframe,interval,array)
	{
		let x=-16-rand(0,interval*4);
		let y=16-448/6;
		let n=0;
		PlaySE(GetCurrentScriptDirectory~"se\arrow01.wav");
		loop(60)
		{
			loop(9)
			{
				Tshot(x,y,atan([14/9,448/6/interval][array]*[-1,+1,+1,-1][n])+[0,180,0,180][n],shotframe,1,interval,array);
				y+=448/6;
			}
			y=16-448/6;
			x+=interval;
			n++;
			if(n==4){n=0;}
		}
	}

	task Tshotattack3(angle,stpos,plpos,width)
	{
		Tse3;
		loop(7)
		{
			if(stpos<plpos&&plpos<stpos+width)
			{
				loop(16)
				{
					if(angle==90)
					{
						Tshot2(stpos+width/2,GetClipMinY-50,angle,3);
					}
					if(angle==0)
					{
						Tshot2(GetClipMinX-50,stpos+width/2,angle,2.5);
						Tshotattack4(GetClipMinX-50,stpos+width/2+width*2,angle);
						Tshotattack5(GetClipMinX-50,stpos+width/2-width*2,angle);
					}
					if(angle==180)
					{
						Tshot2(GetClipMaxX+50,stpos+width/2,angle,2.5);
						Tshotattack4(GetClipMaxX+50,stpos+width/2+width*2,angle);
						Tshotattack5(GetClipMaxX+50,stpos+width/2-width*2,angle);
					}
					wait(2);
				}
			}
			stpos+=width;
		}
	}

	task Tse3
	{
		loop(8)
		{
			StopSE(GetCurrentScriptDirectory~"se\shoot13.wav");
			PlaySE(GetCurrentScriptDirectory~"se\shoot13.wav");
			wait(4);
		}
	}

	task Tshotattack4(x,y,angle)
	{
		Tse45;
		loop(16)
		{
			Tshot2(x,y,angle,1.25);
			wait(4);
		}
	}

	task Tshotattack5(x,y,angle)
	{
		wait(76);
		Tse45;
		loop(16)
		{
			Tshot2(x,y,angle,1.25);
			wait(4);
		}
	}

	task Tse45
	{
		loop(8)
		{
			PlaySE(GetCurrentScriptDirectory~"se\shoot13.wav");
			wait(8);		
		}
	}

	task Tlaser(x,y,angle,delay)
	{
		let obj=Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,x,y);
		Obj_SetSpeed(obj,0);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,2);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetLength(obj,470);
		ObjLaser_SetWidth(obj,30);
		ObjLaser_SetSource(obj,false);
		wait(60+delay);
		Obj_Delete(obj);
	}

	task Tshot(x,y,angle,shotframe,n,i,a)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,1);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetBombResist(obj,true);
		let s=0;
		loop(shotframe)
		{
			Obj_SetSpeed(obj,(([48,i][a])^2+([76.8,448/6][n])^2)^0.5*pi/2/shotframe*sin(s));
			s+=180/shotframe;
			yield;
		}
		Obj_Delete(obj);
	}

	task Tshot2(x,y,angle,speed)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		Obj_SetSpeed(obj,speed);
		ObjShot_SetGraphic(obj,3);
	}
	#include_function ".\lib.txt"
}
