function HueDifine(HueCount)
{
let ColorRed=0;
let ColorGreen=0;
let ColorBlue=0;
let MinColor=0;
while(HueCount>360){HueCount-=360;}
while(HueCount<=0){HueCount+=360;}
	if(0<HueCount && HueCount<=60)
	{
		ColorRed=255;
		ColorGreen=255*(HueCount)/60;
		ColorBlue=0;
	}
	else if(HueCount<=120)
	{
		ColorRed=255*(120-HueCount)/60;
		ColorGreen=255;
		ColorBlue=0;
	}
	else if(HueCount<=180)
	{
		ColorRed=0;
		ColorGreen=255;
		ColorBlue=255*(HueCount-120)/60;
	}
	else if(HueCount<=240)
	{
		ColorRed=0;
		ColorGreen=255*(240-HueCount)/60;
		ColorBlue=255;
	}
	else if(HueCount<=300)
	{
		ColorRed=255*(HueCount-240)/60;
		ColorGreen=0;
		ColorBlue=255;
	}
	else if(HueCount<=360)
	{
		ColorRed=255;
		ColorGreen=0;
		ColorBlue=255*(360-HueCount)/60;
	}
	return([ColorRed,ColorGreen,ColorBlue]);
}

task LoadMenufile
{
	LoadGraphic(imgTitle);
	LoadGraphic(imgBG);
	LoadGraphic(imgWhite);
	LoadGraphic(imgBlack);
      	LoadGraphic(imgMenuLetter);
	//LoadGraphic(imgBer2);
      	LoadGraphic(imgNumber);
      	//LoadGraphic(imgStatusLetter);
	LoadGraphic(imgAchievement);
	LoadGraphic(imgTitleSquareLine);

	LoadGraphic(imgCircleLine);
	LoadGraphic(imgCrossLine);
	LoadGraphic(imgSquareLine);
	LoadGraphic(imgMinusLine);
	LoadGraphic(imgDeltaLine);
	LoadGraphic(imgDoubleCircleLine);
	LoadGraphic(imgStarLine);
	LoadGraphic(imgCircleCrossLine);
}

task LoadStagefile
{
	LoadGraphic(imgTitle);
	LoadGraphic(imgWhite);
	//LoadGraphic(imgBG);
      	//LoadGraphic(imgMenuLetter);
      	LoadGraphic(imgBer2);
      	LoadGraphic(imgNumber);
      	LoadGraphic(imgStatusLetter);
      	LoadGraphic(imgStatusStar);
	LoadGraphic(imgCircleEffect);
	LoadGraphic(imgBreakCircleEffect);
      	LoadGraphic(imgItem);
      	LoadGraphic(imgDoll);
	if(BGDrawing==1)
	{
		LoadGraphic(csd~"img\White.png");
		LoadGraphic(csd~"img\Black.png");

		if(!StagePractice || StageProgress==1)
		{
		LoadGraphic(csd~"img\sky.png");
		LoadGraphic(csd~"img\mountains.png");
		LoadGraphic(csd~"img\st1bg1.png");
		LoadGraphic(csd~"img\cloud.png");
		}

		if(!StagePractice || StageProgress==2)
		{
		LoadGraphic(csd~"img\st2bg2.png");
		LoadGraphic(csd~"img\MountainChip.png");
		LoadGraphic(csd~"img\0024.png");
		LoadGraphic(csd~"img\moon.png");
		LoadGraphic(csd~"img\st4bg1.png");
		}

		if(!StagePractice || StageProgress==3)
		{
		LoadGraphic(csd~"img\cloud2.png");
		LoadGraphic(csd~"img\st3bg1.png");
		LoadGraphic(csd~"img\MountainChip2.png");
		LoadGraphic(csd~"img\st3cloudshadow.png");
		LoadGraphic(csd~"img\st3cloud.png");
		}

		if(!StagePractice || StageProgress==4)
		{
		LoadGraphic(csd~"img\st4bg1.png");
		LoadGraphic(csd~"img\st4bg2.png");
		}

		if(!StagePractice || StageProgress==5)
		{
		LoadGraphic(csd~"img\st5bg1.png");
		LoadGraphic(csd~"img\MagicDust.png");
		LoadGraphic(csd~"img\s0145.png");
		LoadGraphic(csd~"img\circle.png");
		LoadGraphic(csd~"img\Sphere.png");
		LoadGraphic(csd~"img\Pillar1.png");
		LoadGraphic(csd~"img\Pillar2.png");
		LoadGraphic(csd~"img\gradient.png");
		LoadGraphic(csd~"img\circlelight.png");
		}
	}
	LoadGraphic(imgBer);
	if(IsReplay)
	{
      	LoadGraphic(imgSpell);
	}
	LoadGraphic(imgIneDeltaLine);
	LoadGraphic(imgTitleSquareLine);
	LoadGraphic(imgMagicEffect);
	LoadGraphic(imgLight);
	LoadGraphic(imgCircleBorder);
	LoadGraphic(imgEffects);
}


task DeleteUsedFile//もう使わないファイルをメモリから削除
{
	wait(10);
	DeleteSE(MenuSE[0]);//もう使わないから破棄
	DeleteSE(MenuSE[1]);//もう使わないから破棄
}	



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

