	#東方弾幕風[Stage]
	#Title[Magical Singular Day ver0.02]
	#Text[Magical Singular Day ver0.02]
	#Player[.\player/MarisaA\MarisaA.txt,.\player/MarisaA\MarisaAAuto.txt,.\player/MarisaB\MarisaB.txt,.\player/MarisaB\MarisaBAuto.txt]
	#BackGround[User]
	#BackGround[Defalt]
	#ScriptVersion[2]

	script_stage_main
	{
	SetRateScoreSystemEnable(false);
	SetDefaultStatusVisible(false);
	let csd=GetCurrentScriptDirectory;
	let imgBG=csd ~ "img/MenuBG.png";

	let imgMenuEffect=csd ~ "img/effect_tiny.png";

	let imgMenuLetter=csd ~ "img/menuletter.png";
	let imgNumber=csd ~ "img/Number.png";
	let imgStatusLetter=csd ~ "img/StatusLetter.png";
	let imgBer=csd ~ "img/ber.png";
	let imgBer2=csd ~ "img/ber2.png";

	let MenuSE=[csd ~ "se/clock03.wav",csd ~ "se/cursor01.wav"];
	let BGM=[csd ~ "bgm/title.wav",csd ~ "bgm/stage1.wav",csd ~ "bgm/stage1boss.wav",csd ~ "bgm/stage2.wav",csd ~ "bgm/stage2boss.wav",csd ~ "bgm/stage3.wav",csd ~ "bgm/stage3boss.wav",
		csd ~ "bgm/stage4.wav",csd ~ "bgm/stage4boss.wav",csd ~ "bgm/stage5.wav",csd ~ "bgm/stage5boss.wav",csd ~ "bgm/stage6.wav",csd ~ "bgm/stage6boss.wav"];

	let Hiscore=[];
	let Hiscore2=[];
	ascent(let k in 0..10)
	{
		Hiscore = Hiscore ~ [k];
		Hiscore2 = Hiscore2 ~ [k];
	}

	let SelectedDifficult="Difficult";
	let StageProgress=1;
	let StagePractice=false;

	let bgX=0;
	let bgX2=300;
	let bgY=0;
	let bgY2=300;
	let bgY3=300;
	let bgrt=0;
	let ViewFromX=300;
	let stage1alpha1=0;
	let stage1alpha2=0;
	let stage1alpha3=0;
	let stage1scale3=0;
	let StageChange=false;
	let stage2alpha1=0;
	let stage2alpha2=0;
	let stage3alpha=0;
	let stage4alpha1=0;
	let stage4alpha2=0;
	let stage5alpha1=0;
	let stage5alpha2=0;
	let stage6alpha1=0;
	let stage6alpha2=0;

	let ScoreNumber1=0;
	let ScoreNumber2=0;

	let UpTime;
	let PlayTime;

	let BGDrawing=1;
	let PracticeStartBurstCounter=0;
	let PracticeStartMagicCounter=0;
	let LightMode=0;
	let StartDifficult=0;
	let StartStage=0;

	#include_function ".\Config.txt"

	#include_function ".\txt\DifineMenuVariable.txt"//メニュー画面管理用の値の収納先

		task StageTask
		{
			yield;
			LifeAndBombDefine;
			PlayMusic(BGM[0]);
			UpTimeCount;//起動時間計測
			PlayTimeCount;//プレイ時間計測

	//		MenuEffect;//メニューの紅葉
			StageTitleDisplay;
			StatusDisplay;//文字を表示
			PlayerAndBombDisplay;//残機とボム表示
			ForbidShot(false);
			ForbidBomb(false);
			PlayCharacterAndDifficult;//使用キャラと難易度のプレイ回数の記録
			HiScoreLoad;//ハイスコアをロード
			DifficultDisplay;//難易度を表示
			DisPlayScore;//スコアを表示
//StageStartEffect;
			ExtendSystem;
			EnemyLifeDisplay;
			BossLifeSetting;
			TimeBonus;
			if(BGDrawing==1)
			{
				BGGraphicRect;//ステージ背景の矩形処理など
			}
			DeleteUsedFile;
			if(StageProgress==1)
			{
				SetCommonData("STAGEPROGRESS",1);
				Stage1;
				Stage1End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=1;
					wait(240);
					ClearStage;
				}
			wait(240);
			SetCommonData("SectionShift",true);
			StageProgress=2;
			}
			StageChange=false;

			if(StageProgress==2)
			{
				SetCommonData("STAGEPROGRESS",2);
				Stage2;
				Stage2End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=2;
					wait(240);
					ClearStage;
				}

			wait(240);
			StageProgress=3;
			}
			StageChange=false;

