	#東方弾幕風[Stage]
	#Title[Magical Singular Day ver0.20]
	#Text[Magical Singular Day ver0.20]
	#Player[.\player/MarisaA\MarisaA.txt,.\player/MarisaB\MarisaB.txt,.\player/MarisaC\MarisaC.txt,.\player/MarisaD\MarisaD.txt]
	#BackGround[User]

	#ScriptVersion[2]

	script_stage_main
	{
	SetRateScoreSystemEnable(false);
	SetDefaultStatusVisible(false);
	let csd=GetCurrentScriptDirectory;

	let imgTitle=csd ~ "img/title.png";
	let imgWhite=csd ~ "img/White.png";

	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 imgStatusStar=csd ~ "img/StatusStar.png";
	let imgBer=csd ~ "img/ber.png";
	let imgBer2=csd ~ "img/ber2.png";
	let imgCircleEffect=csd ~ "player/img/Marisa_shots.png";

	let imgBreakCircleEffect=csd ~ "img/circle.png";

	let imgItem=csd ~ "img/Item.png";

	let imgAchievement=csd ~ "img/secret/Achievement.png";
	let imgSpell=csd ~ "img/spell.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=[];

	let Stagescore=0;
	let Stagescore2=0;

	let SubtotalStagescore=0;
	let SubtotalStagescore2=0;

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

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

	let bgX=0;
	let bgX2=300;
	let bgX3=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 stage1BGCount=0;

	let stage4bgfromy=0;
	let Adjuststage4bgfromy=0;
	let stage4bgfromz=0;
	let stage4bg1yangle=0;
	let stage4bg2zangle=0;
	let stage4bg2scale=0;
	let stage4fogRGB=[255,255,255];
	let stage4bgLeftLayerX=0;

	let StageChange=false;
	let stage2alpha1=0;
	let stage2alpha2=0;
	let stage3alpha1=0;
	let stage3alpha2=0;
	let stage4alpha1=0;
	let stage4alpha2=0;
	let stage4alpha3=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 PracticeStartBurstRank=0;
	let PracticeStartRushGauge=0;
	let StartDifficult=0;
	let StartStage=0;

	let LightMode=0;
	let LightMode_HiscoreDraw=0;
	let LightMode_PlayerIntervalEffect=0;
	let LightMode_ShotEffect=0;
	let LightMode_BombEffect=0;
	let LightMode_PlayerBlur=0;
	let LightMode_BossBlur=0;
	let LightMode_ElementalBlur=0;
	let LightMode_SpecialEffect=0;
	let LightMode_BreakEffect=0;

	let UseAutoBombCount;
	let UseStageBombCount;
	let BurstModeErazeBulletNum;

	let JudgTimeInitialMAM=false;

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

		task StageTask
		{
			yield;
			LoadUserShotData(GetCurrentScriptDirectory~".\img\shot_All.txt");
	//TitleImage;
			BombStateAM;
			InitialMAM;
			CheckBMEBN;
			CheckBMEBE;
			CheckExtendItem;
			CheckMagicCircle;
			LifeAndBombDefine;

			UpTimeCount;//起動時間,プレイ時間計測

			StageTitleDisplay;
			wait(1);
			StatusDisplay;//文字と残機とボム表示を表示
			ForbidShot(false);
			ForbidBomb(false);
			PlayCharacterAndDifficult;//使用キャラと難易度のプレイ回数の記録
			HiScoreLoad;//ハイスコアをロード
			DifficultDisplay;//難易度を表示
			DisPlayScore;//スコアを表示
//StageStartEffect;
			ExtendSystem;
			EnemyLifeDisplay;
			EnemyMagicCircle;
			TimeBonus;
			INEffect;
			SpellDrawTask;
			if(BGDrawing==1)
			{
				BGGraphicRect;//ステージ背景の矩形処理など
			}
			DeleteUsedFile;

			if(StageProgress==1)
			{
				SubtotalStagescore=0;
				SubtotalStagescore2=0;
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",1);
				wait(1);
				SetCommonData("SPIRALJUDG",1);
				SetCommonData("BOSSDEFEAT",false);
				Stage1;
				Stage1End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=1;
					wait(240);
					ClearStage;
				}

				if(ScoreNumber2>=1000)
				{
					SetCommonDataEx(NsScore,NsAchievement[13],1);
				}
				if(ScoreNumber1<=300000 && ScoreNumber2==0 && Continued==false)
				{
					SetCommonDataEx(NsScore,NsAchievement[20],1);
				}
				if(UseStageBombCount+10<=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0))
				{
					SetCommonDataEx(NsScore,NsAchievement[27],1);
				}
				wait(120);
				FadeOutMusic(BGM[2],20);
				wait(120);
				StageHiscoreSave(1);
				SetCommonData("SectionShift",true);
				SetCommonData("SPIRALJUDG",0);
				StageProgress=2;
			}

			StageChange=false;

			if(StageProgress==2)
			{
				SubtotalStagescore=ScoreNumber1;
				SubtotalStagescore2=ScoreNumber2;
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",2);
				SetCommonData("BOSSDEFEAT",false);
				Stage2;
				Stage2End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=2;
					wait(240);
					ClearStage;
				}
				if(UseStageBombCount+10<=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0))
				{
					SetCommonDataEx(NsScore,NsAchievement[27],1);
				}
				wait(120);
				FadeOutMusic(BGM[4],20);
				wait(120);
				StageHiscoreSave(2);
				SetCommonData("SectionShift",true);
				StageProgress=3;
			}

			StageChange=false;

			if(StageProgress==3)
			{
				SubtotalStagescore=ScoreNumber1;
				SubtotalStagescore2=ScoreNumber2;
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",3);
				SetCommonData("BOSSDEFEAT",false);
				Stage3;
				Stage3End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=3;
					wait(240);
					ClearStage;
				}
				if(UseStageBombCount+10<=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0))
				{
					SetCommonDataEx(NsScore,NsAchievement[27],1);
				}
				wait(120);
				FadeOutMusic(BGM[6],20);
				wait(120);
				StageHiscoreSave(3);
				SetCommonData("SectionShift",true);
				StageProgress=4;
			}

			StageChange=false;

			if(StageProgress==4)
			{
				SubtotalStagescore=ScoreNumber1;
				SubtotalStagescore2=ScoreNumber2;
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",4);
				SetCommonData("BOSSDEFEAT",false);
				Stage4;
				Stage4End;
				StageChange=true;
				if(StagePractice==true)
				{
					StageProgress=4;
					wait(300);
					ClearStage;
				}
				if(UseStageBombCount+10<=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0))
				{
					SetCommonDataEx(NsScore,NsAchievement[27],1);
				}
				wait(120);
				FadeOutMusic(BGM[8],20);
				wait(120);
				StageHiscoreSave(4);
				SetCommonData("SectionShift",true);
				//StageProgress=5;
			}

			StageChange=false;

			wait(60);
			if(StagePractice==false)
			{//通しクリア
				if(GetPlayerInfo(PLAYER_SPEED_HIGH)==4)
				{
					SetCommonDataEx(NsScore,NsAchievement[0],1);
				}
				else if(GetPlayerInfo(PLAYER_SPEED_HIGH)==5)
				{
					SetCommonDataEx(NsScore,NsAchievement[1],1);
				}
				if(GetPlayerInfo(PLAYER_SPEED_HIGH)==5.5)
				{
					SetCommonDataEx(NsScore,NsAchievement[2],1);
				}
				else if(GetPlayerInfo(PLAYER_SPEED_HIGH)==4.5)
				{
					SetCommonDataEx(NsScore,NsAchievement[3],1);
				}
				alternative(SelectedDifficult)
				case("Moderate")
				{
					SetCommonDataEx(NsScore,NsAchievement[4],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[5],1);
					}
				}
				case("Extream")
				{
					SetCommonDataEx(NsScore,NsAchievement[6],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[7],1);
					}
				}
				
				case("Apocalypse")
				{
					SetCommonDataEx(NsScore,NsAchievement[8],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[9],1);
					}
				}
				if(GetBombCount==0 && Continued==false)
				{
					SetCommonDataEx(NsScore,NsAchievement[23],1);
				}
				JudgTimeInitialMAM=true;
				ClearBonus;
			}

			wait(5);
			ClearStage;
		}
	
		
		@Initialize()
		{
			SetCommonData("MagicalSingularDay",true);
			ExpertEx(false,100,3);

			CreateCommonDataArea(NsScore);
			SetCommonData(NsGetSpell,0);
			let isRep = IsReplay();
			LoadCommonDataEx(NsScore,savePathstage);

			if(isRep==true)
			{
				LoadCommonDataFromReplayFile;
				StageState=Loading;
			}
			SetCommonData(NsIsReplay,isRep);
			SetCommonData(NsIsReplayJudgment,isRep);

			if(GetCommonDataDefaultEx(NsScore,NsContinueCount,0)>=30)
			{
				SetCommonDataEx(NsScore,NsAchievement[19],1);
			}

			UseAutoBombCount=GetCommonDataDefaultEx(NsScore,"UseAutoBombCount",0);
			BurstModeErazeBulletNum=GetCommonDataDefaultEx(NsScore,"BurstModeErazeBulletNumAM",0);

			StartDifficult=GetCommonDataDefaultEx(NsScore,"StartDifficult",0);
			StartStage=GetCommonDataDefaultEx(NsScore,"StartStage",0);
			StagePhaseProgress=GetCommonDataDefaultEx(NsScore,"StagePhaseProgressConfig",0);
			PracticeStartBurstCounter=GetCommonDataDefaultEx(NsScore,"PracticeStartBurstCounter",0);
			PracticeStartMagicCounter=GetCommonDataDefaultEx(NsScore,"PracticeStartMagicCounter",0);
			PracticeStartBurstRank=GetCommonDataDefaultEx(NsScore,"PracticeStartBurstRank",0);
			PracticeStartRushGauge=GetCommonDataDefaultEx(NsScore,"PracticeStartRushGauge",0);
			BGDrawing=GetCommonDataDefaultEx(NsScore,"BGDrawing",1);
			LightMode=GetCommonDataDefaultEx(NsScore,"LightMode",0);
			AutoBombMode=GetCommonDataDefaultEx(NsScore,"AutoBombMode",0);

			StageTask();
		}

		let SlowModeJudgRShot1;
		let SlowModeJudgRShot2;
		let SlowModeJudgRShot3;

		@MainLoop()
		{
			yield;
			SlowModeJudgRShot1=GetEnemyShotCountEx(GetCenterX,GetCenterY,400,5);
			SlowModeJudgRShot2=GetEnemyShotCountEx(GetCenterX,GetCenterY,400,2);
			SlowModeJudgRShot3=GetEnemyShotCountEx(GetCenterX,GetCenterY,400,1);

			if(SlowModeJudgRShot1+SlowModeJudgRShot2+SlowModeJudgRShot3>=34)
			{
				Slow(1);
			}
			else
			{
				Slow(0);
			}
		
			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(RShot1+RShot2+RShot3,320,432,12,255);//起動時間の表示
			//DrawText(GetCommonDataDefaultEx(NsScore,"LOWSPIRALNUM",0),320,452,12,255);//プレイ時間の表示
			//DrawText(UseAutoBombCount,120,432,12,255);//起動時間の表示
			//DrawText(GetCommonDataDefaultEx(NsScore,NsContinueCount,0),120,452,12,255);//プレイ時間の表示
			//DrawText(AchievementState,120,412,12,255);//起動時間の表示
			//DrawText(BurstModeErazeBulletNum,120,412,12,255);//起動時間の表示
		//	DrawText(GetCommonData("MagicAbsorbShortRange"),120,412,12,255);//起動時間の表示
		//	DrawText(GetCommonData("MagicAbsorbLongRange"),120,397,12,255);//起動時間の表示
		//	DrawText(GetCommonDataDefault("BURSTRANK",0),120,382,12,255);//起動時間の表示
		//	DrawText(StartStage,120,427,12,255);//起動時間の表示

			MenuDraw;
		}

		@Finalize()
		{
			if(GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None")=="None" && Continued==false)
			{
				if(ScoreNumber2>=1)
				{
				HiScoreSave;
				}
			}
			if(ScoreNumber2>=1000)
			{
				SetCommonDataEx(NsScore,NsAchievement[10],1);
			}
			if(ScoreNumber2>=5000)
			{
				SetCommonDataEx(NsScore,NsAchievement[11],1);
			}
			if(ScoreNumber2>=10000)
			{
				SetCommonDataEx(NsScore,NsAchievement[12],1);
			}
			if(GetCommonData("MAGICFRAGMENT")>=10000)
			{
				SetCommonDataEx(NsScore,NsAchievement[14],1);
			}
			if(GetCommonData("MAGICFRAGMENT")>=30000)
			{
				SetCommonDataEx(NsScore,NsAchievement[15],1);
			}
			if(GetCommonData("MAGICFRAGMENT")>=50000)
			{
				SetCommonDataEx(NsScore,NsAchievement[16],1);
			}
			if(GetCommonDataDefaultEx(NsScore,NsAllFragment,0)>=500000)
			{
				SetCommonDataEx(NsScore,NsAchievement[17],1);
			}
			if(GetCommonDataDefaultEx(NsScore,NsAllFragment2,0)>=1)
			{
				SetCommonDataEx(NsScore,NsAchievement[18],1);
			}
			if(GetCommonDataDefault("Achievement21",0))
			{
				SetCommonDataEx(NsScore,NsAchievement[21],1);
			}
			UseAutoBombCount+=GetCommonDataDefault("UseAutoBombCount",0);
			if(UseAutoBombCount>=100)
			{
				SetCommonDataEx(NsScore,NsAchievement[24],1);
			}	

			SetCommonDataEx(NsScore,"UseAutoBombCount",UseAutoBombCount);
			SetCommonDataEx(NsScore,"ExFlag","true");
			SetCommonDataEx(NsScore,NsUpTime,UpTime);
			SetCommonDataEx(NsScore,NsPlayTime,PlayTime);
			let AllFragmentFinalize=GetCommonDataDefaultEx(NsScore,NsAllFragment,0);
			let AllFragmentFinalize2=GetCommonDataDefaultEx(NsScore,NsAllFragment2,0);
			if(AllFragmentFinalize>=1000000)
			{
				AllFragmentFinalize2+=1;
				AllFragmentFinalize-=1000000;
			}
			SetCommonDataEx(NsScore,NsAllFragment,AllFragmentFinalize+GetCommonDataDefault("MAGICFRAGMENT",0));
			SetCommonDataEx(NsScore,NsAllFragment2,AllFragmentFinalize2);

			let spiralnum=GetCommonDataDefaultEx(NsScore,"LOWSPIRALNUM",0);
			if(GetCommonDataDefault("SPIRALJUDG",0)==1 && StagePractice==false)
			{
				SetCommonDataEx(NsScore,"LOWSPIRALNUM",spiralnum+1);
				if(spiralnum>=14)
				{
					SetCommonDataEx(NsScore,NsAchievement[26],1);
				}
			}
			else if(StageProgress!=1 || StagePractice==true)
			{
				SetCommonDataEx(NsScore,"LOWSPIRALNUM",0);
			}
			
			SetCommonDataEx(NsScore,"BurstModeErazeBulletNumAM",BurstModeErazeBulletNum);
			if(BurstModeErazeBulletNum>=10000)
			{
				SetCommonDataEx(NsScore,NsAchievement[28],1);
			}		
			if(PlayTime>=3600)
			{
				SetCommonDataEx(NsScore,NsAchievement[29],1);
			}

				SetCommonDataEx(NsScore,"StartDifficult",StartDifficult);
				SetCommonDataEx(NsScore,"StartStage",StartStage);
				SetCommonDataEx(NsScore,"StagePhaseProgressConfig",StagePhaseProgress);
				SetCommonDataEx(NsScore,"PracticeStartBurstCounter",PracticeStartBurstCounter);
				SetCommonDataEx(NsScore,"PracticeStartMagicCounter",PracticeStartMagicCounter);
				SetCommonDataEx(NsScore,"PracticeStartBurstRank",PracticeStartBurstRank);
				SetCommonDataEx(NsScore,"PracticeStartRushGauge",PracticeStartRushGauge);
				SetCommonDataEx(NsScore,"BGDrawing",BGDrawing);
				SetCommonDataEx(NsScore,"LightMode",LightMode);
				SetCommonDataEx(NsScore,"AutoBombMode",AutoBombMode);

			StageHiscoreSave(StageProgress);
			if(GetCommonDataDefault(NsIsReplay,true) == false)
			{
				SaveCommonDataEx(NsScore,savePathstage);
			}
			ClearCommonDataEx(NsScore);
			DeleteCommonData(NsGetSpell);
			DeleteCommonData(NsDefeatFrame);
			DeleteCommonData(NsDefeatPosX);
			DeleteCommonData(NsDefeatPosY);
			DeleteCommonData(NsBossFrame);
			DeleteCommonData(NsIsReplay);
			AddScore(-GetScore);
			AddScore(ScoreNumber2);
		}

		let bgAngle=90;
		let BossAdjust=0;

		@BackGround {
		BackGroundLoop;
	}



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

task LoadStagefile
{
	LoadGraphic(imgTitle);
	LoadGraphic(imgWhite);
	//LoadGraphic(imgBG);
      	//LoadGraphic(imgMenuLetter);
      	LoadGraphic(imgBer2);
      	LoadGraphic(imgNumber);
      	LoadGraphic(imgStatusLetter);
      	LoadGraphic(imgStatusStar);
	LoadGraphic(imgCircleEffect);
	LoadGraphic(imgBreakCircleEffect);
      	LoadGraphic(imgItem);
	if(BGDrawing==1)
	{
		LoadGraphic(csd~"img\st1bg1.png");
		LoadGraphic(csd~"img\cloud.png");
		LoadGraphic(csd~"img\cloud2.png");
		LoadGraphic(csd~"img\st2bg1.png");
		LoadGraphic(csd~"img\st2bg2.png");
		LoadGraphic(csd~"img\st3bg1.png");
		LoadGraphic(csd~"img\st4bg1.png");
		LoadGraphic(csd~"img\st4bg2.png");
	}
	LoadGraphic(imgBer);
	if(IsReplay)
	{
      	LoadGraphic(imgSpell);
	}
}

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


	function StageHiscoreSave(let Stage)
	{
		Stage-=1;
		Stagescore2=ScoreNumber2-SubtotalStagescore2;
		if(ScoreNumber1-SubtotalStagescore<0)
		{
			Stagescore=1000000+ScoreNumber1-SubtotalStagescore;
			Stagescore2-=1;
		}
		else
		{
			Stagescore=ScoreNumber1-SubtotalStagescore;
		}
		alternative(SelectedDifficult)
		case("Moderate")
		{
			alternative(SelectedCharacter)
			case(DefinedPlayer1)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAEasy2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAEasy2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAEasy[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAEasy2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAEasy[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAEasy[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer2)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBEasy2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBEasy2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBEasy[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBEasy2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBEasy[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBEasy[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer3)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCEasy2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCEasy2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCEasy[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCEasy2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCEasy[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCEasy[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer4)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDEasy2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDEasy2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDEasy[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDEasy2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDEasy[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDEasy[Stage],Stagescore);
					}
				}
			}
		}
		case("Extream")
		{
			alternative(SelectedCharacter)
			case(DefinedPlayer1)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuANormal2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuANormal2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuANormal[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuANormal2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuANormal[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuANormal[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer2)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBNormal2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBNormal2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBNormal[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBNormal2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBNormal[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBNormal[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer3)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCNormal2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCNormal2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCNormal[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCNormal2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCNormal[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCNormal[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer4)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDNormal2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDNormal2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDNormal[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDNormal2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDNormal[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDNormal[Stage],Stagescore);
					}
				}
			}
		}
		case("Apocalypse")
		{
			alternative(SelectedCharacter)
			case(DefinedPlayer1)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAHard2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAHard2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAHard[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAHard2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuAHard[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuAHard[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer2)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBHard2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBHard2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBHard[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBHard2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuBHard[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuBHard[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer3)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCHard2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCHard2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCHard[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCHard2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuCHard[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuCHard[Stage],Stagescore);
					}
				}
			}
			case(DefinedPlayer4)
			{
				if(Stagescore2>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDHard2[Stage],0))
				{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDHard2[Stage],Stagescore2);
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDHard[Stage],Stagescore);
				}
				else if(Stagescore2==GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDHard2[Stage],0))
				{
					if(Stagescore>GetCommonDataDefaultEx(NsScore,NsStageHiScoreReimuDHard[Stage],0))
					{
					SetCommonDataEx(NsScore,NsStageHiScoreReimuDHard[Stage],Stagescore);
					}
				}
			}
		}
	}
///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////ステージエフェクト、残機調整部////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

sub ClearBonus
{
	while(GetPlayerLife>1)
	{
		ExtendPlayer(-1);
		AddScore(50000000);
		PlaySE("se\se1UP.wav");
		wait(60);
	}
	while(GetPlayerBomb>0)
	{
		AddBomb(-1);
		AddScore(10000000);
		PlaySE("se\se1UP.wav");
		wait(60);
	}
	wait(60);
}

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")
	{
		PlayMusic(BGM[0]);
		LoadMenufile;
		loop
		{
			alternative(StageState)	
			case(Menu)
			{
				TASK_MENU;
		 	}
			case(Exit)
			{//メニュー画面で設定した値の保存
				FadeOutMusic(BGM[0],20);
				StageState=Loading;
				SetCommonDataEx(NsScore,"SelectedDifficult",SelectedDifficult);
				SetCommonDataEx(NsScore,"StagePractice",StagePractice);
				SetCommonDataEx(NsScore,"StageProgress",StageProgress);
				SetCommonDataEx(NsScore,"StagePhaseProgress",StagePhaseProgress);

				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);
			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);

			if(StagePractice)
			{
				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);

			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 ExtendSystem//エクステンドの設定
{
	while(ScoreNumber2<1000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<5000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<10000){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 TitleImage
{
	loop
	{
		titleimage;
	//	titlewhite;
		yield;
	}
}

task titleimage
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgTitle);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -320, -240);
		ObjEffect_SetVertexXY(obj, 1,320,  -240);
		ObjEffect_SetVertexXY(obj, 2,320, 240);
		ObjEffect_SetVertexXY(obj, 3,  -320,  240);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  600, 0);
		ObjEffect_SetVertexUV(obj, 2, 600, 480);
		ObjEffect_SetVertexUV(obj, 3, 0, 480);

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

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

		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,320,GetCenterY);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

task titlewhite
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgWhite);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, SUBTRACT); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1,192,  -224);
		ObjEffect_SetVertexXY(obj, 2,192, 224);
		ObjEffect_SetVertexXY(obj, 3,  -192,  224);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  10, 0);
		ObjEffect_SetVertexUV(obj, 2, 10, 10);
		ObjEffect_SetVertexUV(obj, 3, 0, 10);

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

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

		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,GetCenterX,GetCenterY);

		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 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,  19,  0);
			ObjEffect_SetVertexUV(obj, 1,  35, 0);
			ObjEffect_SetVertexUV(obj, 2, 35,  16);
			ObjEffect_SetVertexUV(obj, 3, 19, 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(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<20)
			{
				break;
			}
			if(((Obj_GetX(obj)-GetPlayerX)^2+(Obj_GetY(obj)-GetPlayerY)^2)^0.5<50 && GetPlayerMoveState==MOVE_SLOW)
			{
				break;
			}
			if(Obj_GetY(obj)>=GetClipMaxY+16)
			{
				Obj_Delete(obj);			
			}
			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(type==1)
				{
					ExtendPlayer(1);
					PlaySE("se\se1UP.wav");
				//	SetCommonDataEx(NsScore,NsAchievement[9],1);
				}
				if(type==2)
				{
					AddBomb(1);
					PlaySE("se\se1UP.wav");
				//	SetCommonDataEx(NsScore,NsAchievement[8],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,  19,  0);
			ObjEffect_SetVertexUV(obj, 1,  35, 0);
			ObjEffect_SetVertexUV(obj, 2, 35,  16);
			ObjEffect_SetVertexUV(obj, 3, 19, 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 CheckMagicCircle
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
//let ItemPerFrame=60;//１フレームあたりの最大アイテム生成数（処理落ち対策）
loop
{
	ItemCheck=length(GetCommonDataDefault("MagicCircleBreak",[]));//毎フレーム共通データの長さチェック
	if(ItemCheck>0)
	{//配列に中身がある（アイテム発生フラグ立っている）場合の処理
		loop
		{
			XY=GetCommonDataDefault("MagicCircleBreak",[]);//共通データ内容を変数に渡す

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

task MagicCircleBreak(x,y,type,scale)
{
	let angle=rand(0,360);
	if(GetCommonDataDefault("LightMode_BreakEffect",0)==1){return;}
	ascent(i in 0..6)
	{
	MagicCircleBreakEffect(x,y,type,scale*1.2,angle+i*60);
	}
}

task MagicCircleBreakEffect(x,y,type,scale,angle)
{
	let r=128;
	let way=6;
	let X=[0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/2*cos(angle);
	X[2]=r/2*cos(angle+360/way);
	X[3]=r*cos(angle);
	X[4]=r*cos(angle+180/way);
	X[5]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/2*sin(angle);
	Y[2]=r/2*sin(angle+360/way);
	Y[3]=r*sin(angle);
	Y[4]=r*sin(angle+180/way);
	Y[5]=r*sin(angle+360/way);

	MagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale);
	MagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale);
}

task MagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale)
{
		let CX=384;
		let CY=384;
		if(type==2){CY=128;}
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,7);

		ascent(let i in 0..3)
		{
		if(type==2)
		{
		ObjEffect_SetVertexColor(obj,i,255,200,200,255);
		}
		}

		Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);

		ObjEffect_SetScale(obj, scale,scale);
/*
		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);
*/
		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05;
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);
		loop(20)
		{
		//	Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(Angle),Obj_GetY(obj)+speed*sin(Angle));
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/20;
			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>0)
		{
		//	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 ColorRed=255;
	let ColorGreen=0;
	let ColorBlue=0;
	HueDifine;

	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, -4);
		ObjEffect_SetVertexXY(obj, 1, 142,  -4);
		ObjEffect_SetVertexXY(obj, 2, 142, 4);
		ObjEffect_SetVertexXY(obj, 3,  0,  4);
		
		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,1.0);

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

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

		while(GetEnemyLife>0)
		{
			scale=2.5*GetEnemyLife/BossLifeMax;
			ObjEffect_SetScale(obj, scale,1.0);
		ascent(let i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,120,255-ColorRed/5, 200-ColorGreen/5,255-ColorBlue/5);
		}
			yield;
		}
		Obj_Delete(obj);


	task HueDifine
	{
		let HueCount=0;
		let MinColor=50;
		loop
		{
			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;
			}
			HueCount+=3;
			if(HueCount>=361){HueCount=1;}
		yield;
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////
//////////////////時間計測、回数記録部,初期ボーナス部/////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
		task UpTimeCount//起動時間とプレイ時間の計測
		{
			UpTime=GetCommonDataDefaultEx(NsScore,NsUpTime,0);
			PlayTime=GetCommonDataDefaultEx(NsScore,NsPlayTime,0);
			loop
			{
				UpTime++;
				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(DefinedPlayer3)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuCEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuCEasy,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuDEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuDEasy,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(DefinedPlayer3)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuCNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuCNormal,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuDNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuDNormal,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);		
				}
				case(DefinedPlayer3)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuCHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuCHard,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuDHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuDHard,Frequency);		
				}
			}
			SetCommonData("SELECTEDDIFFICULT",SelectedDifficult);//選択難易度を受け渡すため保存
		}

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

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 CheckBMEBE
{
let ItemCheck=0;
let XY=[];
loop
{
	ItemCheck=length(GetCommonDataDefault("BurstModeErazeBulletEffect",[]));
	if(ItemCheck>0)
	{
		loop
		{
			XY=GetCommonDataDefault("BurstModeErazeBulletEffect",[]);

			BurstModeErazeBulletEffect(XY[0],XY[1],XY[2]);
	
			loop(3)
			{
				XY=erase(XY, 0);
			}
			if(length(XY)==0)
			{
				SetCommonData("BurstModeErazeBulletEffect",[]);
				break;
			}
			else
			{
				SetCommonData("BurstModeErazeBulletEffect",XY);
			}
		}
	}
yield;
}
}