sub ClearBonus
{
	LoadGraphic(imgMenuLetter);
	LoadGraphic(csd~"img\Clear.png");
	let OptionPenalty=1;
	let DifficultBonus=1;
	alternative(SelectedDifficult)
	case("Moderate"){DifficultBonus=1.0;}
	case("Extream"){DifficultBonus=1.5;}
	case("Apocalypse"){DifficultBonus=2.0;}
	if(InitialLife>3 || InitialBomb>3){OptionPenalty=0.1;}
	let Fragment=GetCommonDataDefault("MAGICFRAGMENT",0);
	let FragmentScore=Fragment*10*OptionPenalty*DifficultBonus;
	let RestPlayerScore=100000*OptionPenalty*DifficultBonus;
	let RestBombScore=20000*OptionPenalty*DifficultBonus;

	let TotalScore=FragmentScore+RestPlayerScore*(GetPlayerLife-1)+(RestBombScore*GetPlayerBomb);

	Display;

	wait(60);

	loop(100)
	{
		AddScore(TotalScore*10);
		yield;
	}
	wait(80);


	wait(120);
	task Display
	{
		ascent(i in 0..30)
		{
			if(GetCommonDataDefault("TrueBossFlag",false))
			{
			TrueClearDisplay(GetCenterX,GetCenterY-135,255*i/30,255,255,255);
			}
			else
			{
			ClearDisplay(GetCenterX,GetCenterY-135,255*i/30,255,255,255);
			}
			ClearBonusDisplay(GetCenterX,GetCenterY-90,255*i/30,255,255,255);

			ClearBonusDisPlayScoreNumber(GetCenterX,GetCenterY-45,TotalScore,255*i/30);

			yield;
		}

		loop(180)
		{
			if(GetCommonDataDefault("TrueBossFlag",false))
			{
			TrueClearDisplay(GetCenterX,GetCenterY-135,255,255,255,255);
			}
			else
			{
			ClearDisplay(GetCenterX,GetCenterY-135,255,255,255,255);
			}
			ClearBonusDisplay(GetCenterX,GetCenterY-90,255,255,255,255);

			ClearBonusDisPlayScoreNumber(GetCenterX,GetCenterY-45, TotalScore,255);

			yield;
		}
		descent(i in 0..30)
		{
			if(GetCommonDataDefault("TrueBossFlag",false))
			{
			TrueClearDisplay(GetCenterX,GetCenterY-135,255*i/30,255,255,255);
			}
			else
			{
			ClearDisplay(GetCenterX,GetCenterY-135,255*i/30,255,255,255);
			}
			ClearBonusDisplay(GetCenterX,GetCenterY-90,255*i/30,255,255,255);

			ClearBonusDisPlayScoreNumber(GetCenterX,GetCenterY-45,TotalScore,255*i/30);

			yield;
		}
	}

}

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

	if(GetCommonData(NsIsReplayJudgment) == false && GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None")=="None")
	{
		PlayMusic(BGM[0]);
		LoadMenufile;
		TitleEffect;
		loop
		{
			alternative(StageState)	
			case(Menu)
			{
				TASK_MENU;
		 	}
			case(Exit)
			{//メニュー画面で設定した値の保存
				FadeOutMusic(BGM[0],20);
				StageState=Loading;
				StageStartSignal=true;
				StageStartEffect;
				wait(120);

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

				wait(1);
				Retry;
		 	}
			others{}
		yield;
		}
	}
	else
	{
		LoadStagefile;
		PlayStartWhite;
		StageState=Start;
		if(GetCommonData(NsIsReplayJudgment) == false)
		{
			SelectedDifficult=GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None");
			StagePractice=GetCommonDataDefaultEx(NsScore,"StagePractice",false);
			StageProgress=GetCommonDataDefaultEx(NsScore,"StageProgress",1);
			StagePhaseProgress=GetCommonDataDefaultEx(NsScore,"StagePhaseProgress",0);

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

			SetCommonDataEx(NsScore,"AutoBombMode",AutoBombMode);
			SetCommonData("AutoBombMode",AutoBombMode);
			SetCommonDataEx(NsScore,"InitialLife",InitialLife);
			SetCommonData("InitialLife",InitialLife);
			SetCommonDataEx(NsScore,"InitialBomb",InitialBomb);
			SetCommonData("InitialBomb",InitialBomb);


			if(StagePractice)
			{
				if(StageProgress==1 && StagePhaseProgress==0)
				{
					SetCommonData("PracticeStartBurstCounter",0);
					SetCommonData("PracticeStartMagicCounter",0);
					SetCommonData("PracticeStartBurstRank",0);
					SetCommonData("PracticeStartRushGauge",0);
				}
				else
				{
				SetCommonData("PracticeStartBurstCounter",PracticeStartBurstCounter);
				SetCommonData("PracticeStartMagicCounter",PracticeStartMagicCounter);
				SetCommonData("PracticeStartBurstRank",PracticeStartBurstRank);
				SetCommonData("PracticeStartRushGauge",PracticeStartRushGauge);
				}
			}
			else
			{
				SetCommonData("PracticeStartBurstCounter",0);
				SetCommonData("PracticeStartMagicCounter",0);
				SetCommonData("PracticeStartBurstRank",0);
				SetCommonData("PracticeStartRushGauge",0);
			}

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

		else
		{
			SelectedDifficult=GetCommonDataDefault("SelectedDifficult","None");
			StagePractice=GetCommonDataDefault("StagePractice","None");
			StageProgress=GetCommonDataDefault("StageProgress",1);
			StagePhaseProgress=GetCommonDataDefault("StagePhaseProgress",0);

			AutoBombMode=GetCommonDataDefault("AutoBombMode",0);
			InitialLife=GetCommonDataDefault("InitialLife",0);
			InitialBomb=GetCommonDataDefault("InitialBomb",0);

			SetCommonData(NsIsReplayJudgment,false);
		}
	}
	ForbidShot(false);
	SetCommonData("TitleMenu",false);


	ForbidBomb(false);

	SetCommonData("LightMode",LightMode);

	if(LightMode==1)
	{
		LightMode_HiscoreDraw=1;
		LightMode_PlayerIntervalEffect=1;
		LightMode_ShotEffect=1;
		LightMode_BombEffect=1;
		LightMode_PlayerBlur=1;
		LightMode_BossBlur=1;
		LightMode_ElementalBlur=1;
		LightMode_SpecialEffect=1;
		LightMode_BreakEffect=1;
	}

	SetCommonData("LightMode_PlayerIntervalEffect",LightMode_PlayerIntervalEffect);
	SetCommonData("LightMode_BombEffect",LightMode_BombEffect);
	SetCommonData("LightMode_ShotEffect",LightMode_ShotEffect);
	SetCommonData("LightMode_PlayerBlur",LightMode_PlayerBlur);
	SetCommonData("LightMode_BossBlur",LightMode_BossBlur);
	SetCommonData("LightMode_ElementalBlur",LightMode_ElementalBlur);
	SetCommonData("LightMode_SpecialEffect",LightMode_SpecialEffect);
	SetCommonData("LightMode_BreakEffect",LightMode_BreakEffect);

	SetCommonData("MSDSetting",true);

}

task StageRestart
{
let RestartCount=0;
let TempStageProgress=StageProgress;
let TempStagePhaseProgress=StagePhaseProgress;
loop
{
	if(GetKeyState(VK_SKIP)==KEY_HOLD)
	{
		RestartCount+=1;
	}
	else
	{
		RestartCount=0;
	}
	if(RestartCount>=60)
	{
		StageStartWhite;
		CreateEnemyFromFile(csd~"SystemEnemy/Invincibility.txt",GetClipMaxX+16,GetCenterY-128,2,90,1);
		wait(58);
		SetCommonDataEx(NsScore,"SelectedDifficult",SelectedDifficult);
		SetCommonDataEx(NsScore,"StagePractice",StagePractice);
		SetCommonDataEx(NsScore,"StageProgress",TempStageProgress);
		SetCommonDataEx(NsScore,"StagePhaseProgress",TempStagePhaseProgress);
		wait(2);
		Retry;
	}
yield;
}
}

task ExtendSystem//エクステンドの設定
{
	while(ScoreNumber2<1000 || MSDClear){yield;}
	if(StageProgress==1)
	{
		SetCommonDataEx(NsScore,NsAchievement[52],1);
	}
	if(GetPlayerLife==1 && GetPlayerBomb==0)
	{
		SetCommonDataEx(NsScore,NsAchievement[74],1);
	}
	Ah_DoubleExtendCheck;
	ExtendNum+=1;
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<3000 || MSDClear){yield;}
	if(GetPlayerLife==1 && GetPlayerBomb==0)
	{
		SetCommonDataEx(NsScore,NsAchievement[74],1);
	}
	Ah_DoubleExtendCheck;
	ExtendNum+=1;
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<6000 || MSDClear){yield;}
	if(GetPlayerLife==1 && GetPlayerBomb==0)
	{
		SetCommonDataEx(NsScore,NsAchievement[74],1);
	}
	Ah_DoubleExtendCheck;
	ExtendNum+=1;
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<10000 || MSDClear){yield;}
	if(GetPlayerLife==1 && GetPlayerBomb==0)
	{
		SetCommonDataEx(NsScore,NsAchievement[74],1);
	}
	Ah_DoubleExtendCheck;
	ExtendNum+=1;
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<15000 || MSDClear){yield;}
	if(GetPlayerLife==1 && GetPlayerBomb==0)
	{
		SetCommonDataEx(NsScore,NsAchievement[74],1);
	}
	Ah_DoubleExtendCheck;
	ExtendNum+=1;
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
}