/*
			if(StageProgress==3)
			{
				Stage3;
				SetCommonData("STAGEPROGRESS",3);
				while(StageProgress==3){yield;}
				if(StagePractice==true)
				{
					StageProgress=3;
					wait(240);
					ClearStage;
				}
			wait(60);

			AddGraze(-GetGraze);
			}

			if(StageProgress==4)
			{
				Stage4;
				SetCommonData("STAGEPROGRESS",4);
				while(StageProgress==4){yield;}
				if(StagePractice==true)
				{
					StageProgress=4;
					wait(240);
					ClearStage;
				}
			DeleteGraphic(csd~"img\stage4bg.png");
			wait(60);

			AddGraze(-GetGraze);
			}

			if(StageProgress==5)
			{
				Stage5;
				SetCommonData("STAGEPROGRESS",5);
				while(StageProgress==5){yield;}
				if(StagePractice==true)
				{
					StageProgress=5;
					wait(240);
					ClearStage;
				}
			DeleteGraphic(csd~"img\stage5bg.png");
			wait(60);

			AddGraze(-GetGraze);
			}

			if(StageProgress==6)
			{
				Stage6;
				SetCommonData("STAGEPROGRESS",6);
				while(StageProgress==6){yield;}
				if(StagePractice==true)
				{
					StageProgress=6;
					wait(240);
					ClearStage;
				}
			SetCommonData("STAGECLEAR",true);
			wait(120);
			}
			CrearBonus;
			wait(600);
			if(Continued==false && StagePractice==false)
			{
				SetCommonDataEx(NsScore,"SecretFlag","true");
				SetCommonDataEx(NsScore,"ExFlag","true");
			}
*/
			ClearStage;
		}
	
		
		@Initialize()
		{
			SetCommonData("MagicalSingularDay",true);
			ExpertEx(false,1,3);

			CreateCommonDataArea(NsScore);
			SetCommonData(NsGetSpell,0);
			let isRep = IsReplay();
			LoadCommonDataEx(NsScore,savePathstage);
			if(isRep==false)
			{
		//		LoadCommonDataEx(NsScore,savePathstage);
			}
			else
			{
				LoadCommonDataFromReplayFile;
				StageState=Loading;
			}
			SetCommonData(NsIsReplay,isRep);
			SetCommonData(NsIsReplayJudgment,isRep);
			StageTask();
		}
	
		@MainLoop()
		{
			yield;
			AddGraze(-GetGraze);
			if(OnPlayerMissed)
			{
				SetCommonData("Playermissed",true);
			}
			else
			{
				SetCommonData("Playermissed",false);
			}

		}
		

		@DrawTopObject
		{
			SetTexture(imgBG);
			SetGraphicScale(30.0,30.0);
			SetGraphicRect(0,0,16,16);
			if(StageState==Menu || StageState==Loading || StageState==Exit)
			{
				SetGraphicAngle(0, 0, 0);
				SetViewTo(0,0,0);
				DrawGraphic(GetCenterX, GetCenterY);
			}
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsUpTime,0)),320,432,12,255);//起動時間の表示
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/60),320,452,12,255);//プレイ時間の表示
			//DrawText(StageState,120,432,12,255);//起動時間の表示
			//DrawText(DefinedPlayer1,120,452,12,255);//プレイ時間の表示
			//DrawText(SelectedCharacter,120,412,12,255);//起動時間の表示
			MenuDraw;
		}

		@Finalize()
		{
			SetCommonDataEx(NsScore,"ExFlag","true");
			SetCommonDataEx(NsScore,NsUpTime,UpTime);
			SetCommonDataEx(NsScore,NsPlayTime,PlayTime);
			HiScoreSave;
			if(GetCommonDataDefault(NsIsReplay,true) == false)
			{
				SaveCommonDataEx(NsScore,savePathstage);
			}
			ClearCommonDataEx(NsScore);
			DeleteCommonData(NsGetSpell);
			DeleteCommonData(NsDefeatFrame);
			DeleteCommonData(NsDefeatPosX);
			DeleteCommonData(NsDefeatPosY);
			DeleteCommonData(NsBossFrame);
			DeleteCommonData(NsIsReplay);
		}

		let bgAngle=90;
		let BossAdjust=0;

		@BackGround {
		BackGroundLoop;
	}



