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

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

	let 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 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 MenuSE=[csd ~ "se/clock03.wav",csd ~ "se/cursor01.wav"];
	let BGM=[csd ~ "bgm/title.wav",csd ~ "bgm/stage1.wav",csd ~ "bgm/stage1boss.wav",csd ~ "bgm/stage2.wav",csd ~ "bgm/stage2boss.wav",csd ~ "bgm/stage3.wav",csd ~ "bgm/stage3boss.wav",
		csd ~ "bgm/stage4.wav",csd ~ "bgm/stage4boss.wav",csd ~ "bgm/stage5.wav",csd ~ "bgm/stage5boss.wav",csd ~ "bgm/stage6.wav",csd ~ "bgm/stage6boss.wav"];

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

	let SelectedDifficult="Difficult";
	let StageProgress=1;
	let StagePractice=false;
	let 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 StageChange=false;
	let stage2alpha1=0;
	let stage2alpha2=0;
	let stage3alpha1=0;
	let stage3alpha2=0;
	let stage4alpha1=0;
	let stage4alpha2=0;
	let stage5alpha1=0;
	let stage5alpha2=0;
	let stage6alpha1=0;
	let stage6alpha2=0;

	let ScoreNumber1=0;
	let ScoreNumber2=0;

	let UpTime;
	let PlayTime;

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

	let UseAutoBombCount;
	let UseStageBombCount;
	let BurstModeErazeBulletNum;

	let JudgTimeInitialMAM=false;
	#include_function ".\Config.txt"

	#include_function ".\txt\DifineMenuVariable.txt"//メニュー画面管理用の値の収納先
		task StageTask
		{
			yield;
			LoadUserShotData(GetCurrentScriptDirectory~".\img\shot_All.txt");
	//TitleImage;
			BombStateAM;
			InitialMAM;
			CheckBMEBN;
			CheckBMEBE;
			CheckExtendItem;
			CheckMagicCircle;
			LifeAndBombDefine;
			PlayMusic(BGM[0]);
			UpTimeCount;//起動時間計測
			PlayTimeCount;//プレイ時間計測

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

			if(StagePractice==false)
			{
				StagePhaseProgress=0;
			}

			if(StageProgress==1)
			{
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",1);
				wait(1);
				SetCommonData("SPIRALJUDG",1);
				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);
			SetCommonData("SectionShift",true);
			SetCommonData("SPIRALJUDG",0);
			StageProgress=2;
			}
			StageChange=false;

			if(StageProgress==2)
			{
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",2);
				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);
			SetCommonData("SectionShift",true);
			StageProgress=3;
			}
			StageChange=false;


			if(StageProgress==3)
			{
				UseStageBombCount=GetBombCount-GetCommonDataDefault("UseAutoBombCount",0);
				SetCommonData("STAGEPROGRESS",3);
				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);
			SetCommonData("SectionShift",true);
			}
			StageChange=false;
/*
			if(StageProgress==4)
			{
				Stage4;
				SetCommonData("STAGEPROGRESS",4);
				while(StageProgress==4){yield;}
				if(StagePractice==true)
				{
					StageProgress=4;
					wait(240);
					ClearStage;
				}
			DeleteGraphic(csd~"img\stage4bg.png");
			wait(60);

			AddGraze(-GetGraze);
			}

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

			AddGraze(-GetGraze);
			}
			StageProgress=10;
			CrearBonus;
			wait(600);
*/
			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);
				}
				alternative(SelectedDifficult)
				case("Moderate")
				{
					SetCommonDataEx(NsScore,NsAchievement[2],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[3],1);
					}
				}
				case("Extream")
				{
					SetCommonDataEx(NsScore,NsAchievement[4],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[5],1);
					}
				}
				
				case("Apocalypse")
				{
					SetCommonDataEx(NsScore,NsAchievement[6],1);
					if(Continued==false)
					{
						SetCommonDataEx(NsScore,NsAchievement[7],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==false)
			{
		//		LoadCommonDataEx(NsScore,savePathstage);
			}
			else
			{
				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);
			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>=100)
			{
				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);//起動時間の表示
			MenuDraw;
		}

		@Finalize()
		{
			if(GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None")=="None" && Continued==false)
			{
			HiScoreSave;
			}
			if(ScoreNumber2>=1000)
			{
				SetCommonDataEx(NsScore,NsAchievement[10],1);
			}
			if(ScoreNumber2>=3000)
			{
				SetCommonDataEx(NsScore,NsAchievement[11],1);
			}
			if(ScoreNumber2>=5000)
			{
				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);
			}
			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(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(imgBer);
}

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

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

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")
{
	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);
				//	SaveCommonDataEx(NsScore,savePath);//Select&Levelを保存
					wait(5);
					Retry;
					break;
		 		}
				others{}
			yield;
			}
}
else
{
	LoadStagefile;

	StageState=Start;
	if(GetCommonData(NsIsReplayJudgment) == false)
	{
	SelectedDifficult=GetCommonDataDefaultEx(NsScore,"SelectedDifficult","None");
	StagePractice=GetCommonDataDefaultEx(NsScore,"StagePractice",false);
	StageProgress=GetCommonDataDefaultEx(NsScore,"StageProgress",1);
	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);

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

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

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


			ForbidBomb(false);

		SetCommonData("LightMode",LightMode);

		SetCommonData("MSDSetting",true);
}