task LifeExtendEffectSystem
{
	LifeExtendEffect;
}

task LifeExtendEffect
{
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj,imgLight);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_CreateVertex(obj, 4);

	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,  64, 0);
	ObjEffect_SetVertexUV(obj, 2, 64, 64);
	ObjEffect_SetVertexUV(obj, 3, 0,  64);

	let Alpha=255;
	let R=255;let G=50;let B=50;
	ascent(let i in 0..4)
	{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
	}

	let x=GetClipMaxX+96+8+(GetPlayerLife-1)*16;
	Obj_SetPosition(obj,x,165);

	ObjEffect_SetLayer(obj,8);

	let Zangle=rand(0,360);
	ObjEffect_SetAngle(obj,0,0,Zangle);

	let Scale=0.0;

	OnLifeExtend=true;
	loop(30)
	{
		ObjEffect_SetScale(obj, Scale, Scale);
		ObjEffect_SetAngle(obj,0,0,Zangle);
		Zangle+=6;
		Scale+=0.5/30;
		yield;
	}
	OnLifeExtend=false;
	loop(30)
	{
		ObjEffect_SetScale(obj, Scale, Scale);
		ObjEffect_SetAngle(obj,0,0,Zangle);
		ascent(let i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Zangle+=6;
		Scale+=0.5/30;
		Alpha-=255/30;
		yield;
	}
	Obj_Delete(obj);
}

task TimeBonus
{
let x=GetCenterX;
let y=GetCenterY-64;
loop
{
	if(GetCommonDataDefault("TimeBonus",0)>0)
	{
		let BossRate=GetCommonDataDefault("BossRate",0)/10000;
		let Rate=GetCommonDataDefault("TimeBonus",0);
		let MagicCounter=GetCommonDataDefault("SECTIONMAGICFRAGMENT",0);
		if(GetCommonDataDefault("MSDPlayer",false)==true && GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Arrange")
		{
			BossDefeatAddScore(BossRate*Rate*MagicCounter);
		}
		else if(GetCommonDataDefault("MSDPlayer",false)==false && GetCommonDataDefault("SELECTEDDIFFICULT","None")!="Arrange")
		{
			BossRate/=5;
			BossDefeatAddScore(BossRate*Rate*MSDSectionScoreItemCount);
		}
		else if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Arrange")
		{
			BossDefeatAddScore(BossRate*Rate*StageMultiply);
		}
//////////////////////////////////////////////////////
TimeBonusDisplay(x,y-40,255,255,255,255);

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

		}	
		descent(let i in 0..15)
		{
	//	TimeBonusDisplay(x,y-40,255*i/30,255,255,255);
		BossRateNumDisplay(x-40,y,BossRate*10000,255*i/15,255,255,255,2-i/15,i/15);
		TimeBonusNumDisplay(x+60,y,Rate*100000,255*i/15,255,255,255,2-i/15,i/15);
		KakeruDisplay(x-20,y,255*i/15,255,255,255,2-i/15,i/15);
		PercentDisplay(x+80,y,255*i/15,255,255,255,2-i/15,i/15);
		y-=0.2;
		yield;
		}
///////////////////////////////////////////////////////////////////
	SetCommonData("TimeBonus",0);
	x=GetCenterX;
	y=GetCenterY-64;
	}
yield;
}
	task BossDefeatAddScore(Score)
	{
		let ScorePlus=0;
		let Score2Plus=0;
		if(Score>=10000)
		{
			Score2Plus=trunc(Score/10000)
		}
		ScorePlus=Score%10000;
		loop(100)
		{
			AddScore(ScorePlus*100*FragmentMultiply);
			ScoreNumber2+=Score2Plus*FragmentMultiply;
			yield;
		}
	}
}