task LoadMenufile
{
	LoadGraphic(imgBG);
      	LoadGraphic(imgMenuLetter);
	//LoadGraphic(imgBer2);
      	LoadGraphic(imgNumber);
      	LoadGraphic(imgStatusLetter);
}

task LoadStagefile
{
	//LoadGraphic(imgBG);
      	//LoadGraphic(imgMenuLetter);
      	LoadGraphic(imgBer2);
      	LoadGraphic(imgNumber);
      	LoadGraphic(imgStatusLetter);
	if(BGDrawing==1)
	{
		LoadGraphic(csd~"img\st1bg1.png");
		LoadGraphic(csd~"img\cloud.png");
		LoadGraphic(csd~"img\st2bg1.png");
		LoadGraphic(csd~"img\st2bg2.png");
	}
	LoadGraphic(imgBer);
}

task DeleteUsedFile//もう使わないファイルをメモリから削除
{
//	DeleteGraphic(csd ~ "img\spellname.png");//もう使わないから破棄
//	DeleteGraphic(imgBG);//もう使わないから破棄
	wait(10);
	DeleteSE(MenuSE[0]);//もう使わないから破棄
	DeleteSE(MenuSE[1]);//もう使わないから破棄
//	wait(900);
	//DeleteGraphic(imgMenuEffect);//もう使わないから破棄
}	

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

sub LifeAndBombDefine//初期の残機とボムを設定（専用自機だから別にいらないが）
{
	while(GetPlayerLife<3)
	{
		ExtendPlayer(1);
	}
	while(GetPlayerBomb<3)
	{
		AddBomb(1);
	}
	while(GetPlayerLife>3)
	{
		ExtendPlayer(-1);
	}
	while(GetPlayerBomb>3)
	{
		AddBomb(-1);
	}
}

