	#東方弾幕風[Stage]
	#Title[ダブルスポイラー風ver0.50]
	#Text[ダブルスポイラー風ver0.50]
	#Player[.\player\player\AYA.txt,.\player\player\HATATE.txt]
	#BackGround[User]
	#BackGround[Defalt]
	#ScriptVersion[2]

	script_stage_main
	{
	#include_function ".\txt\DifineMenuVariable.txt"//メニュー画面管理用の値の収納先
	#include_function ".\txt/stagedata.txt"
	let StagesnapFile=[];
	loop(30){StagesnapFile=StagesnapFile~["0"];}
	if(SelectedCharacter==DefinedPlayer1)
	{
	StagesnapFile=["DSAya00","DSAya01","DSAya02","DSAya03","DSAya04","DSAya05","DSAya06","DSAya07","DSAya08","DSAya09",
			"DSAya10","DSAya11","DSAya12","DSAya13","DSAya14","DSAya15","DSAya16","DSAya17","DSAya18","DSAya19",
			"DSAya20","DSAya21","DSAya22","DSAya23","DSAya24","DSAya25","DSAya26","DSAya27","DSAya28","DSAya29"];//SSに適当に名付け
	}
	if(SelectedCharacter==DefinedPlayer2)
	{
	StagesnapFile=["DSHatate00","DSHatate01","DSHatate02","DSHatate03","DSHatate04","DSHatate05","DSHatate06","DSHatate07","DSHatate08","DSHatate09",
			"DSHatate10","DSHatate11","DSHatate12","DSHatate13","DSHatate14","DSHatate15","DSHatate16","DSHatate17","DSHatate18","DSHatate19",
			"DSHatate20","DSHatate21","DSHatate22","DSHatate23","DSHatate24","DSHatate25","DSHatate26","DSHatate27","DSHatate28","DSHatate29"];//SSに適当に名付け

	}	
	let imgBG=csd ~ "img/MenuBG.png";
	let imgMenuLetter=csd ~ "img/MenuLetter.bmp";
	let imgDifficult=csd ~ "img/letter.png";
	let imgMenuEffect=csd ~ "img/effect_tiny.png";
	let imgSpellName=GetCurrentScriptDirectory ~ "img/SpellName.jpg";

	let imgBestShot=[];
	let imgBestShotDetail=[];
	let snapFile=[];
	ascent(let i in 0..100)
	{
		snapFile=snapFile~[NumToStringNoComplete(i)];
	}
	ascent(let i in 0..100)
	{
		if(SelectedCharacter==DefinedPlayer1)
		{
			imgBestShot=imgBestShot~[csd ~ "AYABestShot/"~snapFile[i]~".bmp"];
			imgBestShotDetail=imgBestShotDetail~[csd ~ "AYABestShot/"~snapFile[i]~"Detail.bmp"];
		}
		if(SelectedCharacter==DefinedPlayer2)
		{
			imgBestShot=imgBestShot~[csd ~ "HATATEBestShot/"~snapFile[i]~".bmp"];
			imgBestShotDetail=imgBestShotDetail~[csd ~ "HATATEBestShot/"~snapFile[i]~"Detail.bmp"];
		}	
	}

	#include_function ".\settingtxt/SpellCardFile.txt"

	let MenuSE=[csd ~ "se/clock03.wav",csd ~ "se/cursor01.wav"];
	let BGM=[csd ~ "bgm/scene.wav"];
	let SelectedDifficult="Difficult";//スペル後のメニューの制御用。名前はおかしいが。

	let ScoreNumber1=0;
	let ScoreNumber2=0;

	let PhotoDrawing=true;//写真表示の有無の切り替え用変数
	let DetailDrawing=true;//スコア詳細表示の有無の切り替え用変数

		task StageTask
		{
			yield;
			//MenuBackDraw;
			ShootFlagTask;
			MenuEffect;
			DefeatEffect;
			PhotoShooting;
		//	UpTimeCount;//起動時間計測
			PlayTimeCount;//プレイ時間計測
			StageTitleDisplay;

			ForbidShot(false);
			ForbidBomb(false);

		}
	
		
		@Initialize()
		{
		//	SetCommonData("ReplayMode",true);
		//	ExpertEx(false,1,3);
			CreateCommonDataArea(NsScore);
			LoadGraphic(imgBG);
			LoadGraphic(imgMenuEffect);
			LoadGraphic(imgLetter);
			let isRep = IsReplay();
			if(isRep==false)
			{
				LoadCommonDataEx(NsScore,savePathstage);
			}
			else
			{
				LoadCommonDataFromReplayFile;
				StageState=Loading;
			}
			SetCommonData(NsIsReplay,isRep);
			SetCommonData(NsIsReplayJudgment,isRep);
			StageTask();
		}
	
		@MainLoop()
		{
			yield;
			if(OnPlayerMissed)
			{
				SetCommonData("Playermissed",true);
			}
			else
			{
				SetCommonData("Playermissed",false);
			}

		}
		

		@DrawTopObject
		{
			SetTexture(imgBG);
			SetGraphicScale(1.0,1.0);
			SetGraphicRect(0,0,384,448);
			if(StageState==Menu || StageState==Loading || StageState==Exit)
			{
				SetGraphicAngle(0, 0, 0);
				SetViewTo(0,0,0);
				DrawGraphic(GetCenterX, GetCenterY);
			}
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsUpTime,0)/60),320,432,12,255);//起動時間の表示
			//DrawText(NumToStringNoComplete(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/60),320,452,12,255);//プレイ時間の表示
			//DrawText(NumToStringNoComplete(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/6),320,432,12,255);//プレイ時間の表示
			//DrawText(ToString(100),320,452,12,255);//プレイ時間の表示
			//DrawText(StageState,120,432,12,255);//起動時間の表示
		//	DrawText(SpellSelect,120,452,12,255);//プレイ時間の表示
		//	DrawText(SpellLevel,120,412,12,255);//起動時間の表示
			MenuDraw;
		}

		@Finalize()
		{
			if(GetCommonDataDefault(NsIsReplay,true) == false)
			{
				SaveCommonDataEx(NsScore,savePathstage);
			}
			ClearCommonDataEx(NsScore);
			DeleteCommonData(NsGetSpell);
			DeleteCommonData(NsDefeatFrame);
			DeleteCommonData(NsDefeatPosX);
			DeleteCommonData(NsDefeatPosY);
			DeleteCommonData(NsBossFrame);
			DeleteCommonData(NsIsReplay);
		}
		@BackGround {

			}