task TimeBonusDisplay(x,y,Alpha,R,G,B)//Apocalypseを表示
{
		let Alpha=0;
		let scx=2.0;
		let scy=1.0;
		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, -101, -10);
		ObjEffect_SetVertexXY(obj, 1,101,  -10);
		ObjEffect_SetVertexXY(obj, 2,101, 10);
		ObjEffect_SetVertexXY(obj, 3,  -101,  10);
		
		ObjEffect_SetVertexUV(obj, 0,  1,  58);
		ObjEffect_SetVertexUV(obj, 1,  203, 58);
		ObjEffect_SetVertexUV(obj, 2, 203, 78);
		ObjEffect_SetVertexUV(obj, 3, 1, 78);

		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

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

		ObjEffect_SetScale(obj, scx,scy);

		loop(15)
		{
		Obj_SetPosition(obj,x,y+5);
		ObjEffect_SetScale(obj, scx,scy);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		y-=0.2;
		Alpha+=255/15;
		scx-=1/15;
		yield;
		}
		loop(90)
		{
		Obj_SetPosition(obj,x,y+5);
		ObjEffect_SetScale(obj, scx,scy);
		y-=0.2;
		yield;
		}
		loop(15)
		{
		Obj_SetPosition(obj,x,y+5);
		ObjEffect_SetScale(obj, scx,scy);
		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		y-=0.2;
		Alpha-=255/15;
		scx+=1/15;
		scy-=1/15;
		yield;
		}
		Obj_Delete(obj);