sub StageTitleDisplay//メニュー画面の表示、SecretSpell部分でも呼び出して再起している。
{
			SetCommonData("TitleMenu",true);

if(GetCommonData(NsIsReplayJudgment) == false && GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None")=="None")
{
	LoadMenufile;
			loop
			{
				alternative(StageState)	
				case(Menu)
				{
					TASK_MENU;
		 		}
				case(Exit)
				{
					StageState=Loading;
					SetCommonDataEx(NsScore,"SelectedDifficult",SelectedDifficult);
					SetCommonDataEx(NsScore,"StagePractice",StagePractice);
					SetCommonDataEx(NsScore,"StageProgress",StageProgress);
					SaveCommonDataEx(NsScore,savePath);//Select&Levelを保存
					wait(5);
					Retry;
					break;
		 		}
				others{}
			yield;
			}
}
else
{
	LoadStagefile;

	StageState=Start;
	if(GetCommonData(NsIsReplayJudgment) == false)
	{
	SelectedDifficult=GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None");
	StagePractice=GetCommonDataDefaultEx(NsScore,"StagePractice",false);
	StageProgress=GetCommonDataDefaultEx(NsScore,"StageProgress",1);

	SetCommonDataEx(NsScore,"SelectedDifficult",SelectedDifficult);
	SetCommonData("SelectedDifficult",SelectedDifficult);
	SetCommonDataEx(NsScore,"StagePractice",StagePractice);
	SetCommonData("StagePractice",StagePractice);
	SetCommonDataEx(NsScore,"StageProgress",StageProgress);
	SetCommonData("StageProgress",StageProgress);

		if(StagePractice)
		{
			SetCommonData("PracticeStartBurstCounter",PracticeStartBurstCounter);
			SetCommonData("PracticeStartMagicCounter",PracticeStartMagicCounter);
		}
		else
		{
			SetCommonData("PracticeStartBurstCounter",0);
			SetCommonData("PracticeStartMagicCounter",0);
		}

	SaveCommonDataInReplayFile;
	SetCommonDataEx(NsScore,"SelectedDifficult","None");
	SetCommonDataEx(NsScore,"StagePractice","None");
	SetCommonDataEx(NsScore,"StageProgress","None");
	}

	else
	{
	SelectedDifficult=GetCommonDataDefault("SelectedDifficult","None");
	StagePractice=GetCommonDataDefault("StagePractice","None");
	StageProgress=GetCommonDataDefault("StageProgress",1);
	SetCommonData(NsIsReplayJudgment,false);
	}
}
			ForbidShot(false);
			SetCommonData("TitleMenu",false);


			ForbidBomb(false);

		SetCommonData("LightMode",LightMode);

		SetCommonData("MSDSetting",true);
}

task ExtendSystem//エクステンドの設定
{
	while(ScoreNumber2<1000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<10000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<100000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
}

task TimeBonus
{
let x=GetCenterX;
let y=GetCenterY-64;
loop
{
	if(GetCommonDataDefault("TimeBonus",0)>0)
	{
		let BossRate=GetCommonDataDefault("BossRate",0);
		let Rate=GetCommonDataDefault("TimeBonus",0)*100000;
		let MagicCounter=GetCommonData("SECTIONMAGICFRAGMENT");

		AddScore(BossRate*Rate*MagicCounter/100000);
		ascent(let i in 0..30)
		{
		TimeBonusDisplay(x,y-40,255*i/30,255,255,255);
		BossRateNumDisplay(x-40,y,BossRate,255*i/30,255,255,255);
		TimeBonusNumDisplay(x+60,y,Rate,255*i/30,255,255,255);
		KakeruDisplay(x-20,y,255*i/30,255,255,255);
		PercentDisplay(x+80,y,255*i/30,255,255,255);
		y-=0.2;
		yield;
		}
		loop(60)
		{
		TimeBonusDisplay(x,y-40,255,255,255,255);
		BossRateNumDisplay(x-40,y,BossRate,255,255,255,255);
		TimeBonusNumDisplay(x+60,y,Rate,255,255,255,255);
		KakeruDisplay(x-20,y,255,255,255,255);
		PercentDisplay(x+80,y,255,255,255,255);
		y-=0.2;
		yield;

		}	
		descent(let i in 0..30)
		{
		TimeBonusDisplay(x,y-40,255*i/30,255,255,255);
		BossRateNumDisplay(x-40,y,BossRate,255*i/30,255,255,255);
		TimeBonusNumDisplay(x+60,y,Rate,255*i/30,255,255,255);
		KakeruDisplay(x-20,y,255*i/30,255,255,255);
		PercentDisplay(x+80,y,255*i/30,255,255,255);
		y-=0.2;
		yield;
		}
	SetCommonData("TimeBonus",0);
	x=GetCenterX;
	y=GetCenterY-64;
	}
yield;
}
}

task TimeBonusDisplay(x,y,Alpha,R,G,B)//Apocalypseを表示
{
		let scx=0.4;
		let scy=0.4;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgStatusLetter);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -201, -18);
		ObjEffect_SetVertexXY(obj, 1,201,  -18);
		ObjEffect_SetVertexXY(obj, 2,201, 18);
		ObjEffect_SetVertexXY(obj, 3,  -201,  18);
		
		ObjEffect_SetVertexUV(obj, 0,  12,  120);
		ObjEffect_SetVertexUV(obj, 1,  414, 120);
		ObjEffect_SetVertexUV(obj, 2, 414, 156);
		ObjEffect_SetVertexUV(obj, 3, 12, 156);

		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,x,y+5);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}