///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////ステージエフェクト、残機調整部////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

task PhotoShooting
{
loop
{
	if(GetCommonDataDefault("SnapShootingToStage",false)==true)
	{
		SnapShootingMove("Success");
		SetCommonData("SnapShootingToStage",false);
	}
	if(GetCommonDataDefault("SnapShootingToStageFalse",false)==true)
	{
		SnapShootingMove("False");
		SetCommonData("SnapShootingToStageFalse",false);
	}
yield;
}
}

task SnapShootingMove(Judg)
{
	let photoNo=GetCommonData("CD_photoNo");
	let dis2=GetCommonData("CD_dis2");
	let finderangle=GetCommonData("CD_finderangle");
	let CX=GetCommonData("CameraPositionX");
	let CY=GetCommonData("CameraPositionY");
	let CameraLong=GetCommonData("CameraLong");
	let CameraWide=GetCommonData("CameraWide");
	let CAngle=GetCommonData("CameraAngle");
	let CameraDir=GetCommonData("CameraDir");
	let size=GetCommonData("CameraSize");
	let imgPhoto = "snapshot\"~StagesnapFile[photoNo]~".bmp";
		LoadGraphic(imgPhoto);//撮った写真から読み込む
		let scax=1;
		let scay=1;
	//以下カメラの中心から画面端までの距離と角度を設定
		let OriAngle1=atan2(GetClipMinX-CX,GetClipMinY-CY);
		let OriDis1=((GetClipMinX-CX)^2+((GetClipMinY-CY)^2))^0.5;
		let OriAngle2=atan2(GetClipMaxX-CX,GetClipMinY-CY);
		let OriDis2=((GetClipMaxX-CX)^2+((GetClipMinY-CY)^2))^0.5;
		let OriAngle3=atan2(GetClipMaxX-CX,GetClipMaxY-CY);
		let OriDis3=((GetClipMaxX-CX)^2+((GetClipMaxY-CY)^2))^0.5;
		let OriAngle4=atan2(GetClipMinX-CX,GetClipMaxY-CY);
		let OriDis4=((GetClipMinX-CX)^2+((GetClipMaxY-CY)^2))^0.5;

		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgPhoto);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