task BurstModeErazeBulletEffect(x,y,R)
{
		let scx=1;
		let scy=1;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -R, -R);
		ObjEffect_SetVertexXY(obj, 1,R,  -R);
		ObjEffect_SetVertexXY(obj, 2,R, R);
		ObjEffect_SetVertexXY(obj, 3,  -R,  R);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		let Alpha=255;
		let R=100;let G=100; let B=255;

		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,3);
		Obj_SetPosition(obj,x,y);
		
		ObjEffect_SetScale(obj, scx,scy);

		loop(30)
		{
			scx-=1/30;
			scy-=1/30;
			ObjEffect_SetScale(obj, scx,scy);
			yield;
		}
		Obj_Delete(obj);
}


task EnemyMagicCircle//敵スペルカード発動時のエフェクト
{
loop
{
if(GetCommonDataDefault("BossLastAttack",false)==true)
{
let BMcolor=GetCommonData("BossLastAttackColor");
MagicCircleAppear1(BMcolor[0],BMcolor[1],BMcolor[2],1);
MagicCircleAppear1(BMcolor[0],BMcolor[1],BMcolor[2],-1);
while(GetCommonDataDefault("BossLastAttack",false)==true){yield;}
}
yield;
}
}

task MagicCircleAppear1(R,G,B,dir)//魔方陣その１
{
		let scax=0.0;
		let scay=0.0;
		let angle=0;
		let Xangle=-90;
		let Yangle=-90;	
		let Zangle=0;
		let RotateAngle=3;
  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
		ObjEffect_SetTexture(obj,imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, scax,scay);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  256,  256);
		ObjEffect_SetVertexUV(obj, 1,  512, 256);
		ObjEffect_SetVertexUV(obj, 2, 512,  512);
		ObjEffect_SetVertexUV(obj, 3, 256, 512);

		ObjEffect_SetLayer(obj,2);

		let Alpha=50;
		let ColorCount=0;

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

		let BossX=GetEnemyX;
		let BossY=GetEnemyY;

		loop(90)
		{
			ObjEffect_SetScale(obj, scax,scay);
			scax+=1/90;
			scay+=1/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
				Xangle+=3*dir;
				Yangle+=3;
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);	
			yield;
		}
	//	while(GetCommonDataDefault("BossLastAttack",false)==true)
	//	{
		while(GetEnemyLife>0)
		{
/*
		ObjEffect_SetVertexColor(obj,0,Alpha,R+(255-R)*cos(ColorCount),G+(255-G)*cos(ColorCount),B+(255-B)*cos(ColorCount));
		ObjEffect_SetVertexColor(obj,1,Alpha,R+(255-R)*sin(ColorCount),G+(255-G)*sin(ColorCount),B+(255-B)*sin(ColorCount));
		ObjEffect_SetVertexColor(obj,2,Alpha,R+(255-R)*cos(ColorCount),G+(255-G)*cos(ColorCount),B+(255-B)*cos(ColorCount));
		ObjEffect_SetVertexColor(obj,3,Alpha,R+(255-R)*sin(ColorCount),G+(255-G)*sin(ColorCount),B+(255-B)*sin(ColorCount));

		ColorCount+=1;
*/
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);		
			yield;
		}
		while(GetCommonDataDefault("BossLastAttack",false)==true)
		{
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Xangle+=3*dir;
			Yangle+=3+dir*1.5;
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			BossX=GetEnemyX;
			BossY=GetEnemyY;	
			yield;
		}
		Obj_Delete(obj);
		if(dir==1)
		{
		BossMagicCircleBreak(BossX,BossY,1,1,Zangle,R,G,B);
		}
}