//////////////////////////////////////////////////////////
task StageStartEffect//ライフバーのバー部分の設定
{
	let BossLifeMax=GetEnemyLife;
	let scaleX=0;
	let scaleY=0;
	let MX=(GetClipMaxX-GetCenterX)/25;
	let MY=(GetClipMaxY-GetCenterY)/25;
	let ZAngle=90;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"img\sub.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, SUBTRACT); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -512, -512);
		ObjEffect_SetVertexXY(obj, 1, 512,  -512);
		ObjEffect_SetVertexXY(obj, 2, 512, 512);
		ObjEffect_SetVertexXY(obj, 3, -512,  512);

		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  1024, 0);
		ObjEffect_SetVertexUV(obj, 2, 1024,  1024);
		ObjEffect_SetVertexUV(obj, 3, 0, 1024);
		ObjEffect_SetLayer(obj,7);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,255,255,255,255);
		}

		Obj_SetPosition(obj,GetCenterX,GetCenterY);
		ObjEffect_SetAngle(obj,0,0,ZAngle);

		loop(61)
		{
			ZAngle-=-90/60;
			scaleX+=MX/60;
			scaleY+=MY/60;
		//	ObjEffect_SetScale(obj, 1,1);
			ObjEffect_SetScale(obj, scaleX,scaleY);
			ObjEffect_SetAngle(obj,0,0,ZAngle);
			yield;
		}
		Obj_Delete(obj);
}
////////////////////////////////////////////////////////////////////////
////////////////////////エネミーライフ部////////////////////////////////
//////////////////////////////////////////////////////////////////////////

task EnemyLifeDisplay//下部に敵のライフを表示
{
loop
{
if(IsBossExisting==true && GetEnemyLife>1)
{
BossLifeBerDisplay;
BossLifeDisplay;
while(GetEnemyLife>1){yield}
}
yield;
}
}

task BossLifeBerDisplay//ライフバーの枠の設定
{
	let BossLifeMax=GetEnemyLife;
	let scale=2.5;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -71, -8);
		ObjEffect_SetVertexXY(obj, 1, 71,  -8);
		ObjEffect_SetVertexXY(obj, 2, 71, 8);
		ObjEffect_SetVertexXY(obj, 3,  -71,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  11);
		ObjEffect_SetVertexUV(obj, 1,  148, 11);
		ObjEffect_SetVertexUV(obj, 2, 148,  21);
		ObjEffect_SetVertexUV(obj, 3, 6, 21);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj, 2.5,0.8);
		Obj_SetPosition(obj,GetCenterX,GetClipMaxY+8);

		while(GetEnemyLife>1)
		{
			if(GetCommonDataDefault("BOSSDEFEAT",false)){break;}
			yield;
		}
		loop(60)
		{
			ObjEffect_SetScale(obj, scale,0.8);
			scale-=2.5/60;
			yield;
		}
		SetCommonData("BOSSDEFEAT",false);
		Obj_Delete(obj);
}