//X,Yはカメラの４頂点の座標。PX,PYはカメラの中心から頂点までの成分の絶対値。
		let X=[CX+dxdy(0,0,dis2,finderangle,CAngle,CameraDir,size),CX+dxdy(CameraLong,0,dis2,finderangle,CAngle,CameraDir,size),CX+dxdy(CameraLong,CameraWide,dis2,finderangle,CAngle,CameraDir,size), CX+dxdy(0,CameraWide,dis2,finderangle,CAngle,CameraDir,size), ];
		let Y=[CY+dxdy2(0,0,dis2,finderangle,CAngle,CameraDir,size),CY+dxdy2(CameraLong,0,dis2,finderangle,CAngle,CameraDir,size),CY+dxdy2(CameraLong,CameraWide,dis2,finderangle,CAngle,CameraDir,size), CY+dxdy2(0,CameraWide,dis2,finderangle,CAngle,CameraDir,size)];
		let PX=CameraLong/2*size;
		let PY=CameraWide/2*size;
//写真の切り取り方を決定するタスク。
		let CDAngle=CameraDir;
		ShootRange(obj,CAngle,CDAngle,X,Y,PX,PY,OriAngle1,OriDis1,OriAngle2,OriDis2,OriAngle3,OriDis3,OriAngle4,OriDis4);

		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir);
		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,CX,CY);



		let DX=GetClipMaxX+40+65*((photoNo%10)%3);//一般スペルの時の写真Ｘ座標
		let DY=GetCenterY+50+65*trunc((photoNo%10)/3);//一般スペルの時の写真Ｘ座標
		let posX=Obj_GetX(obj);//徐々に移動させるために必要
		let posY=Obj_GetY(obj);
		let loopnum=30;//写真が規定座標に行くまでの時間スローのため体感時間は長いけど

		let SnapAngle=0;//回転させるための値
		let SnapSize=0.2;//そのまま。写真のサイズ

		SnapSize=0.4;
		if((photoNo%10)<=4)
		{
			DX=GetClipMaxX+70;
			DY=GetCenterY-170+(photoNo%10)*85;
		}
		else
		{
			DX=GetClipMaxX+155;
			DY=GetCenterY-170+((photoNo%10)-5)*85;
		}
			
		if(Judg=="False")
		{
			DX=CX;
			DY=CY+60;
		}