/*
		let scx=1.0;
		let scy=1.0;
		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, -101, -10);
		ObjEffect_SetVertexXY(obj, 1,101,  -10);
		ObjEffect_SetVertexXY(obj, 2,101, 10);
		ObjEffect_SetVertexXY(obj, 3,  -101,  10);
		
		ObjEffect_SetVertexUV(obj, 0,  1,  58);
		ObjEffect_SetVertexUV(obj, 1,  203, 58);
		ObjEffect_SetVertexUV(obj, 2, 203, 78);
		ObjEffect_SetVertexUV(obj, 3, 1, 78);

		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 BalanceCheckMain
{
loop
{
	if(GetKeyState(VK_USER)==KEY_PUSH)
	{
		BalanceCheck;
	}
	yield;
}

task BalanceCheck
{
	let CheckFlag=true;
	let EraseShot=0;

	wait(180);
	CheckShot;
	wait(600);
	CheckFlag=false;

task CheckShot
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
	//Obj_SetSpeed(obj, speed);
	//Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 9);
	//ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	//Obj_SetAutoDelete(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAlpha(obj,0);
	ObjShot_ToItem(obj,false);
	while(!Obj_BeDeleted(obj))
	{
	Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
		yield;
	}
	EraseShot+=1;
	if(EraseShot>=120)
	{
		SetCommonData("BalanceBreak",true);
	}

	if(CheckFlag==true && !OnBomb && GetTimeOfPlayerInvincibility==0)
	{
		CheckShot;
	}
}

}

}

//////////////////////////////////////////////////////////

task CheckExtendItem
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
//let ItemPerFrame=60;//１フレームあたりの最大アイテム生成数（処理落ち対策）
loop
{
	ItemCheck=length(GetCommonDataDefault("ExtendItem",[]));//毎フレーム共通データの長さチェック
	if(ItemCheck>0)
	{//配列に中身がある（アイテム発生フラグ立っている）場合の処理
		loop
		{
			XY=GetCommonDataDefault("ExtendItem",[]);//共通データ内容を変数に渡す

			CreateExtendItem(XY[0],XY[1],XY[2]);//アイテム生成。順番にX座標、Y座標、アイテムの種類
	
			loop(3)
			{
				XY=erase(XY, 0);
			}//生成したのでその要素を配列から削除
			if(length(XY)==0)
			{//削除後の配列が空になった場合
				SetCommonData("ExtendItem",[]);//共通データを空にして
				break;//アイテム生成ループ脱出
		
			}
			else
			{
				SetCommonData("ExtendItem",XY);
			}//配列が空でない場合共通データに変更後の配列を渡す
		}
	}
yield;
}
}

task CreateExtendItem(x,y,type)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgItem);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		//ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		Obj_SetPosition(obj,x,y);

		if(type==1)
		{
			ObjEffect_SetVertexXY(obj, 0, -8, -8);
			ObjEffect_SetVertexXY(obj, 1, 8,  -8);
			ObjEffect_SetVertexXY(obj, 2, 8, 8);
			ObjEffect_SetVertexXY(obj, 3,  -8,  8);
		
			ObjEffect_SetVertexUV(obj, 0,  0,  0);
			ObjEffect_SetVertexUV(obj, 1,  16, 0);
			ObjEffect_SetVertexUV(obj, 2, 16,  16);
			ObjEffect_SetVertexUV(obj, 3, 0, 16);
		}
		if(type==2)
		{
			ObjEffect_SetVertexXY(obj, 0, -8, -8);
			ObjEffect_SetVertexXY(obj, 1, 8,  -8);
			ObjEffect_SetVertexXY(obj, 2, 8, 8);
			ObjEffect_SetVertexXY(obj, 3,  -8,  8);
		
			ObjEffect_SetVertexUV(obj, 0,  16,  0);
			ObjEffect_SetVertexUV(obj, 1,  32, 0);
			ObjEffect_SetVertexUV(obj, 2, 32,  16);
			ObjEffect_SetVertexUV(obj, 3, 16, 16);
		}

		let dx=0;
		let dy=0;
		let dya=-2;
		let angle=0;
		let speed=-2;
		let count=0;
		while(!Obj_BeDeleted(obj))
		{
			let sangle=90;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			ObjEffect_SetAngle(obj, 0,0,angle);
			if(count<60)
			{
				speed+=4/120;
			}
			if(count<60)
			{
				angle+=30;
			}
			if(count>=60){break;}
			dy=dy+dya;
			count++;
			ExtendItemEffect(Obj_GetX(obj),Obj_GetY(obj),angle,type);
			yield;
		}
		while(!Obj_BeDeleted(obj))
		{
			speed+=0.2;	
			let sangle=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			Obj_SetAngle(obj,0);
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(sangle),Obj_GetY(obj)+speed*sin(sangle));
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<10)
			{
				if(GetPlayerLife==1 && GetPlayerBomb==0)
				{
					SetCommonDataEx(NsScore,NsAchievement[74],1);
				}
				if(type==1)
				{
					ExtendNum+=1;
					ExtendPlayer(1);
					PlaySE("se\se1UP.wav");
					SetCommonDataEx(NsScore,NsAchievement[51],1);
				}
				if(type==2)
				{
					Ah_DoubleExtendCheck;
					AddBomb(1);
					PlaySE("se\se1UP.wav");
					SetCommonDataEx(NsScore,NsAchievement[53],1);
				}
				Obj_Delete(obj);
			}
			ExtendItemEffect(Obj_GetX(obj),Obj_GetY(obj),angle,type);
			yield;
		}

	task ExtendItemEffect(x,y,angle,type)
	{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgItem);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		Obj_SetPosition(obj,x,y);

		if(type==1)
		{
			ObjEffect_SetVertexXY(obj, 0, -8, -8);
			ObjEffect_SetVertexXY(obj, 1, 8,  -8);
			ObjEffect_SetVertexXY(obj, 2, 8, 8);
			ObjEffect_SetVertexXY(obj, 3,  -8,  8);
		
			ObjEffect_SetVertexUV(obj, 0,  0,  0);
			ObjEffect_SetVertexUV(obj, 1,  16, 0);
			ObjEffect_SetVertexUV(obj, 2, 16,  16);
			ObjEffect_SetVertexUV(obj, 3, 0, 16);
		}
		if(type==2)
		{
			ObjEffect_SetVertexXY(obj, 0, -8, -8);
			ObjEffect_SetVertexXY(obj, 1, 8,  -8);
			ObjEffect_SetVertexXY(obj, 2, 8, 8);
			ObjEffect_SetVertexXY(obj, 3,  -8,  8);
		
			ObjEffect_SetVertexUV(obj, 0,  16,  0);
			ObjEffect_SetVertexUV(obj, 1,  32, 0);
			ObjEffect_SetVertexUV(obj, 2, 32,  16);
			ObjEffect_SetVertexUV(obj, 3, 16, 16);
		}
		let scale=1.0;
		let alpha=100;
		ObjEffect_SetLayer(obj,2);
		Obj_SetAlpha(obj,alpha);
		ObjEffect_SetScale(obj,scale,scale);
		ObjEffect_SetAngle(obj, 0,0,angle);
		loop(5)
		{
			Obj_SetAlpha(obj,alpha);
			ObjEffect_SetScale(obj,scale,scale);
			alpha-=20;
			scale+=0.02;
			yield;
		}
		Obj_Delete(obj);
	}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

task SpellDrawTask
{
wait(5);
if(!IsReplay){return;}
let SpellCheck=0;
let SpellNum=[];
loop
{
	SpellCheck=length(GetCommonDataDefault("SpellDraw",[]));
	if(SpellCheck>0)
	{
		loop
		{
			SpellNum=GetCommonDataDefault("SpellDraw",[]);
	
			SpellDisplay(SpellNum[0],SpellNum[1]);

			loop(2)
			{
				SpellNum=erase(SpellNum, 0);
			}
			if(length(SpellNum)==0)
			{
				SetCommonData("SpellDraw",[]);
				break;
			}
			else
			{
				SetCommonData("SpellDraw",SpellNum);
			}
		}
	}
yield;
}
}

task CheckBMEBN
{
let ItemCheck=0;
let XY=[];
loop
{
	ItemCheck=length(GetCommonDataDefault("BurstModeErazeBulletNum",[]));
	if(ItemCheck>0)
	{
		loop
		{
			XY=GetCommonDataDefault("BurstModeErazeBulletNum",[]);

			BurstModeErazeBulletNum+=XY[0];
	
			loop(1)
			{
				XY=erase(XY, 0);
			}
			if(length(XY)==0)
			{
				SetCommonData("BurstModeErazeBulletNum",[]);
				break;
			}
			else
			{
				SetCommonData("BurstModeErazeBulletNum",XY);
			}
		}
	}
yield;
}
}
/*
task INEffect
{
yield;
if(LightMode_PlayerIntervalEffect==1){return;}
loop
{
if(GetTimeOfPlayerInvincibility!=0)
{
	StarLaser;
	while(GetTimeOfPlayerInvincibility!=0){yield;}
}
yield;
}
}

task StarLaser
{
	let R=100;

	let Rmax=100;
	let anglePlus=0;
	let ExpandTime=60;
	let Count=0;
	while(GetTimeOfPlayerInvincibility>0)
	{
		if(Count==0)
		{
		DeltaStarLaserEffect(R,anglePlus);
		DeltaStarLaserEffect(R,-anglePlus);
		}
		if(GetTimeOfPlayerInvincibility>ExpandTime && R<Rmax)
		{
			R+=Rmax/ExpandTime;
		}
		if(GetTimeOfPlayerInvincibility<=ExpandTime)
		{
			R-=Rmax/ExpandTime;
		}
		if(OnPlayerMissed){Count=1;}
		else if(Count>0){Count-=1;}
		anglePlus+=2;
		yield;
	}
}

task DeltaStarLaserEffect(R,angle)
{
		let Scale=1.5*R/100;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgIneDeltaLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -55, -66);
		ObjEffect_SetVertexXY(obj, 1,55,  -66);
		ObjEffect_SetVertexXY(obj, 2,55, 33);
		ObjEffect_SetVertexXY(obj, 3,  -55,  33);
		
		ObjEffect_SetVertexUV(obj, 0,  8,  13);
		ObjEffect_SetVertexUV(obj, 1,  118, 13);
		ObjEffect_SetVertexUV(obj, 2, 118, 111);
		ObjEffect_SetVertexUV(obj, 3, 8, 111);

		let Alpha=200;
		if(OnPlayerMissed){Alpha=0;}

		let R=255;let G=255;let B=255;

		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(5.5/5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4.5/2){R=50;G=205;B=50;}

		Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);
		ObjEffect_SetScale(obj,Scale,Scale);

		loop(15)
		{
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=200/15;
		if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}
*/
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////ステータス表示部//////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
task DifficultDisplay//難易度を表示
{
	alternative(SelectedDifficult)
	case("Moderate")
	{
		ascent(let i in 0..60)
		{
		StatusModerateDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		StatusModerateDisplayLong(530,20,255,255,255,255);
		wait(600);
		}
	}
	case("Extream")
	{
		ascent(let i in 0..60)
		{
		StatusExtreamDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		StatusExtreamDisplayLong(530,20,255,255,255,255);
		wait(600);
		}
	}
	case("Apocalypse")
	{
		ascent(let i in 0..60)
		{
		StatusApocalypseDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		StatusApocalypseDisplayLong(530,20,255,255,255,255);
		wait(600);
		}
	}
	case("Arrange")
	{
		ascent(let i in 0..60)
		{
		StatusArrangeDisplay(530,20,255*i/60,255,255,255);
		yield;
		}
		loop{
		StatusArrangeDisplay(530,20,255,255,255,255);
		yield;
		}
	}
}