task BossLifeDisplay//ライフバーのバー部分の設定
{
	let BossLifeMax=GetEnemyLife;
	let scale=2.5;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer2);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -5);
		ObjEffect_SetVertexXY(obj, 1, 142,  -5);
		ObjEffect_SetVertexXY(obj, 2, 142, 5);
		ObjEffect_SetVertexXY(obj, 3,  0,  5);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  148, 27);
		ObjEffect_SetVertexUV(obj, 2, 148,  33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj, scale,0.8);

		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,120,255,200,255);
		}

		Obj_SetPosition(obj,GetCenterX-177,GetClipMaxY+8);

		while(GetEnemyLife>1)
		{
			scale=2.5*GetEnemyLife/BossLifeMax;
			ObjEffect_SetScale(obj, scale,0.8);
			yield;
		}
		Obj_Delete(obj);
}

////////////////////////////////////////////////////////////////////////////////////////////
//////////////////時間計測、回数記録部,初期ボーナス部/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
		task UpTimeCount//起動時間の計測
		{
			UpTime=GetCommonDataDefaultEx(NsScore,NsUpTime,0);
			loop
			{
				UpTime++;
				wait(60);
			}
		}

		task PlayTimeCount//プレイ時間の計測
		{
			PlayTime=GetCommonDataDefaultEx(NsScore,NsPlayTime,0);
			loop
			{
				if(StageState!=Menu)
				{
				PlayTime++;
				}
				wait(60);
			}
		}

		task PlayCharacterAndDifficult//プレイ回数を増やし難易度を決定
		{
			alternative(SelectedDifficult)
			case("Moderate")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuAEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuAEasy,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBEasy,Frequency);		
				}
			}
			case("Extream")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuANormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuANormal,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBNormal,Frequency);		
				}
			}
			case("Apocalypse")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuAHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuAHard,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBHard,Frequency);		
				}
			}
			SetCommonData("SELECTEDDIFFICULT",SelectedDifficult);//選択難易度を受け渡すため保存
		}
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////ステータス表示部//////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
task DifficultDisplay//難易度を表示
{
	alternative(SelectedDifficult)
	case("Moderate")
	{
		ascent(let i in 0..60)
		{
		ModerateDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		ModerateDisplay(530,20,255,255,255,255);
		yield;
		}
	}
	case("Extream")
	{
		ascent(let i in 0..60)
		{
		ExtreamDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		ExtreamDisplay(530,20,255,255,255,255);
		yield;
		}
	}
	case("Apocalypse")
	{
		ascent(let i in 0..60)
		{
		ApocalypseDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		ApocalypseDisplay(530,20,255,255,255,255);
		yield;
		}
	}
}

task StatusDisplay//Hiscoreから霊点までの文字を表示
{
loop
{
		StatusHighScoreDisplay(530,60,255,255,255,255);
		StatusScoreDisplay(530,110,255,255,255,255);
		StatusMagicCounterDisplay(530,160,255,255,255,255);
		StatusFragmentDisplay(530,210,255,255,255,255);
	//	PercentDisplay(610,233,255,255,255,255);
		StatusPlayerDisplay(470,290,255,255,255,255);
		StatusBombDisplay(470,320,255,255,255,255);
		yield;

}
}

task PlayerAndBombDisplay//残機と残ボムを星で表示
{
let life;
let bomb;
loop
{
	life=GetPlayerLife-1;
	if(life>8)
	{
		life=8;
	}
	bomb=GetPlayerBomb;
	if(bomb>8)
	{
		bomb=8;
	}
	ascent(let i in 0..life)
	{
		DisPlayPlayerStar(i);
	}
	ascent(let i in 0..bomb)
	{
		DisPlayBombStar(i);
	}
		
yield;
}
}

task DisPlayPlayerStar(i)//残機を表示
{
		let scx=0.4;
		let scy=0.4;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgStatusLetter);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -21, -18);
		ObjEffect_SetVertexXY(obj, 1,21,  -18);
		ObjEffect_SetVertexXY(obj, 2,21, 18);
		ObjEffect_SetVertexXY(obj, 3,  -21,  18);
		
		ObjEffect_SetVertexUV(obj, 0,  11,  167);
		ObjEffect_SetVertexUV(obj, 1,  53, 167);
		ObjEffect_SetVertexUV(obj, 2, 53, 207);
		ObjEffect_SetVertexUV(obj, 3, 11, 207);

		ObjEffect_SetVertexColor(obj,0,255,255,200,200);
		ObjEffect_SetVertexColor(obj,1,255,255,200,200);
		ObjEffect_SetVertexColor(obj,2,255,255,200,200);
		ObjEffect_SetVertexColor(obj,3,255,255,200,200);

		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,GetClipMaxX+105+16*i,293);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