task BossMagicCircleBreak(x,y,type,scale,Zangle,R,G,B)
{
	//if(GetCommonDataDefault("LightMode",0)==1){return;}
	ascent(i in 0..36)
	{
	BossMagicCircleBreakEffect(x,y,type,scale*1.2,Zangle+i*10,R,G,B);
	}
}

task BossMagicCircleBreakEffect(x,y,type,scale,angle,R,G,B)
{
	let r=128;
	let way=36;

	let X=[0,0,0,0,0,0,0,0,0,0];
	let Y=[0,0,0,0,0,0,0,0,0,0];
	X[0]=0;
	X[1]=r/3*cos(angle);
	X[2]=r/3*cos(angle+360/way);
	X[3]=r*2/3*cos(angle);
	X[4]=r*2/3*cos(angle+180/way);
	X[5]=r*2/3*cos(angle+360/way);
	X[6]=r*cos(angle);
	X[7]=r*cos(angle+120/way);
	X[8]=r*cos(angle+240/way);
	X[9]=r*cos(angle+360/way);

	Y[0]=0;
	Y[1]=r/3*sin(angle);
	Y[2]=r/3*sin(angle+360/way);
	Y[3]=r*2/3*sin(angle);
	Y[4]=r*2/3*sin(angle+180/way);
	Y[5]=r*2/3*sin(angle+360/way);
	Y[6]=r*sin(angle);
	Y[7]=r*sin(angle+120/way);
	Y[8]=r*sin(angle+240/way);
	Y[9]=r*sin(angle+360/way);

	BossMagicCircleBreakEffectTriangle(x,y,X[0],X[1],X[2],Y[0],Y[1],Y[2],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[3],X[4],Y[1],Y[3],Y[4],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[2],X[4],X[5],Y[2],Y[4],Y[5],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[1],X[2],X[4],Y[1],Y[2],Y[4],type,scale,R,G,B);

	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[6],X[7],Y[3],Y[6],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[3],X[4],X[7],Y[3],Y[4],Y[7],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[7],X[8],Y[4],Y[7],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[4],X[5],X[8],Y[4],Y[5],Y[8],type,scale,R,G,B);
	BossMagicCircleBreakEffectTriangle(x,y,X[5],X[8],X[9],Y[5],Y[8],Y[9],type,scale,R,G,B);

}