task StatusDisplay//Hiscoreから霊点までの文字を表示
{
	let life;
	let bomb;
	let DrawY=60;
	yield;
	loop
	{
		life=GetPlayerLife-1;
		if(life>8)
		{
			life=8;
		}
		bomb=GetPlayerBomb;
		if(bomb>8)
		{
			bomb=8;
		}
		if(OnLifeExtend){life-=1;}
		if(GetCommonDataDefault("OnBombExtend",false)){bomb-=1;}
		if(LightMode_HiscoreDraw==-1)
		{	
			if(StagePractice)
			{
			DrawY=60;
			StatusHighScoreDisplay(530,DrawY,255,255,255,255);
			StatusScoreDisplay(530,DrawY+50,255,255,255,255);
			StatusPlayerDisplay(470,DrawY+100,255,255,255,255);
			StatusBombDisplay(470,DrawY+130,255,255,255,255);
			}
			else
			{
			DrawY=100;
			StatusHighScoreDisplay(530,DrawY-40,255,255,255,255);
			StatusScoreDisplay(530,DrawY+30,255,255,255,255);
			StatusPlayerDisplay(470,DrawY+100,255,255,255,255);
			StatusBombDisplay(470,DrawY+130,255,255,255,255);
			}
		}
		else if(LightMode_HiscoreDraw==0)
		{	
			DrawY=60;
			StatusHighScoreDisplay(530,DrawY,255,255,255,255);
			StatusScoreDisplay(530,DrawY+50,255,255,255,255);
			StatusPlayerDisplay(470,DrawY+100,255,255,255,255);
			StatusBombDisplay(470,DrawY+130,255,255,255,255);
		}
		else if(LightMode_HiscoreDraw==1)
		{	
			DrawY=10;
			StatusScoreDisplay(530,DrawY+50,255,255,255,255);
			StatusPlayerDisplay(470,DrawY+100,255,255,255,255);
			StatusBombDisplay(470,DrawY+130,255,255,255,255);
		}

	//	if(life>0)
	//	{
			DisPlayPlayerStar(life,105+DrawY);
	//	}
	//	if(bomb>0)
	//	{
			DisPlayBombStar(bomb,135+DrawY);
	//	}
		wait(600);
	}
}

task DisPlayPlayerStar(i,y)//残機を表示
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgStatusStar);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -0, -8);
		ObjEffect_SetVertexXY(obj, 1,16*i,  -8);
		ObjEffect_SetVertexXY(obj, 2,16*i, 8);
		ObjEffect_SetVertexXY(obj, 3,  -0,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  16*i, 0);
		ObjEffect_SetVertexUV(obj, 2, 16*i, 16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);

		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+96,y);

		loop(600)
		{
		ObjEffect_SetVertexXY(obj, 0, -0, -8);
		ObjEffect_SetVertexXY(obj, 1,16*(GetPlayerLife-1),  -8);
		ObjEffect_SetVertexXY(obj, 2,16*(GetPlayerLife-1), 8);
		ObjEffect_SetVertexXY(obj, 3,  -0,  8);
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  16*(GetPlayerLife-1), 0);
		ObjEffect_SetVertexUV(obj, 2, 16*(GetPlayerLife-1), 16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);
		if(GetPlayerLife==0)
		{
		ObjEffect_SetVertexColor(obj,0,0,255,200,200);
		ObjEffect_SetVertexColor(obj,1,0,255,200,200);
		ObjEffect_SetVertexColor(obj,2,0,255,200,200);
		ObjEffect_SetVertexColor(obj,3,0,255,200,200);
		}
		else
		{
		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);
		}
		yield;
		}
		Obj_Delete(obj);
}

