#東方弾幕風[Stage]
#Title[小悪魔ステージ]
#Text[小悪魔ステージ]
#Player[FREE]
#BackGround[User()]
#ScriptVersion[2]

script_event Start{
	@Initialize{}

	@MainLoop{
		Wait(10);
			TextOutA("\c[RED]………");
			TextOutA("\c[RED]…すみません。調子に乗りました");
			TextOutA("\c[RED]…大した実力もないのに");
			TextOutA("\c[RED]ホント、すみません……");
		Wait(50);
		End;
	}
	@Finalize{}
}

script_stage_main
{
	let csd     = GetCurrentScriptDirectory;
	let imgEnemy=csd~"img\familiar.png";
	let imgBack=csd~"img\Back.png";
	let imgKUMO=csd~"img\kumo.png";
	let imgTITLE=csd~"img\TITLE.png";
        let cx=GetCenterX();
        let cy=GetCenterY();
        let big=0;
        let ICHI=0;
        let IDOU=0;
	let BGM_B = csd~"BGM\BGM2";

	task StageTask
	{//ステージタスク
		function Wait(let frame)
		{//待機関数
			loop(frame){yield};
		}
		function WaitForZeroEnemy()
		{//敵数が0になるまで待機する関数
			while(GetEnemyNum() != 0){yield;}
		}
		function WaitForEvent()
		{
			while(OnEvent()==true){yield;}
		}
		Wait(50);
		TTITLE;
		PlayMusic(BGM_B);
		Wait(300);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy11.txt",0,rand(30,150),0,0,0);
		Wait(75);
        }
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy12.txt",0,rand(30,150),0,0,0);
		Wait(75);
        }
		Wait(125);
        loop(3){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(75);
        }
		Wait(150);
        loop(3){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(75);
        }
		Wait(150);
        loop(2){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(75);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(75);
        }
		Wait(200);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",rand(90,100),-9,0,0,0);
		Wait(50);
        }
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",rand(348,358),-9,0,0,0);
		Wait(50);
        }
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",rand(90,358),-9,0,0,0);
		Wait(50);
        }
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",rand(90,358),-9,0,0,0);
		Wait(25);
        }
		Wait(300);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",100,0,0,0,0);
		Wait(10);
		}
		Wait(75);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",100,0,0,0,0);
		Wait(10);
		}
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy02.txt",rand(90,358),-9,0,0,0);
		Wait(50);
        }
		Wait(100);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy02.txt",rand(90,358),-9,0,0,0);
		Wait(20);
        }
		Wait(200);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(200);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,0);
		Wait(200);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,50);
		Wait(300);
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"小悪魔０.txt",GetCenterX(),0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		Wait(10);
        loop(40){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",100,0,0,0,0);
		Wait(10);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",100,0,0,0,0);
		Wait(10);
		}
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(1);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy11.txt",0,rand(30,150),0,0,0);
		Wait(5);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy12.txt",0,rand(30,150),0,0,0);
		Wait(100);
		}
		Wait(200);
        loop(3){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(5);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(100);
		}
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(300);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,0);
		Wait(500);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,-100);
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,-50);
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,50);
		Wait(500);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy40.txt",100,-9,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		Wait(150);
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"小悪魔１.txt",GetCenterX(),0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		CreateEventFromScript("Start");
		WaitForEvent();
		Wait(100);
		Clear();
	}
	@Initialize()
	{
		StageTask();//ステージタスク起動
		LoadGraphic(imgEnemy);
		LoadGraphic(imgBack);
		LoadGraphic(imgKUMO);
		LoadGraphic(imgTITLE);
		LoadMusic(BGM_B);
	}
	@MainLoop()
	{
        	if(IDOU>=225)
        	{
        		IDOU=0;
        	}
        	if(IDOU%2==0&&!OnEnemySpell)
        	{
        		HaikeiTask();
        	}
        	IDOU++;
		yield;//毎フレームタスク復帰
	}
	@Finalize()
	{
		DeleteGraphic(imgEnemy);
	}

	@BackGround()
	{
		SetTexture(imgBack);
		SetGraphicRect(0,0,384,448);
		DrawGraphic(cx,224+(IDOU*2));
		SetTexture(imgBack);
		SetGraphicRect(0,0,384,448);
		DrawGraphic(cx,-224+(IDOU*2));
	}
	task HaikeiTask{
		kuraud;
        }
    sub kuraud {
		let obj = Obj_Create(OBJ_EFFECT);
		let ICHI=rand_int(0,448);
		let big=0;
		let csd     = GetCurrentScriptDirectory;
		let imgKUMO=csd~"img\kumo.png";
		Obj_SetPosition(obj,ICHI,-300);
		Obj_SetAngle(obj,90);
		Obj_SetSpeed(obj,rand(4,7));

		ObjEffect_SetLayer(obj,0);
		ObjEffect_SetTexture(obj,imgKUMO);
		ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj,4);
		ObjEffect_SetRenderState(obj,ALPHA);

		ObjEffect_SetVertexXY(obj,0,-162,-81);
		ObjEffect_SetVertexXY(obj,1,-162,81);
		ObjEffect_SetVertexXY(obj,2,162,-81);
		ObjEffect_SetVertexXY(obj,3,162,81);

		ObjEffect_SetVertexUV(obj,0,0,0);
		ObjEffect_SetVertexUV(obj,1,0,162);
		ObjEffect_SetVertexUV(obj,2,324,0);
		ObjEffect_SetVertexUV(obj,3,324,162);

		ObjEffect_SetVertexColor(obj,0,100,155,0,155);
		ObjEffect_SetVertexColor(obj,1,100,155,0,155);
		ObjEffect_SetVertexColor(obj,2,100,255,0,255);
		ObjEffect_SetVertexColor(obj,3,100,255,0,255);
        loop(100){
		big++;
		ObjEffect_SetScale(obj,0.25+0.01*big,0.25+0.01*big);
        	loop(2){yield;}
		yield;
		}
		Obj_Delete(obj);
	}

    task TTITLE {
		let obj = Obj_Create(OBJ_EFFECT);
		let Talpha=0;
		let csd     = GetCurrentScriptDirectory;
		let imgTITLE=csd~"img\TITLE.png";

		ObjEffect_SetLayer(obj,3);
		ObjEffect_SetTexture(obj,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,112+Talpha,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,112+Talpha,150);
		Talpha--;
		yield;
		}
		Obj_Delete(obj);
	}
}