task BossMagicCircleBreakEffectTriangle(x,y,x1,x2,x3,y1,y2,y3,type,scale,R,G,B)
{
		let CX=384;
		let CY=384;
		if(type==2){CY=128;}
		let TriCX=(x1+x2+x3)/3;
		let TriCY=(y1+y2+y3)/3;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBreakCircleEffect);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 3);
		ObjEffect_SetVertexXY(obj, 0, x1-TriCX, y1-TriCY);
		ObjEffect_SetVertexXY(obj, 1, x2-TriCX, y2-TriCY);
		ObjEffect_SetVertexXY(obj, 2, x3-TriCX, y3-TriCY);
		
		ObjEffect_SetVertexUV(obj, 0,  x1+CX,  y1+CY);
		ObjEffect_SetVertexUV(obj, 1,  x2+CX, y2+CY);
		ObjEffect_SetVertexUV(obj, 2, x3+CX,  y3+CY);

		ObjEffect_SetLayer(obj,7);

		ascent(let i in 0..3)
		{
		ObjEffect_SetVertexColor(obj,i,255,R,G,B);
		}

Obj_SetPosition(obj,x+TriCX*scale,y+TriCY*scale);

ObjEffect_SetScale(obj, scale,scale);

		let Sscale=scale;
		let speed=((TriCX)^2+(TriCY)^2)^0.5*0.05/3*rand(0.85,1.15);
		let Angle=atan2(TriCY,TriCX);
		Obj_SetSpeed(obj,speed);
		Obj_SetAngle(obj,Angle);

		let Xangle=rand(0,360);
		let Yangle=rand(0,360);
		let Zangle=rand(0,360);
		let XangleRotate=rand(-10,10);
		let YangleRotate=rand(-10,10);
		let ZangleRotate=rand(-10,10);

		loop(120)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/240;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}

		loop(30)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/120;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			yield;
		}
		ItemSet(Obj_GetX(obj),Obj_GetY(obj),100+StageProgress);
		Obj_Delete(obj);

}