task DisPlayBombStar(i,y)//残ボムを表示
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgStatusStar);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -0, -8);
		ObjEffect_SetVertexXY(obj, 1,16*i,  -8);
		ObjEffect_SetVertexXY(obj, 2,16*i, 8);
		ObjEffect_SetVertexXY(obj, 3,  -0,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  16*i, 0);
		ObjEffect_SetVertexUV(obj, 2, 16*i, 16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);

		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+96,y);

		loop(600)
		{
		ObjEffect_SetVertexXY(obj, 0, -0, -8);
		ObjEffect_SetVertexXY(obj, 1,16*(GetPlayerBomb),  -8);
		ObjEffect_SetVertexXY(obj, 2,16*(GetPlayerBomb), 8);
		ObjEffect_SetVertexXY(obj, 3,  -0,  8);
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  16*(GetPlayerBomb), 0);
		ObjEffect_SetVertexUV(obj, 2, 16*(GetPlayerBomb), 16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);
		yield;
		}
		Obj_Delete(obj);
}

task DisPlayScore//ハイスコアを呼び出し、ハイスコアと現スコアを表示
{
let EachHiScore=0;
let EachHiScore2=0;
let EachHiScore3=0;
let EachHiScore4=0;
let EachHiScore5=0;
let StageHiscore=[0,0,0,0,0];
let StageHiscore2=[0,0,0,0,0];
let StageHiscore3=[0,0,0,0,0];
let StageHiscore4=[0,0,0,0,0];
let StageHiscore5=[0,0,0,0,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(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCEasy[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCEasy2[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDEasy[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDEasy2[0],0);
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuEEasy[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuEEasy2[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(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCNormal[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCNormal2[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDNormal[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDNormal2[0],0);
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuENormal[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuENormal2[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);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCHard[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCHard2[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDHard[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDHard2[0],0);
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuEHard[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuEHard2[0],0);
		}
	}
	case("Arrange")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuALuna[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuALuna2[0],0);
			EachHiScore3=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuALuna3[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBLuna[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBLuna2[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCLuna[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuCLuna2[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDLuna[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuDLuna2[0],0);
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuELuna[0],0);
			EachHiScore2=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuELuna2[0],0);
		}
	}
//----------------------------------------------------------------------------------------------------------
	if(SelectedDifficult=="Moderate")
	{
		if(SelectedCharacter==DefinedPlayer1)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAEasy[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAEasy2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer2)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBEasy[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBEasy2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer3)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCEasy[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCEasy2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer4)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDEasy[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDEasy2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer5)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuEEasy[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuEEasy2[i],0);
			}
		}
	}

	if(SelectedDifficult=="Extream")
	{
		if(SelectedCharacter==DefinedPlayer1)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuANormal[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuANormal2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer2)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBNormal[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBNormal2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer3)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCNormal[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCNormal2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer4)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDNormal[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDNormal2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer5)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuENormal[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuENormal2[i],0);
			}
		}
	}


	if(SelectedDifficult=="Apocalypse")
	{
		if(SelectedCharacter==DefinedPlayer1)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAHard[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAHard2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer2)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBHard[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBHard2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer3)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCHard[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCHard2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer4)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDHard[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDHard2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer5)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuEHard[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuEHard2[i],0);
			}
		}
	}


	if(SelectedDifficult=="Arrange")
	{
		if(SelectedCharacter==DefinedPlayer1)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuALuna[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuALuna2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer2)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBLuna[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBLuna2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer3)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCLuna[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCLuna2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer4)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDLuna[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDLuna2[i],0);
			}
		}
		if(SelectedCharacter==DefinedPlayer5)
		{
			ascent(let i in 0..5)
			{
				StageHiscore[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuELuna[i],0);
				StageHiscore2[i] = GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuELuna2[i],0);
			}
		}
	}
//--------------------------------------------------------------------------------------------------------
	yield;
CreateScore(EachHiScore,EachHiScore2,EachHiScore3,EachHiScore4,EachHiScore5,StageHiscore,StageHiscore2,StageHiscore3,StageHiscore4,StageHiscore5);

}

function CreateScore(let EachHiScore,let EachHiScore2,let EachHiScore3,let EachHiScore4,EachHiScore5,StageHiscore,StageHiscore2,StageHiscore3,StageHiscore4,StageHiscore5)//GetScore関数から二つにわけた変数に記録し擬似的に桁を増やしている
{
	continucount;
	let PosX=GetClipMaxX+174;
	let PosX2=GetClipMaxX+174-ScoreNumberXpx*6;
	let PosX3=GetClipMaxX+174-ScoreNumberXpx*12;
	let PosX4=GetClipMaxX+174-ScoreNumberXpx*18;
	let PosX5=GetClipMaxX+174-ScoreNumberXpx*24;
	if(SelectedDifficult=="Arrange")
	{
		ScoreNumberXpx=12;
		PosX=GetClipMaxX+174;
		PosX2=GetClipMaxX+174-ScoreNumberXpx*6;
		PosX3=GetClipMaxX+174-ScoreNumberXpx*12;
		PosX4=GetClipMaxX+174-ScoreNumberXpx*18;
		let PosX5=GetClipMaxX+174-ScoreNumberXpx*24;
	}
	let ScoreNumber3digit=0;
	let ScoreNumber4digit=0;
	let ScoreNumber5digit=0;

	let TempStageScore1=0;
	let TempStageScore2=0;

	let PosY=GetClipMinY+67;
	let PosY2=GetClipMinY+117;
loop
{

	TempStageScore2=ScoreNumber2-SubtotalStagescore2;
	if(ScoreNumber1-SubtotalStagescore<0)
	{
		TempStageScore1=1000000+ScoreNumber1-SubtotalStagescore;
		TempStageScore2-=1;
	}
	else
	{
		TempStageScore1=ScoreNumber1-SubtotalStagescore;
	}
let SubTotalStageHiscore=0;
let SubTotalStageHiscore2=0;
	ScoreNumber1+=GetScore;
	AddScore(-GetScore);

	loop(1000)
	{
		if(ScoreNumber1>=1000000)
		{
			ScoreNumber2+=1;
			ScoreNumber1-=1000000;
		}
		else{break;}
	}
	ScoreNumber1=ScoreNumber1%1000000;
	loop(1000)
	{
		if(ScoreNumber2>=1000000)
		{
			ScoreNumber3+=1;
			ScoreNumber2-=1000000;
		}
		else{break;}
	}
	ScoreNumber2=ScoreNumber2%1000000;

if(StagePractice==false)
{
	if(LightMode_HiscoreDraw<=0)
	{
		if(EachHiScore2>ScoreNumber2)
		{
			DisPlayScoreNumber(PosX,GetClipMinY+67,EachHiScore,EachHiScore2);
			DisPlayScoreNumber2(PosX2,GetClipMinY+67,EachHiScore2,EachHiScore3);
		}
		else if(EachHiScore2==ScoreNumber2)
		{
			if(EachHiScore>ScoreNumber1)
			{
				DisPlayScoreNumber(PosX,GetClipMinY+67,EachHiScore,EachHiScore2);
				DisPlayScoreNumber2(PosX2,GetClipMinY+67,EachHiScore2,EachHiScore3);
			}
			else
			{
				DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
				DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,ScoreNumber3);
			}
		}
		else
		{
			DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,ScoreNumber3);
		}
	
		if(LightMode_HiscoreDraw==0)
		{
			DisPlayScoreNumber(PosX,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(PosX2,GetClipMinY+117,ScoreNumber2,ScoreNumber3);
		}
		if(LightMode_HiscoreDraw==-1)
		{
			DisPlayScoreNumber(PosX,GetClipMinY+117+20,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(PosX2,GetClipMinY+117+20,ScoreNumber2,ScoreNumber3);
		}
	}
	else
	{
		DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
		DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,ScoreNumber3);
	}

	if(LightMode_HiscoreDraw==-1)
	{
		if(StageHiscore2[StageProgress-1]>TempStageScore2)
		{
			SubDisPlayScoreNumber(PosX,GetClipMinY+67+20,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
			SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+67+20,StageHiscore2[StageProgress-1],0);
		}
		else if(StageHiscore2[StageProgress-1]==TempStageScore2)
		{
			if(StageHiscore[StageProgress-1]>TempStageScore1)
			{
				SubDisPlayScoreNumber(PosX,GetClipMinY+67+20,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
				SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+67+20,StageHiscore2[StageProgress-1],0);
			}
			else
			{
				SubDisPlayScoreNumber(PosX,GetClipMinY+67+20,TempStageScore1,TempStageScore2);
				SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+67+20,TempStageScore2,0);
			}
		}
		else
		{
			SubDisPlayScoreNumber(PosX,GetClipMinY+67+20,TempStageScore1,TempStageScore2);
			SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+67+20,TempStageScore2,0);
		}

		if(LightMode_HiscoreDraw==0)
		{
			SubDisPlayScoreNumber(PosX,GetClipMinY+117+20,TempStageScore1,TempStageScore2);
			SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+117+20,TempStageScore2,0);
		}
		if(LightMode_HiscoreDraw==-1)
		{
			SubDisPlayScoreNumber(PosX,GetClipMinY+117+40,TempStageScore1,TempStageScore2);
			SubDisPlayScoreNumber2(PosX2+24,GetClipMinY+117+40,TempStageScore2,0);
		}

	}


}
else
{
	if(LightMode_HiscoreDraw<=0)
	{
		if(StageHiscore2[StageProgress-1]>ScoreNumber2)
		{
			DisPlayScoreNumber(PosX,GetClipMinY+67,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
			DisPlayScoreNumber2(PosX2,GetClipMinY+67,StageHiscore2[StageProgress-1],0);
			DisPlayScoreNumber3(PosX3,GetClipMinY+67,StageHiscore3[StageProgress-1],0);
		}
		else if(StageHiscore2[StageProgress-1]==ScoreNumber2)
		{
			if(StageHiscore[StageProgress-1]>ScoreNumber1)
			{
				DisPlayScoreNumber(PosX,GetClipMinY+67,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
				DisPlayScoreNumber2(PosX2,GetClipMinY+67,StageHiscore2[StageProgress-1],0);
				DisPlayScoreNumber3(PosX3,GetClipMinY+67,StageHiscore3[StageProgress-1],0);
			}
			else
			{
				DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
				DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,0);
				DisPlayScoreNumber3(PosX3,GetClipMinY+67,ScoreNumber3,0);
			}
		}
		else
		{
			DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,0);
			DisPlayScoreNumber3(PosX3,GetClipMinY+67,ScoreNumber3,0);
		}
		DisPlayScoreNumber(PosX,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
		DisPlayScoreNumber2(PosX2,GetClipMinY+117,ScoreNumber2,0);
		DisPlayScoreNumber3(PosX3,GetClipMinY+117,ScoreNumber3,0);
	}
	else
	{
		DisPlayScoreNumber(PosX,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
		DisPlayScoreNumber2(PosX2,GetClipMinY+67,ScoreNumber2,0);
		DisPlayScoreNumber3(PosX3,GetClipMinY+67,ScoreNumber3,0);
	}
	}
yield;
}

}

task continucount//コンテしたらスコアを0にする
{
	let StageContinueCount=GetCommonDataDefaultEx(NsScore,NsContinueCount,0);
	let ContinueNum=GetAllowedContinueCount;
	while(ContinueNum==GetAllowedContinueCount)
	{
		yield;
	}
	StageContinueCount+=1;
	SetCommonDataEx(NsScore,NsContinueCount,StageContinueCount);
	ScoreNumber2=0;
	ScoreNumber1=0;
	continucount;
}