///////////////////////////////////////////////////////////////////////////////////
let CameraBack2=csd~"player\img\Back2.png";
LoadGraphic(CameraBack2);//撮った写真から読み込む
		let BGscax2=1.00;
		let BGscay2=1.00;
	//	let finderangle9=atan(1.15/1.5)+180+CameraDir-90;
		let obj9=Obj_Create(OBJ_EFFECT);
				ObjEffect_SetTexture(obj9, CameraBack2);
		ObjEffect_SetPrimitiveType(obj9, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj9, ADD); 
	//	ObjEffect_SetRenderState(obj9, MULTIPLY); 
		ObjEffect_CreateVertex(obj9, 16);

		let VertexX=PX/2;
		let VertexY=PY/2;

		ObjEffect_SetVertexXY(obj9, 0, -VertexX*2, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 1, -VertexX,  -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 2, 0, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 3,  VertexX,  -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 4, VertexX*2, -VertexY*2);
		ObjEffect_SetVertexXY(obj9, 5, VertexX*2,  -VertexY);
		ObjEffect_SetVertexXY(obj9, 6, VertexX*2, 0);
		ObjEffect_SetVertexXY(obj9, 7,  VertexX*2,  VertexY);
		ObjEffect_SetVertexXY(obj9, 8, VertexX*2, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 9, VertexX,  VertexY*2);
		ObjEffect_SetVertexXY(obj9, 10, 0, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 11,  -VertexX,  VertexY*2);
		ObjEffect_SetVertexXY(obj9, 12, -VertexX*2, VertexY*2);
		ObjEffect_SetVertexXY(obj9, 13, -VertexX*2,  VertexY);
		ObjEffect_SetVertexXY(obj9, 14, -VertexX*2, 0);
		ObjEffect_SetVertexXY(obj9, 15,  -VertexX*2,  -VertexY);

		ObjEffect_SetVertexUV(obj9, 0,  0,  0);
		ObjEffect_SetVertexUV(obj9, 1,  100, 0);
		ObjEffect_SetVertexUV(obj9, 2, 200,  0);
		ObjEffect_SetVertexUV(obj9, 3, 300, 0);
		ObjEffect_SetVertexUV(obj9, 4, 401,  0);
		ObjEffect_SetVertexUV(obj9, 5, 401,  100);
		ObjEffect_SetVertexUV(obj9, 6, 401, 200);
		ObjEffect_SetVertexUV(obj9, 7,  401,  300);
		ObjEffect_SetVertexUV(obj9, 8,  401, 401);
		ObjEffect_SetVertexUV(obj9, 9, 300,  401);
		ObjEffect_SetVertexUV(obj9, 10, 200, 401);
		ObjEffect_SetVertexUV(obj9, 11,  100,  401);
		ObjEffect_SetVertexUV(obj9, 12,  0, 401);
		ObjEffect_SetVertexUV(obj9, 13, 0,  300);
		ObjEffect_SetVertexUV(obj9, 14, 0, 200);
		ObjEffect_SetVertexUV(obj9, 15, 0, 100);

		ObjEffect_SetScale(obj9, BGscax2,BGscay2);
		ObjEffect_SetAngle(obj9,0,0,CAngle+CameraDir);
		ObjEffect_SetLayer(obj9,8);
		Obj_SetPosition(obj9,CX,CY);
			ascent(let i in 0..16)
			{
				ObjEffect_SetVertexColor(obj9,i,150,255,255,255);
			}
	ascent(let j in 0..4)
	{
		ascent(let i in 0..5)
		{
			if((X[j]*(5-i)+X[(j+1)%4]*i)/5<GetClipMinX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5<GetClipMinY || (X[j]*(5-i)+X[(j+1)%4]*i)/5>GetClipMaxX || (Y[j]*(5-i)+Y[(j+1)%4]*i)/5>GetClipMaxY)
			{
				ObjEffect_SetVertexColor(obj9,j*4+i,0,50,50,50);
			}
		}
	}
//////////////////////////////////////////////////////////////////////////
		loop(loopnum)
		{
			Obj_SetPosition(obj,Obj_GetX(obj)+(DX-posX)/loopnum,Obj_GetY(obj)+(DY-posY)/loopnum);
			ObjEffect_SetScale(obj, scax,scay);
			scax-=(1-SnapSize)/loopnum;
			scay-=(1-SnapSize)/loopnum;
			SnapAngle+=360/loopnum;
			ObjEffect_SetAngle(obj,0,0,CAngle+CameraDir+SnapAngle);

			Obj_SetPosition(obj9,Obj_GetX(obj9)+(DX-posX)/loopnum,Obj_GetY(obj9)+(DY-posY)/loopnum);
			ObjEffect_SetScale(obj9, BGscax2,BGscay2);
			BGscax2-=(1-SnapSize)/loopnum;
			BGscay2-=(1-SnapSize)/loopnum;
			ObjEffect_SetAngle(obj9,0,0,CAngle+CameraDir+SnapAngle);

			yield;
		}