task INEffect
{
yield;
if(LightMode_PlayerIntervalEffect==1){return;}
loop
{
if(GetTimeOfPlayerInvincibility!=0)
{
	StarLaser;
	while(GetTimeOfPlayerInvincibility!=0){yield;}
}
yield;
}
}

task StarLaser
{
	let R=100;
	let length=R*3^0.5+3;

	let count=0;
	let Rmax=100;
	let anglePlus=0;
	let ExpandTime=60;
	while(GetTimeOfPlayerInvincibility>0)
	{
		ascent(i in 0..6)
		{
		StarLaserEffect(GetPlayerX+R*cos(anglePlus*(i%2*2-1)+i*60),GetPlayerY+R*sin(anglePlus*(i%2*2-1)+i*60),length,anglePlus*(i%2*2-1)+i*60+210);
		}

		if(GetTimeOfPlayerInvincibility>ExpandTime && R<Rmax)
		{
			R+=Rmax/ExpandTime;
		}
		if(GetTimeOfPlayerInvincibility<=ExpandTime)
		{
			R-=Rmax/ExpandTime;
		}
		length=R*3^0.5+3;

		anglePlus+=2;
		//count++;
		yield;
	}
}


task StarLaserEffect(x,y,length,angle)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -0, 3);
		ObjEffect_SetVertexXY(obj, 1,length,  -3);
		ObjEffect_SetVertexXY(obj, 2,length, 3);
		ObjEffect_SetVertexXY(obj, 3,  -0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  228, 27);
		ObjEffect_SetVertexUV(obj, 2, 228, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		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;}


		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);

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

		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)
		{
		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から霊点までの文字を表示
{
	let life;
	let bomb;
	let DrawY=60;
	loop
	{
		life=GetPlayerLife-1;
		if(life>8)
		{
			life=8;
		}
		bomb=GetPlayerBomb;
		if(bomb>8)
		{
			bomb=8;
		}

		if(!LightMode_HiscoreDraw)
		{	
			DrawY=60;
			StatusHighScoreDisplay(530,DrawY,255,255,255,255);
		}
		else
		{	
			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);
		}

		yield;
	}
}

