let S3_imgBACK=csd~"img\3001.png";
let S3_imgTITLE=csd~"img\TITLE3.png";
let S3_imgBOSST=csd~"img\CAUTION.png";
let S3_imgEF	= csd~"img\kumo.png";

sub STAGE3T{
	LoadGraphic(S3_imgBACK);
	LoadGraphic(S3_imgTITLE);
	LoadGraphic(S3_imgBOSST);
	LoadGraphic(S3_imgEF);

	SetCommonData("STAGE",3);
	SetCommonData("Sfade",0);

	function Wait(let frame){loop(frame){yield;}}
	function WaitForZeroEnemy(){while(GetEnemyNum()!=0){yield;}}

	PlayMusic(GetCurrentScriptDirectory~"BGM\bgm3a.mp3");
	SetCommonData("EFC",3);
	Wait(50);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy30_T.txt",224,155,0,0,0);
	WaitForZeroEnemy();//敵が消えるまで停止
	Wait(50);
	TITLE3;
	Wait(350);
        loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31_T.txt",0,0,0,0,0);
		Wait(20);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32_T.txt",0,0,0,0,0);
		Wait(20);
        	}
	Wait(100);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy30_T.txt",224,155,0,0,0);
	Wait(400);
        loop(30){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(40,408),rand(40,360),0,0,0);
		Wait(20);
        	}
	Wait(100);
        DeleteAllEnemyWithoutBoss;
	Wait(10);
	loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy35_T.txt",448,120,0,0,68);
		Wait(10);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy35_T.txt",0,140,0,0,388);
		Wait(10);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy35_T.txt",448,80,0,0,68);
		Wait(10);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy35_T.txt",0,60,0,0,338);
		Wait(10);
		}
		Wait(50);
	loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(50,200),rand(50,200),0,0,0);
		Wait(10);
		}
		Wait(50);
	loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(248,398),rand(50,200),0,0,0);
		Wait(10);
		}
		Wait(100);
	loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(50,200),rand(50,200),0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(248,398),rand(50,200),0,0,0);
		Wait(10);
		}
	Wait(350);
	DeleteAllEnemyWithoutBoss;
	DeleteEnemyShotInCircle(SHOT,224,240,500);
	Wait(10);
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"メディ連続１_T.txt",0,0,0,0,0);
	WaitForZeroEnemy();//敵が消えるまで停止
	Wait(100);
        loop(30){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31_T.txt",0,0,0,0,0);
		Wait(20);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32_T.txt",0,0,0,0,0);
		Wait(20);
        	}
	Wait(100);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy30_T.txt",224,155,0,0,0);
	Wait(300);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy30_T.txt",180,135,0,0,0);
	Wait(300);
	CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy30_T.txt",268,135,0,0,0);
	Wait(400);
	loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(50,200),rand(50,200),0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(248,398),rand(50,200),0,0,0);
		Wait(10);
		}
	Wait(100);
	loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy33_T.txt",rand(50,398),rand(50,200),0,0,0);
		Wait(5);
		}
	Wait(400);
	DeleteAllEnemyWithoutBoss;
	DeleteEnemyShotInCircle(SHOT,224,240,500);
	FadeOutMusic(GetCurrentScriptDirectory~"BGM\bgm3a.mp3",20);
	OVER(1,-224,224,-50,50,0,447,0,99,25,100,70);
	OVER(2,-224,224,-50,50,0,447,0,99,25,100,70);
	OVER(3,-224,224,-50,50,0,447,0,99,25,100,70);
	Wait(175);
	PlayMusic(GetCurrentScriptDirectory~"BGM\bgm3b.mp3");
	CreateEnemyBossFromFile(GetCurrentScriptDirectory~"メディ連続２_T.txt",0,0,0,0,0);
	WaitForZeroEnemy();//敵が消えるまで停止
	Wait(200);
	SetCommonData("EFC",0);
	OVER(1,-224,224,-50,50,0,447,100,199,25,125,70);
	OVER(2,-224,224,-50,50,0,447,100,199,25,125,70);
	OVER(3,-224,224,-50,50,0,447,100,199,25,125,70);
	Wait(50);
	OVER(1,-115,115,-15,15,0,230,262,292,25,75,45);
	OVER(2,-115,115,-15,15,0,230,262,292,25,75,45);
	OVER(3,-115,115,-15,15,0,230,262,292,25,75,45);
	Wait(50);
	AddScore(15000000);
	FadeOutMusic(GetCurrentScriptDirectory~"BGM\bgm3b.mp3",20);
	SetCommonData("Sfade",1);
	Wait(350);
	DeleteGraphic(S3_imgBACK);
	DeleteGraphic(S3_imgTITLE);
	DeleteGraphic(S3_imgBOSST);
	DeleteGraphic(S3_imgEF);