ObjEffect_SetScale(obj, BGscax2,BGscay2);
ObjEffect_SetScale(obj9, BGscax2,BGscay2);
if(Judg=="Success")
{
wait(10);
}
Obj_Delete(obj);
Obj_Delete(obj9);
}


task MenuEffect//写真枚数表示の紅葉を表示する
{
let DX=0;
let DY=0;
let No=0;
while(GetCommonDataDefault("BossExist",false)==false){yield;}
let EnemyLife=GetCommonDataDefault("EnemyLife",1);
wait(1);
loop(ceil(EnemyLife/500))
{
	if((No%10)<=4)
	{
		DX=GetClipMaxX+70;
		DY=GetCenterY-170+(No%10)*85;
	}
	else
	{
		DX=GetClipMaxX+155;
		DY=GetCenterY-170+((No%10)-5)*85;
	}
	EffectMomiji(DX,DY,No);
	No+=1;
}
}

task EffectMomiji(X,Y,No)//紅葉の設定
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMenuEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj, 1,1);
		
		ObjEffect_SetVertexColor(obj,0,255,255,50,50);
		ObjEffect_SetVertexColor(obj,1,255,255,50,50);
		ObjEffect_SetVertexColor(obj,2,255,255,50,50);
		ObjEffect_SetVertexColor(obj,3,255,255,50,50);

		Obj_SetPosition(obj,X,Y);
		ascent(let i in 0..30)
		{
			ObjEffect_SetScale(obj, i/30,i/30);
			yield;
		}
		while(GetEnemyInfoDefault(1,ENEMY_LIFE,10000)-1000+501*No>=GetCommonDataDefault("EnemyLife",1) && GetCommonDataDefault("ShootingEnd",false)==false){yield;}
		Obj_Delete(obj);
}
//////////////////////////////////////////////////////////////////////////////////////////
task DefeatEffect//撃破時紅葉を表示する
{
let No=0;
while(GetCommonDataDefault("DefeatBoss",false)==false){yield;}
let DX=GetEnemyInfo(1,ENEMY_X);
let DY=GetEnemyInfo(1,ENEMY_Y);
let Alpha;
let Angle;
let Speed=0;
wait(1);
loop(30)
{
let Alpha=rand(150,255);
DefeatMomiji(DX,DY,Speed,0.75,Alpha);
DefeatMomiji(DX,DY,Speed,1,Alpha);
DefeatMomiji(DX,DY,Speed,1.25,Alpha);
DefeatMomiji(DX,DY,Speed,1.5,Alpha);
DefeatMomiji(DX,DY,Speed,1.75,Alpha);
DefeatMomiji(DX,DY,Speed,0.5,Alpha);
DefeatMomiji(DX,DY,Speed,2.0,Alpha);
wait(1);
Speed+=0.05;
}
}

task DefeatMomiji(X,Y,speed,Scale,Alpha)//紅葉の設定
{
		let Angle=rand(0,360);
		let Speed=speed+rand(3,7);
		let RotateAngle=rand(2,5);
		let Zangle=rand(0,360);
		let dir=rand_int(0,1)*2-1;
		let YRandamColor=rand(50,200);

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgMenuEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -15, -15);
		ObjEffect_SetVertexXY(obj, 1, 15,  -15);
		ObjEffect_SetVertexXY(obj, 2, 15, 15);
		ObjEffect_SetVertexXY(obj, 3,  -15,  15);
		
		ObjEffect_SetVertexUV(obj, 0,  2,  24);
		ObjEffect_SetVertexUV(obj, 1,  32, 24);
		ObjEffect_SetVertexUV(obj, 2, 32,  55);
		ObjEffect_SetVertexUV(obj, 3, 2, 55);
		ObjEffect_SetLayer(obj,4);
		ObjEffect_SetScale(obj, Scale,Scale);
		
		ObjEffect_SetVertexColor(obj,0,Alpha,255,YRandamColor,50);
		ObjEffect_SetVertexColor(obj,1,Alpha,255,YRandamColor,50);
		ObjEffect_SetVertexColor(obj,2,Alpha,255,YRandamColor,50);
		ObjEffect_SetVertexColor(obj,3,Alpha,255,YRandamColor,50);

		Obj_SetPosition(obj,X,Y);
		Obj_SetAngle(obj,Angle);
		Obj_SetSpeed(obj,Speed);

		while(!Obj_BeDeleted(obj))
		{
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=RotateAngle*dir;
			yield;
		}
}