task DisPlayPlayerStar(i,y)//残機を表示
{

		let scx=0.35;
		let scy=0.35;
		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, -18);
		ObjEffect_SetVertexXY(obj, 1,43*i,  -18);
		ObjEffect_SetVertexXY(obj, 2,43*i, 18);
		ObjEffect_SetVertexXY(obj, 3,  -0,  18);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  43*i, 0);
		ObjEffect_SetVertexUV(obj, 2, 43*i, 40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);

		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);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

task DisPlayBombStar(i,y)//残ボムを表示
{
		let scx=0.35;
		let scy=0.35;
		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, -18);
		ObjEffect_SetVertexXY(obj, 1,43*i,  -18);
		ObjEffect_SetVertexXY(obj, 2,43*i, 18);
		ObjEffect_SetVertexXY(obj, 3,  -0,  18);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  43*i, 0);
		ObjEffect_SetVertexUV(obj, 2, 43*i, 40);
		ObjEffect_SetVertexUV(obj, 3, 0, 40);

		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);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

task DisPlayScore//ハイスコアを呼び出し、ハイスコアと現スコアを表示
{
let EachHiScore=0;
let EachHiScore2=0;
let StageHiscore=[0,0,0,0,0];
let StageHiscore2=[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("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("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);
		}
	}