task DisPlayBombStar(i)//残ボムを表示
{
		let scx=0.4;
		let scy=0.4;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgStatusLetter);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -21, -18);
		ObjEffect_SetVertexXY(obj, 1,21,  -18);
		ObjEffect_SetVertexXY(obj, 2,21, 18);
		ObjEffect_SetVertexXY(obj, 3,  -21,  18);
		
		ObjEffect_SetVertexUV(obj, 0,  11,  167);
		ObjEffect_SetVertexUV(obj, 1,  53, 167);
		ObjEffect_SetVertexUV(obj, 2, 53, 207);
		ObjEffect_SetVertexUV(obj, 3, 11, 207);

		ObjEffect_SetVertexColor(obj,0,255,200,255,200);
		ObjEffect_SetVertexColor(obj,1,255,200,255,200);
		ObjEffect_SetVertexColor(obj,2,255,200,255,200);
		ObjEffect_SetVertexColor(obj,3,255,200,255,200);

		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,GetClipMaxX+105+16*i,323);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

task DisPlayScore//ハイスコアを呼び出し、ハイスコアと現スコアを表示
{
let EachHiScore=0;
let EachHiScore2=0;
	alternative(SelectedDifficult)
	case("Moderate")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAEasy[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAEasy2[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBEasy[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBEasy2[0],0);
		}
	}
	case("Extream")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuANormal[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuANormal2[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBNormal[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBNormal2[0],0);
		}
	}
	case("Apocalypse")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAHard[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAHard2[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBHard[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBHard2[0],0);
		}
	}
CreateScore(EachHiScore,EachHiScore2);

}

function CreateScore(let EachHiScore,let EachHiScore2)//GetScore関数から二つにわけた変数に記録し擬似的に桁を増やしている
{
	continucount;
loop
{
	ScoreNumber1+=GetScore;
	AddScore(-GetScore);

	loop(10)
	{
		if(ScoreNumber1>=1000000)
		{
			ScoreNumber2+=1;
			ScoreNumber1-=1000000;
		}
	}

	if(EachHiScore2>ScoreNumber2)
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,EachHiScore,EachHiScore2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,EachHiScore2,0);
	}
	else if(EachHiScore2==ScoreNumber2)
	{
		if(EachHiScore>ScoreNumber1)
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,EachHiScore,EachHiScore2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,EachHiScore2,0);
		}
		else
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,ScoreNumber2,0);
		}
	}
	else
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,ScoreNumber2,0);
	}

	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,ScoreNumber2,0);
yield;
}
}

task continucount//コンテしたらスコアを0にする
{
	while(Continued==false)
	{
		yield;
	}
	ScoreNumber2=0;
	ScoreNumber1=0;
}

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////インクルード部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#include_function ".\txt/stagedata.txt"
#include_function ".\txt/StageMenuLetter.txt"
#include_function ".\txt/StatusLetter.txt"
#include_function ".\txt/hiscore.txt"
#include_function ".\txt/BossLife.txt"
#include_function ".\txt/MENU.txt"
#include_function ".\txt/MENUDRAW.txt"
#include_function ".\stage1/STAGE1.txt"
#include_function ".\stage2/STAGE2.txt"
#include_function ".\stage3/STAGE3.txt"
#include_function ".\stage4/STAGE4.txt"
#include_function ".\stage5/STAGE5.txt"
#include_function ".\stage6/STAGE6.txt"
#include_function ".\txt/BackGround.txt"

}