task ExtendSystem//エクステンドの設定
{
	while(ScoreNumber2<1000){yield;}
	ExtendPlayer(1);
	PlaySE("se\se1UP.wav");
	while(ScoreNumber2<5000){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",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 BossLifeMax=GetEnemyLife;
	let scale=2.5;

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

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

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

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

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

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

		task PlayCharacterAndDifficult//プレイ回数を増やし難易度を決定
		{
			alternative(SelectedDifficult)
			case("Moderate")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuAEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuAEasy,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBEasy,Frequency);		
				}
			}
			case("Extream")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuANormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuANormal,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBNormal,Frequency);		
				}
			}
			case("Apocalypse")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuAHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuAHard,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBHard,Frequency);		
				}
			}
			SetCommonData("SELECTEDDIFFICULT",SelectedDifficult);//選択難易度を受け渡すため保存
		}

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

task CheckBMEBN
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
//let ItemPerFrame=60;//１フレームあたりの最大アイテム生成数（処理落ち対策）
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=[];//共通データの書き換えにワンクッション置くための変数
//let ItemPerFrame=60;//１フレームあたりの最大アイテム生成数（処理落ち対策）
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,  160, 0);
		ObjEffect_SetVertexUV(obj, 2, 160, 160);
		ObjEffect_SetVertexUV(obj, 3, 0, 160);

		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]);
MagicCircleAppear2(BMcolor[0],BMcolor[1],BMcolor[2]);
while(GetCommonDataDefault("BossLastAttack",false)==true){yield;}
}
yield;
}
}

task MagicCircleAppear1(R,G,B)//魔方陣その１
{
		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);

		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,50,R,G,B);
		}
		loop(90)
		{
			ObjEffect_SetScale(obj, scax,scay);
			scax+=1/90;
			scay+=1/90;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
				Xangle+=1;
				Yangle+=1;
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);	
			yield;
		}
		while(GetCommonDataDefault("BossLastAttack",false)==true)
		{
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);		
			yield;
		}
		Obj_Delete(obj);
}

task MagicCircleAppear2(R,G,B)//魔方陣その2
{
		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);

		ascent(i in 0..4)
		{
		ObjEffect_SetVertexColor(obj,i,50,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-=1;
				Yangle+=1;
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);	
			yield;
		}
		while(GetCommonDataDefault("BossLastAttack",false)==true)
		{
			ObjEffect_SetScale(obj, scax,scay);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			Zangle+=RotateAngle;
			Obj_SetPosition(obj,GetEnemyX,GetEnemyY);
			BossX=GetEnemyX;
			BossY=GetEnemyY;	
			yield;
		}
		Obj_Delete(obj);
		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];
	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);

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

	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(60)
		{
			ObjEffect_SetScale(obj, scale,scale);
			scale-=Sscale/120;
			Xangle+=XangleRotate;
			Yangle+=YangleRotate;
			Zangle+=ZangleRotate;
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			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から霊点までの文字を表示
{
loop
{
		StatusHighScoreDisplay(530,60,255,255,255,255);
		StatusScoreDisplay(530,110,255,255,255,255);
	//	StatusMagicCounterDisplay(530,160,255,255,255,255);
	//	StatusFragmentDisplay(530,220,255,255,255,255);
	//	PercentDisplay(610,233,255,255,255,255);
		StatusPlayerDisplay(470,160,255,255,255,255);
		StatusBombDisplay(470,190,255,255,255,255);
		yield;

}
}

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

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

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

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

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

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

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

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

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

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

}

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

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

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

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

task continucount//コンテしたらスコアを0にする
{
	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"
	}