//----------------------------------------------------------------------------------------------------------
	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(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(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);
			}
		}
	}
//--------------------------------------------------------------------------------------------------------
CreateScore(EachHiScore,EachHiScore2,StageHiscore,StageHiscore2);

}

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

loop
{
let SubTotalStageHiscore=0;
let SubTotalStageHiscore2=0;
	ScoreNumber1+=GetScore;
	AddScore(-GetScore);

	loop(10)
	{
		if(ScoreNumber1>=1000000)
		{
			ScoreNumber2+=1;
			ScoreNumber1-=1000000;
		}
	}
if(StagePractice==false)
{
	if(!LightMode_HiscoreDraw)
	{
	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);
	}
	else
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,ScoreNumber2,0);
	}
/*
	ascent(i in 0..StageProgress)
	{
		SubTotalStageHiscore+=StageHiscore[i];
		SubTotalStageHiscore2+=StageHiscore2[i];
		loop(floor(SubTotalStageHiscore/1000000))
		{
			SubTotalStageHiscore-=1000000;
			SubTotalStageHiscore2+=1;
		}
	}

	if(SubTotalStageHiscore2>ScoreNumber2)
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,SubTotalStageHiscore,SubTotalStageHiscore2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,SubTotalStageHiscore2,0);
	}
	else if(SubTotalStageHiscore2==ScoreNumber2)
	{
		if(SubTotalStageHiscore>ScoreNumber1)
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,SubTotalStageHiscore,SubTotalStageHiscore2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,SubTotalStageHiscore2,0);
		}
		else
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,ScoreNumber2,0);
		}
	}
	else
	{

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

	}
*/
}
else
{
	if(!LightMode_HiscoreDraw)
	{
	if(StageHiscore2[StageProgress-1]>ScoreNumber2)
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,StageHiscore2[StageProgress-1],0);
	}
	else if(StageHiscore2[StageProgress-1]==ScoreNumber2)
	{
		if(StageHiscore[StageProgress-1]>ScoreNumber1)
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,StageHiscore[StageProgress-1],StageHiscore2[StageProgress-1]);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,StageHiscore2[StageProgress-1],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);
	}
	else
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+67,ScoreNumber1,ScoreNumber2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+67,ScoreNumber2,0);
	}

