#東方弾幕風[Stage]
#Title[大妖精ステージ]
#Text[天空からの使者]
#Player[FREE]
#BackGround[User()]
#BGM[User(.\BGM\BGM2.mp3)]
#ScriptVersion[2]

script_event Start{
	@Initialize{}

	@MainLoop{
		Wait(10);
		if(GetPlayerType==REIMU_A || GetPlayerType==REIMU_B){
			TextOutA("\c[RED]うう…今回も負けたぁ…");
			TextOutA("\c[BLUE]天使の力っても、大した事ないわね");
			TextOutA("\c[RED]むー…");
			TextOutA("\c[BLUE]まあ、そんなに落ち込むことはないと思うわ");
			TextOutA("\c[RED]そうですか…？");
			TextOutA("\c[BLUE]妖精は元々、力の弱い種族だからね");
			TextOutA("\c[BLUE]ただ、それほど強力な力を悪戯に使われると困るから……");
			TextOutA("\c[BLUE]大切なものを守る為に使いなさい。\nいいわね？");
			TextOutA("\c[RED]はい……");
			TextOutB(120,"\c[BLUE]よろしいっ");
			} else if(GetPlayerType==MARISA_A || GetPlayerType==MARISA_B){
			TextOutA("\c[RED]うう…今回も負けたぁ…");
			TextOutA("\c[BLUE]天使の力っても、大した事ないな");
			TextOutA("\c[BLUE]まあ、元より私のパワーに勝てるわけが\nないんだがな");
			TextOutA("\c[RED]むー…");
			TextOutA("\c[BLUE]まあ、そんなに落ち込むなって");
			TextOutA("\c[RED]そうですか…？");
			TextOutA("\c[BLUE]妖精は元々、力の弱い種族だからな");
			TextOutA("\c[BLUE]ただ、それほど強力な力を悪戯に使われると困るから……");
			TextOutA("\c[BLUE]その時は是非とも誘ってくれ。な？");
			TextOutB(120,"\c[RED]えー……");
			} else {
			TextOutB(120,"\c[RED]うう……負けちゃった……");
			}
		Wait(300);
		StageClear;
	}
	@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;

	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;
		Wait(300);
        loop(25){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(25){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",0,rand(30,150),0,0,0);
		Wait(10);
        }
		Wait(125);
        loop(3){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(100);
        }
		Wait(100);
        loop(3){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(100);
        }
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(50);
        }
		Wait(200);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy50.txt",rand(48,400),rand(48,200),0,0,0);
		Wait(2);
        }
		Wait(100);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",100,0,0,0,0);
		Wait(10);
		}
		Wait(75);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy50.txt",rand(48,400),rand(48,200),0,0,0);
		Wait(2);
        }
		Wait(100);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",100,0,0,0,0);
		Wait(10);
		}
		Wait(100);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",rand(90,358),-9,0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy50.txt",rand(48,400),rand(48,200),0,0,0);
		Wait(20);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",rand(90,358),-9,0,0,0);
		Wait(20);
        }
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
        loop(25){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy50.txt",rand(48,400),rand(48,200),0,0,0);
		Wait(4);
        }
		Wait(300);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy_Iku.txt",0,0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"永江衣玖連続.txt",GetCenterX(),0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		Wait(50);
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",0,rand(30,150),0,0,0);
		Wait(10);
        }
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy21.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(10){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy22.txt",0,rand(30,150),0,0,0);
		Wait(10);
        }
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		Wait(100);
        loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy11.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy12.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy11.txt",0,0,0,0,0);
		Wait(10);
        }
        loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy12.txt",0,0,0,0,0);
		Wait(10);
        }
		Wait(100);
        loop(5){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy04.txt",348,-9,0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy03.txt",100,-9,0,0,0);
		Wait(100);
		}
		Wait(150);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(200);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,0);
		Wait(100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,-100);
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,-50);
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		Wait(50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,50);
		Wait(200);
        loop(15){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy12.txt",0,0,0,0,0);
		Wait(10);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy11.txt",0,0,0,0,0);
		Wait(10);
        }
		Wait(200);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,-100);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,-50);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy31.txt",0,0,0,0,0);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy32.txt",0,0,0,0,50);
		Wait(100);
        loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy51.txt",rand(48,400),rand(48,200),0,0,0);
		Wait(2);
        }
		WaitForZeroEnemy();//敵が消えるまで停止
		Wait(500);
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy_Daiyousei.txt",0,0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		CreateEnemyBossFromFile(GetCurrentScriptDirectory~"大妖精連続.txt",GetCenterX(),0,0,0,0);
		WaitForZeroEnemy();//敵が消えるまで停止
		CreateEventFromScript("Start");
		WaitForEvent();
		Wait(300);
		Clear();
	}
	@Initialize()
	{
		StageTask();//ステージタスク起動
		LoadGraphic(imgEnemy);
		LoadGraphic(imgBack);
		LoadGraphic(imgKUMO);
		LoadGraphic(imgTITLE);
	}
	@MainLoop()
	{
        	if(IDOU>=225)
        	{
        		IDOU=0;
        	}
        	if(IDOU%4==0&&!OnEnemySpell)
        	{
        		HaikeiTask();
        	}
        	IDOU++;
		yield;//毎フレームタスク復帰
	}
	@Finalize()
	{
		DeleteGraphic(imgEnemy);
	}

	@BackGround()
	{
		SetTexture(imgBack);
		SetGraphicRect(0,0,384,448);
		DrawGraphic(cx,(IDOU*4)+448);
		DrawGraphic(cx,(IDOU*4));
		DrawGraphic(cx,(IDOU*4)-448);
		DrawGraphic(cx,(IDOU*4)-896);
	}
	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,200,200,200,200);
		ObjEffect_SetVertexColor(obj,1,200,200,200,200);
		ObjEffect_SetVertexColor(obj,2,200,255,255,255);
		ObjEffect_SetVertexColor(obj,3,200,255,255,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);
	}
}