task LoadindPhotoImage
{//メニュー表示のための画像をロード
	while(MenuState!=Menu){yield;}
	#include_function ".\settingtxt/SetSpellName.txt"
	LoadGraphic(imgSpellName);
	LoadGraphic(imgMenuLetter);
	ascent(let i in 1..100)
	{
	LoadGraphic(imgBestShot[i]);
	LoadGraphic(imgBestShotDetail[i]);
	}
	BestPhotoDraw;
	DetailDraw;
}
//////////////////////////////////////////////////////////////////////////////////////////////
///////////ステージ部、リトライでの制御//////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
let PhotoReload=true;
sub StageTitleDisplay//メニュー画面の表示、SecretSpell部分でも呼び出して再起している。
{
if(PhotoReload==true && GetCommonData(NsIsReplayJudgment) == false && GetCommonDataDefaultEx(NsScore,"SpellNo",1) == 0)
{
	LoadindPhotoImage;//全てのベストショット画像をロード
}

if(GetCommonDataDefaultEx(NsScore,"MenuSpellNo",0)!=0)
{
	SpellSelect=GetCommonDataDefaultEx(NsScore,"MenuSpellNo",0);//savedataからメニュー用のSelectを読み込む
	SpellLevel=GetCommonDataDefaultEx(NsScore,"MenuSpellLevelNo",0);//savedataからメニュー用のLevelを読み込む
}
if(GetCommonDataDefaultEx(NsScore,"SpellNo",0)==0 && GetCommonData(NsIsReplayJudgment) == false)
{
SetCommonData("DoubleSpoilerStageMenu",true);
	loop
	{
		alternative(StageState)	
		case(Menu)
		{
			TASK_MENU;
		}
		case(Exit)
		{
			StageState=Loading;
			SetCommonDataEx(NsScore,"SpellNo",SpellSelect);
			SetCommonDataEx(NsScore,"SpellLevelNo",SpellLevel);
			SetCommonDataEx(NsScore,"MenuSpellNo",0);
			SetCommonDataEx(NsScore,"MenuSpellLevelNo",0);
			SaveCommonDataEx(NsScore,savePath);//Select&Levelを保存
			wait(5);
SetCommonData("DoubleSpoilerStageMenu",false);
			Retry;
			break;
		 }
		others{}
	yield;
	}
}

else
{

StageState=Start;
if(GetCommonData(NsIsReplayJudgment) == false)
{
	SpellSelect=GetCommonDataDefaultEx(NsScore,"SpellNo",1);
	SpellLevel=GetCommonDataDefaultEx(NsScore,"SpellLevelNo",1);
	SetCommonDataEx(NsScore,"SpellNo",SpellSelect);
	SetCommonData("SpellNo",SpellSelect);
	SetCommonDataEx(NsScore,"SpellLevelNo",SpellLevel);
	SetCommonData("SpellLevelNo",SpellLevel);
	SaveCommonDataInReplayFile;
	SetCommonDataEx(NsScore,"SpellNo",0);
	SetCommonDataEx(NsScore,"SpellLevelNo",0);
}

else
{
	SpellSelect=GetCommonDataDefault("SpellNo",2);
	SpellLevel=GetCommonDataDefault("SpellLevelNo",2);
	SetCommonData(NsIsReplayJudgment,false);
}
}

DisPlayScore(SpellSelect);//スコアを表示

	ForbidShot(false);
	PlayMusic(BGM[0]);
	CreateEnemyFromFile(SpellCardScScript[SpellSelect+SpellLevel*10],GetCenterX,GetClipMinY,2,0,0);
	wait(5);
	while(GetCommonDataDefault("BossExist",false)==true || StageState==Menu)
	{
		yield;
	}
	wait(30);
	EndSpellMenu;
}

