#東方弾幕風[Stage]
#Title[東方幻葬歌]
#Text[]
#Image[]
#BackGround[User()]
#ScriptVersion[2]
#Player[FREE]

script_event Start0{
	@Initialize{}
	@MainLoop{
	Wait(50);
	let ch=Select("\c[BLUE]Ｎｏｒｍａｌ　Ｍｏｄｅ（普通なムズさ）","\c[RED]Ｔａｎａｔｏｓ　Ｍｏｄｅ（理不尽なムズさ）");
	SetCommonData("MODE",ch);
	Wait(50);
	End();
	}
	@Finalize{}
        }

script_stage_main{
	let csd=GetCurrentScriptDirectory;
	let a=0;
	let b=0;
	let Excount=0;
	let Sfade=0;
	#include_function ".\stage1.txt"
	#include_function ".\stage2.txt"
	#include_function ".\stage3.txt"
	#include_function ".\stage4.txt"
	#include_function ".\stage5.txt"
	#include_function ".\stage6.txt"
	#include_function ".\stage7.txt"
	#include_function ".\stage1_T.txt"
	#include_function ".\stage2_T.txt"
	#include_function ".\stage3_T.txt"
	#include_function ".\stage4_T.txt"
	#include_function ".\stage5_T.txt"
	#include_function ".\stage6_T.txt"
	#include_function ".\stage7_T.txt"

	@Initialize(){
		ExpertEx(false,3,3);
		SetRateScoreSystemEnable(false);
		CreateEventFromScript("Start0");
		Tmain;
	}

	@MainLoop(){
		ForbidShot(true);
		ForbidBomb(true);
		if(OnEvent()==true){break;};
		ForbidShot(false);
		ForbidBomb(false);
		a+=2;
		if(a>=350){a=0;}
		alternative(GetCommonDataDefault("Sfade",0))
		case(0){if(b<255){b+=5;}
			if(b>=255){b=255;}}
		case(1){if(b>0){b-=5;}
			if(b<=0){b=0;}}
		case(2){if(b>150){b-=1;}
			if(b<=150){b=150;}}
		case(3){if(b<200){b+=1;}
			if(b>=200){b=200;}}

		alternative(GetCommonDataDefault("EFC",0))
		case(1){if(a%50==0){EF2(55,55,55);}}
		case(2){if(a%10==0){EF3(rand(20,428),rand(150,480));}}
		case(3){if(a%50==0){EF2(155,0,155);}}
		case(4){if(a%10==0){EF(rand(0,60),rand(1,2.5));}}
		case(5){if(a%20==0){EF2(255,255,255);}}
		case(6){if(a%20==0){EF3(rand(20,428),rand(150,480));}}
		case(7){if(GetPlayerBomb>1){AddBomb(-1);}
			if(a%10==0){EF4(rand(0,360),rand(1,2.5),rand(0,360),rand(-2.5,2.5),rand(0,360),rand(-2.5,2.5));}}

		if(GetPoint<250){SetNormPoint(250);}
		if(GetPoint>=250&&GetPoint<750){SetNormPoint(750);}
		if(GetPoint>=750&&GetPoint<1500){SetNormPoint(1500);}
		if(GetPoint>=1500&&GetPoint<2500){SetNormPoint(2500);}
		if(GetPoint>=2500){SetNormPoint(9999);}

		if(GetPoint>=250&&Excount<1){ExtendPlayer(1);
			PlaySE("se1UP.wav");
			Excount+=1;}
		if(GetPoint>=750&&Excount<2){ExtendPlayer(1);
			PlaySE("se1UP.wav");
			Excount+=1;}
		if(GetPoint>=1500&&Excount<3){ExtendPlayer(1);
			PlaySE("se1UP.wav");
			Excount+=1;}
		if(GetPoint>=2500&&Excount<4){ExtendPlayer(1);
			PlaySE("se1UP.wav");
			Excount+=1;}
		if(GetPlayerLife<1){AddPoint(-99999);
			Excount=0;}
	yield;
	}

	@Finalize(){
	}

	@BackGround(){
		SetAlpha(b);
		alternative(GetCommonDataDefault("STAGE",0))
		case(1){SetPerspectiveClip(0,1500);
			SetFog(200,700,0,0,0);
			SetTexture(csd~"img\1001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,0,0);}
		case(2){SetPerspectiveClip(0,1500);
			SetFog(200,700,0,0,0);
			SetTexture(csd~"img\2001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,0,0);
			SetPerspectiveClip(0,1500);
			SetFog(100,1000,0,0,0);
			SetViewTo(0,0,0);
			UseZBuffer(true);
			WriteZBuffer(true);
			SetTexture(csd~"img\2002.png");
			SetGraphicRect(2,2,510,510);
			SetGraphicAngle(-180,0,0);
			DrawGraphic3D(0,0,-1395+a*1.7);
			DrawGraphic3D(0,0,-800+a*1.7);
			DrawGraphic3D(0,0,-205+a*1.7);}
		case(3){SetPerspectiveClip(0,1500);
			SetFog(0,500,0,0,0);
			SetTexture(csd~"img\3001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,0,0);}
		case(4){SetPerspectiveClip(0,1500);
			SetFog(0,1500,51,51,153);
			SetTexture(csd~"img\4001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,100,0);}
		case(5){SetPerspectiveClip(0,1500);
			SetTexture(csd~"img\5001.png");
			SetGraphicRect(0,0+a/2,1050,700+a/2);
			SetGraphicAngle(-45,0,0);
			DrawGraphic3D(0,100,0);}
		case(6){SetPerspectiveClip(0,1500);
			SetFog(200,700,0,0,0);
			SetTexture(csd~"img\6001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,0,0);
			SetPerspectiveClip(0,1500);
			SetFog(100,1000,0,0,0);
			SetViewTo(0,0,0);
			UseZBuffer(true);
			WriteZBuffer(true);
			SetTexture(csd~"img\6002.png");
			SetGraphicRect(2,2,510,510);
			SetGraphicAngle(-180,0,0);
			DrawGraphic3D(0,0,-1692.5+a*1.7);
			DrawGraphic3D(0,0,-1395+a*1.7);
			DrawGraphic3D(0,0,-1097.5+a*1.7);
			DrawGraphic3D(0,0,-800+a*1.7);
			DrawGraphic3D(0,0,-502.5+a*1.7);
			DrawGraphic3D(0,0,-205+a*1.7);
			DrawGraphic3D(0,0,92.5+a*1.7);}
		case(7){SetPerspectiveClip(0,1500);
			SetFog(200,700,0,0,0);
			SetTexture(csd~"img\7001.png");
			SetGraphicRect(0,0+a,1050,700+a);
			SetGraphicAngle(-90,0,0);
			DrawGraphic3D(0,0,0);}
		}

task Tmain{
	if(OnEvent()==true){yield;};
	if(GetCommonData("MODE")==1){STAGE1();
		STAGE2();
		STAGE3();
		STAGE4();
		STAGE5();
		STAGE6();
		if(GetPlayerLife>=3&&!Continued){STAGE7();}}
	if(GetCommonData("MODE")==2){STAGE1T();
		STAGE2T();
		STAGE3T();
		STAGE4T();
		STAGE5T();
		STAGE6T();
		STAGE7T();}
	ClearStage;
	}

task EF(Angle,Angle2){
	let obj=Obj_Create(OBJ_EFFECT);
	let big=rand(0.5,1);
	let APL=0;
	let csd=GetCurrentScriptDirectory;

	Obj_SetSpeed(obj,rand(0.5,3));
	Obj_SetAngle(obj,90);
	ObjEffect_SetLayer(obj,0);
	ObjEffect_SetTexture(obj,csd~"img\4002.png");
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ALPHA);
	Obj_SetPosition(obj,rand(48,400),rand(16,175));

	ObjEffect_SetVertexXY(obj,0,-32,-32);
	ObjEffect_SetVertexXY(obj,1,-32,32);
	ObjEffect_SetVertexXY(obj,2,32,-32);
	ObjEffect_SetVertexXY(obj,3,32,32);

	ObjEffect_SetVertexUV(obj,0,0,0);
	ObjEffect_SetVertexUV(obj,1,0,64);
	ObjEffect_SetVertexUV(obj,2,64,0);
	ObjEffect_SetVertexUV(obj,3,64,64);

        loop(50){
		ObjEffect_SetAngle(obj,0,0,Angle);
		Angle+=Angle2;
		APL+=3;
		ObjEffect_SetScale(obj,big,big);
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
        loop(100){
		ObjEffect_SetAngle(obj,0,0,Angle);
		Angle+=Angle2;
		yield;}
        loop(50){
		ObjEffect_SetAngle(obj,0,0,Angle);
		Angle+=Angle2;
		APL-=3;
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
	Obj_Delete(obj);
	}

	task EF2(R,G,B){
		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(2,4));

		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,150,R,G,B);
		ObjEffect_SetVertexColor(obj,1,150,R,G,B);
		ObjEffect_SetVertexColor(obj,2,150,R,G,B);
		ObjEffect_SetVertexColor(obj,3,150,R,G,B);
        loop(150){
		big++;
		ObjEffect_SetScale(obj,0.25+0.01*big,0.25+0.01*big);
        	loop(2){yield;}
		yield;
		}
		Obj_Delete(obj);
	}

task EF3(x,y){
	let obj=Obj_Create(OBJ_EFFECT);
	let big=rand(0.5,1);
	let APL=0;
	let angle=0;
	let csd=GetCurrentScriptDirectory;

	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,(480.1-y)/500);
	Obj_SetAngle(obj,atan2(480-y,224-x)-180);
	ObjEffect_SetLayer(obj,0);
	ObjEffect_SetTexture(obj,csd~"img\shot_all.png");
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ADD);

	ObjEffect_SetVertexXY(obj,0,-14,-14);
	ObjEffect_SetVertexXY(obj,1,-14,14);
	ObjEffect_SetVertexXY(obj,2,14,-14);
	ObjEffect_SetVertexXY(obj,3,14,14);

	ObjEffect_SetVertexUV(obj,0,56,290);
	ObjEffect_SetVertexUV(obj,1,56,317);
	ObjEffect_SetVertexUV(obj,2,83,290);
	ObjEffect_SetVertexUV(obj,3,83,317);

        loop(50){
		ObjEffect_SetAngle(obj,0,0,angle);
		angle+=3;
		APL+=2;
		big+=0.01;
		ObjEffect_SetScale(obj,big,big);
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
        loop(50){
		ObjEffect_SetAngle(obj,0,0,angle);
		angle+=3;
		APL-=2;
		big+=0.01;
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
	Obj_Delete(obj);
	}

task EF4(Angle,Angle2,Angle3,Angle4,Angle5,Angle6){
	let obj=Obj_Create(OBJ_EFFECT);
	let big=rand(0.5,1);
	let APL=0;
	let csd=GetCurrentScriptDirectory;

	Obj_SetSpeed(obj,rand(0.5,5));
	Obj_SetAngle(obj,90);
	ObjEffect_SetLayer(obj,0);
	ObjEffect_SetTexture(obj,csd~"img\7002.png");
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetRenderState(obj,ALPHA);
	Obj_SetPosition(obj,rand(48,400),rand(-20,175));

	ObjEffect_SetVertexXY(obj,0,-32,-32);
	ObjEffect_SetVertexXY(obj,1,-32,32);
	ObjEffect_SetVertexXY(obj,2,32,-32);
	ObjEffect_SetVertexXY(obj,3,32,32);

	ObjEffect_SetVertexUV(obj,0,0,0);
	ObjEffect_SetVertexUV(obj,1,0,64);
	ObjEffect_SetVertexUV(obj,2,64,0);
	ObjEffect_SetVertexUV(obj,3,64,64);

        loop(50){
		ObjEffect_SetAngle(obj,Angle3,Angle5,Angle);
		Angle+=Angle2;
		Angle3+=Angle4;
		Angle5+=Angle6;
		APL+=2;
		ObjEffect_SetScale(obj,big,big);
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
        loop(100){
		ObjEffect_SetAngle(obj,Angle3,Angle5,Angle);
		Angle+=Angle2;
		Angle3+=Angle4;
		Angle5+=Angle6;
		yield;}
        loop(50){
		ObjEffect_SetAngle(obj,Angle3,Angle5,Angle);
		Angle+=Angle2;
		Angle3+=Angle4;
		Angle5+=Angle6;
		APL-=2;
		ObjEffect_SetVertexColor(obj,0,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,1,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,2,APL,255,255,255);
		ObjEffect_SetVertexColor(obj,3,APL,255,255,255);
		yield;
		}
	Obj_Delete(obj);
	}
}