// ========== ステージ3用関数やタスク ========= //
task TITLE3{
	let obj=Obj_Create(OBJ_EFFECT);
	let Talpha=0;
	let csd=GetCurrentScriptDirectory;

	ObjEffect_SetLayer(obj,3);
	ObjEffect_SetTexture(obj,S3_imgTITLE);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ALPHA);

	ObjEffect_SetVertexXY(obj,0,-163,-40);
	ObjEffect_SetVertexXY(obj,1,-163,40);
	ObjEffect_SetVertexXY(obj,2,163,-40);
	ObjEffect_SetVertexXY(obj,3,163,40);

	ObjEffect_SetVertexUV(obj,0,0,0);
	ObjEffect_SetVertexUV(obj,1,0,80);
	ObjEffect_SetVertexUV(obj,2,326,0);
	ObjEffect_SetVertexUV(obj,3,326,80);

        loop(51){
		ObjEffect_SetVertexColor(obj,0,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,1,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,2,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,3,Talpha*5,255,255,255);
		Obj_SetPosition(obj,170+Talpha/2,150);
		Talpha++;
		yield;
		}
        loop(150){yield;}
        loop(51){
		ObjEffect_SetVertexColor(obj,0,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,1,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,2,Talpha*5,255,255,255);
		ObjEffect_SetVertexColor(obj,3,Talpha*5,255,255,255);
		Obj_SetPosition(obj,170+Talpha/2,150);
		Talpha--;
		yield;
		}
	Obj_Delete(obj);
	}

task OVER(AP,Xmin,Xmax,Ymin,Ymax,XA,XB,YA,YB,LA,LB,YC){
	let obj=Obj_Create(OBJ_EFFECT);
	let big1=0;
	let big2=0;
	let csd=GetCurrentScriptDirectory;
	let imgCAUTION=csd~"img\CAUTION.png";

	ObjEffect_SetLayer(obj,3);
	ObjEffect_SetTexture(obj,imgCAUTION);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ALPHA);
	Obj_SetPosition(obj,GetCenterX,GetCenterY-YC);

	ObjEffect_SetVertexXY(obj,0,Xmin,Ymin);
	ObjEffect_SetVertexXY(obj,1,Xmin,Ymax);
	ObjEffect_SetVertexXY(obj,2,Xmax,Ymin);
	ObjEffect_SetVertexXY(obj,3,Xmax,Ymax);

	ObjEffect_SetVertexUV(obj,0,XA,YA);
	ObjEffect_SetVertexUV(obj,1,XA,YB);
	ObjEffect_SetVertexUV(obj,2,XB,YA);
	ObjEffect_SetVertexUV(obj,3,XB,YB);

	PlaySE("seSuperNaturalBorder2.wav");
        loop(LA){
		big1++;
		ObjEffect_SetScale(obj,2-big1*0.04,big1*0.04);
		ObjEffect_SetVertexColor(obj,0,255,255,255,255);
		ObjEffect_SetVertexColor(obj,1,255,255,255,255);
		ObjEffect_SetVertexColor(obj,2,255,255,255,255);
		ObjEffect_SetVertexColor(obj,3,255,255,255,255);
		yield;
		}
        loop(LB){yield;}
        loop(50){
		big2++;
		ObjEffect_SetScale(obj,1+0.004*AP*big2,1+0.004*AP*big2);
		ObjEffect_SetVertexColor(obj,0,255-4*big2,255,255,255);
		ObjEffect_SetVertexColor(obj,1,255-4*big2,255,255,255);
		ObjEffect_SetVertexColor(obj,2,255-4*big2,255,255,255);
		ObjEffect_SetVertexColor(obj,3,255-4*big2,255,255,255);
		yield;
		}
	Obj_Delete(obj);
	}
}