task EndSpellMenu
{
	Select=3000;
	StageState=Menu;
	MenuState=MenuDifficult;
	SetCommonData("ShootingEnd",true);
	endbunka;
	PhotoReload=false;
	StageTitleDisplay;
}

task endbunka
{
	while(MenuState==MenuDifficult){yield;}
	SetCommonData("PhotoEraze",true);
	StageState=Loading;
	SetCommonDataEx(NsScore,"MenuSpellNo",SpellSelect);
	SetCommonDataEx(NsScore,"MenuSpellLevelNo",SpellLevel);
	SaveCommonDataEx(NsScore,savePath);
	yield;
	Retry;
}
////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////アイテム部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////
//////////////////時間計測、回数記録部/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
		task UpTimeCount//起動時間の計測
		{
			let UpTime=GetCommonDataDefaultEx(NsScore,NsUpTime,0);
			loop
			{
				UpTime++;
				SetCommonDataEx(NsScore,NsUpTime,UpTime);
				yield;
			}
		}

		task PlayTimeCount//プレイ時間の計測
		{
			let PlayTime=GetCommonDataDefaultEx(NsScore,NsPlayTime,0);
			loop
			{
				if(StageState!=Menu)
				{
				PlayTime++;
				}
				SetCommonDataEx(NsScore,NsPlayTime,PlayTime);
				yield;
			}
		}
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////スコア表示部、写真の記録も//////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
task DisPlayScore(let SpellNo)//ハイスコアを呼び出し、ハイスコアと現スコアを表示
{
let EachHiScore=0;

while(GetCommonDataDefault("BossExist",false)==false){yield;}
if(SelectedCharacter==DefinedPlayer1)
{
	CreateScore(GetCommonDataDefaultEx(NsScore,Player1Hiscore[SpellNo+SpellLevel*10],0),SpellNo+SpellLevel*10);
}
if(SelectedCharacter==DefinedPlayer2)
{
	CreateScore(GetCommonDataDefaultEx(NsScore,Player2Hiscore[SpellNo+SpellLevel*10],0),SpellNo+SpellLevel*10);
}
}

function CreateScore(let EachHiScore,SpellNo)//
{
loop
{
	ScoreNumber1+=GetScore;
	AddScore(-GetScore);

	DisPlayScoreNumber(GetClipMinX+80,GetClipMinY+20,EachHiScore,ScoreNumber2);//ハイスコア
	DisPlayScoreNumber(GetClipMaxX-10,GetClipMinY+20,ScoreNumber1,ScoreNumber2);//現スコア

	SetCommonData("PlayerHiPhoto",GetCommonDataEx(NsScore,Player2HiPhoto[SpellNo]));

	if(GetCommonDataDefault("BossExist",false)==false)
	{
		break;
	}
yield;
}

	if(SelectedCharacter==DefinedPlayer1)
	{
	let Number=GetCommonDataDefaultEx(NsScore,Player1AllPhoto[SpellNo],0);
	SetCommonDataEx(NsScore,Player1Challenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player1Challenge[SpellNo],0)+1);//挑戦回数を増やす
	SetCommonDataEx(NsScore,Player1AllPhoto[SpellNo],Number+GetCommonDataDefault("AllPhoto",0));//名前空間に枚数を増やして保存
		if(GetCommonDataDefaultEx(NsScore,Player1Hiscore[SpellNo],0)==0)
		{
			SetCommonDataEx(NsScore,Player1FirstClearChallenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player1FirstClearChallenge[SpellNo],0)+1);//挑戦回数を増やす
			SetCommonDataEx(NsScore,Player1FirstClearPhoto[SpellNo],GetCommonDataDefaultEx(NsScore,Player1FirstClearPhoto[SpellNo],0)+GetCommonDataDefault("AllPhoto",0));
		}
	}
	if(SelectedCharacter==DefinedPlayer2)
	{
	let Number=GetCommonDataDefaultEx(NsScore,Player2AllPhoto[SpellNo],0);
	SetCommonDataEx(NsScore,Player2Challenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player2Challenge[SpellNo],0)+1);//挑戦回数を増やす
	SetCommonDataEx(NsScore,Player2AllPhoto[SpellNo],Number+GetCommonDataDefault("AllPhoto",0));//名前空間に枚数を増やして保存
		if(GetCommonDataDefaultEx(NsScore,Player2Hiscore[SpellNo],0)==0)
		{
			SetCommonDataEx(NsScore,Player2FirstClearChallenge[SpellNo],GetCommonDataDefaultEx(NsScore,Player2FirstClearChallenge[SpellNo],0)+1);//挑戦回数を増やす
			SetCommonDataEx(NsScore,Player2FirstClearPhoto[SpellNo],GetCommonDataDefaultEx(NsScore,Player2FirstClearPhoto[SpellNo],0)+GetCommonDataDefault("AllPhoto",0));
		}
	}