/*
	ascent(i in 0..StageProgress)
	{
		SubTotalStageHiscore+=StageHiscore[i];
		SubTotalStageHiscore2+=StageHiscore2[i];
		loop(floor(SubTotalStageHiscore/1000000))
		{
			SubTotalStageHiscore-=1000000;
			SubTotalStageHiscore2+=1;
		}
	}

	if(SubTotalStageHiscore2>ScoreNumber2)
	{
	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,SubTotalStageHiscore,SubTotalStageHiscore2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,SubTotalStageHiscore2,0);
	}
	else if(SubTotalStageHiscore2==ScoreNumber2)
	{
		if(SubTotalStageHiscore>ScoreNumber1)
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,SubTotalStageHiscore,SubTotalStageHiscore2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,SubTotalStageHiscore2,0);
		}
		else
		{
			DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
			DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,ScoreNumber2,0);
		}
	}
	else
	{

	DisPlayScoreNumber(GetClipMaxX+190,GetClipMinY+117,ScoreNumber1,ScoreNumber2);
	DisPlayScoreNumber2(GetClipMaxX+118,GetClipMinY+117,ScoreNumber2,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;
}

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////インクルード部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#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"
#include_function ".\txt/AchievementLetter.txt"
#include_function ".\txt/Achievement.txt"
#include_function ".\txt/SpellDraw.txt"

	}