if(EachHiScore<=ScoreNumber1 && GetCommonDataDefault("DefeatBoss",false)==true)
{
	if(SelectedCharacter==DefinedPlayer1)
	{
	SetCommonDataEx(NsScore,Player1Hiscore[SpellNo],ScoreNumber1);//名前空間にハイスコア保存
	}
	if(SelectedCharacter==DefinedPlayer2)
	{
	SetCommonDataEx(NsScore,Player2Hiscore[SpellNo],ScoreNumber1);//名前空間にハイスコア保存
	}
}

if(GetCommonDataDefaultEx(NsScore,Player1HiPhoto[SpellNo],0)<=GetCommonDataDefault("HiBasePoint",0))
{
	if(SelectedCharacter==DefinedPlayer1)
	{
	SetCommonDataEx(NsScore,Player1HiPhoto[SpellNo],GetCommonDataDefault("HiBasePoint",0));//名前空間にベストショット保存、最大点は自機側で判断している
	}
}
if(GetCommonDataDefaultEx(NsScore,Player2HiPhoto[SpellNo],0)<=GetCommonDataDefault("HiBasePoint",0))
{
	if(SelectedCharacter==DefinedPlayer2)
	{
	SetCommonDataEx(NsScore,Player2HiPhoto[SpellNo],GetCommonDataDefault("HiBasePoint",0));//名前空間にベストショット保存、最大点は自機側で判断している
	}
}

	AddScore(ScoreNumber1);
	AddScore(SpellLevel*100000000+SpellSelect*10000000);

SavePhoto(SpellNo);

loop
{

	DisPlayScoreNumber(GetClipMinX+80,GetClipMinY+20,EachHiScore,ScoreNumber2);
	DisPlayScoreNumber(GetClipMaxX-10,GetClipMinY+20,ScoreNumber1,ScoreNumber2);
	if(GetCommonDataDefault("PhotoEraze",false)==true)
	{
		break;
	}
yield;
}
}

task SavePhoto(SpellNo)
{
loop
{
	if(GetCommonDataDefault("PhotoSaveReady",false)==true && GetCommonDataDefault(NsIsReplay,true) == false)
	{//写真選択可能時
		if(GetKeyState(VK_SKIP)==KEY_PUSH)
		{
			SetCommonData("DetailShooting",true);
			wait(1);
			SaveSnapShot(imgBestShotDetail[SpellNo],0,0,448,480);
			SetCommonData("DetailShooting",false);
			SetCommonData("SnapShooting",true);
			wait(1);
			SaveSnapShot(imgBestShot[SpellNo],0,0,448,480);
			wait(1);
			SetCommonData("SnapShooting",false);
			DrawKirokusimasita;
			wait(35);
		}
	}
yield;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////インクルード部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#include_function ".\settingtxt/LevelNorma.txt"
#include_function ".\settingtxt/ScoreNorma.txt"
#include_function ".\settingtxt/Topic.txt"
#include_function ".\txt/MENU.txt"
#include_function ".\txt/MENUDRAW.txt"
#include_function ".\txt/DrawMenuLetterData.txt"
#include_function ".\txt/MenuEffectData.txt"
#include_function ".\txt/stagedataforphoto.txt"
}