	#東方弾幕風[Stage]
	#Title[Ex風ステージ]
	#Text[Ex風ステージ]
	#Player[.\player/Marisa/Marisa.txt,.\player/Reimu/Reimu.txt]
	#BackGround[User]
	#BackGround[Defalt]
	#ScriptVersion[2]


	
	script_stage_main
	{
	SetRateScoreSystemEnable(false);
	SetDefaultStatusVisible(false);
	let csd=GetCurrentScriptDirectory;
	let imgBG=csd ~ "img/MenuBG.png";
	let imgItem=csd ~ "img/Item.png";
	let imgDifficult=csd ~ "img/letter.png";
	let imgPlayerAndBomb=csd ~ "img/shot_all.png";

	SetCommonData("ItemXY",[]);//アイテム位置座標保存用共通データ作成

	let MenuSE=[csd ~ "se/clock03.wav",csd ~ "se/cursor01.wav"];
	let BGM=[csd ~ "bgm/menu.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"];

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

	let SelectedDifficult="Difficult";
	let StageProgress=1;
	let StagePractice=false;
	#include_function ".\txt\DifineMenuVariable.txt"//メニュー画面管理用の値の収納先

		task StageTask
		{
			yield;
			LifeAndBombDefine;
			PlayMusic(BGM[0]);
			UpTimeCount;//起動時間計測
			PlayTimeCount;//プレイ時間計測
			StatusDisplay;//文字を表示
			PlayerAndBombDisplay;//残機とボム表示

			StageTitleDisplay;

			ForbidShot(false);
			ForbidBomb(false);
			CheckItem;//アイテム生成開始
			PlayCharacterAndDifficult;//使用キャラと難易度のプレイ回数の記録
			HiScoreLoad;//ハイスコアをロード
			DifficultDisplay;//難易度を表示
			DisPlayScore;//スコアを表示
			SCBItem;//スペルカード取得ボーナスアイテムタスク起動
			ExtendSystem;
			if(StageProgress==1)
			{
				PlayMusic(BGM[1]);
				wait(120);
				Stage1;
				SetCommonData("STAGEPROGRESS",1);
				while(StageProgress==1){yield;}
				if(StagePractice==true)
				{
					wait(120);
					ClearStage;
				}
			}
			if(StageProgress==2)
			{
				PlayMusic(BGM[3]);
				wait(120);
				Stage2;
				SetCommonData("STAGEPROGRESS",2);
				while(StageProgress==2){yield;}
				if(StagePractice==true)
				{
					wait(120);
					ClearStage;
				}
			}
			if(StageProgress==3)
			{
				PlayMusic(BGM[5]);
				wait(120);
				Stage3;
				SetCommonData("STAGEPROGRESS",3);
				while(StageProgress==3){yield;}
				if(StagePractice==true)
				{
					wait(120);
					ClearStage;
				}
			}
			wait(120);
			if(Continued==false && StagePractice==false)
			{
				SetCommonDataEx(NsScore,"SecretFlag","true");
			}
			ClearStage;
		}

			
		
		@Initialize()
		{
			LoadGraphic(imgBG);
			LoadGraphic(imgItem);
			LoadGraphic(imgDifficult);
			LoadGraphic(imgPlayerAndBomb);
			LoadGraphic(csd ~ "img/border.png");
			CreateCommonDataArea(NsScore);
			LoadCommonDataEx(NsScore,savePathstage);
			SetCommonData(NsGetSpell,0);
			let isRep = IsReplay();
			SetCommonData(NsIsReplay,isRep);
			StageTask();
		}
		
		@MainLoop()
		{
			yield;
			if(GetGraze>0)//グレイズによる打ち込み点上昇を防ぐ。グレイズ関係で不具合でたらここを消そう
			{
			//	AddGraze(-1);
			}
		}
		
		@DrawTopObject
		{
			SetTexture(imgBG);
			SetGraphicRect(0,0,384,448);
			if(StageState==Menu)
			{
				DrawGraphic(GetCenterX, GetCenterY);
			}
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsUpTime,0)/60),320,432,12,255);//起動時間の表示
			//DrawText(NumToString(GetCommonDataDefaultEx(NsScore,NsPlayTime,0)/60),320,452,12,255);//プレイ時間の表示
			//DrawText(StageState,120,432,12,255);//起動時間の表示
			//DrawText(SecretSpellSelect,120,452,12,255);//プレイ時間の表示
			//DrawText(Select,120,412,12,255);//起動時間の表示
			MenuDraw;
		}

		@Finalize()
		{
			HiScoreSave;
			if(GetCommonDataDefault(NsIsReplay,true) == false)
			{
				SaveCommonDataEx(NsScore,savePathstage);
			}
			ClearCommonDataEx(NsScore);
			DeleteCommonData(NsGetSpell);
			DeleteCommonData(NsDefeatFrame);
			DeleteCommonData(NsDefeatPosX);
			DeleteCommonData(NsDefeatPosY);
			DeleteCommonData(NsBossFrame);
			DeleteCommonData(NsIsReplay);
		}
///////////////////////////////////////////////////////////////////////////////////////
sub LifeAndBombDefine
{
	while(GetPlayerLife<3)
	{
		ExtendPlayer(1);
	}
	while(GetPlayerBomb<3)
	{
		AddBomb(1);
	}
	while(GetPlayerLife>3)
	{
		ExtendPlayer(-1);
	}
	while(GetPlayerBomb>3)
	{
		AddBomb(-1);
	}
}
sub StageTitleDisplay
{
			loop
			{
				alternative(StageState)	
				case(Menu)
				{
					TASK_MENU;
		 		}
				case(Exit)
				{
					break;
		 		}
				others{}
			yield;
			}

			ForbidShot(false);
			if(SelectedDifficult=="SecretSpell")
			{
				StageSecretSpell;
				while(SelectedDifficult=="SecretSpell")
				{
					yield;
				}
			}
}

task ExtendSystem
{
	while(GetScore<25000000){yield;}
	ExtendPlayer(1);
	PlaySE("se1UP.wav");
	while(GetScore<50000000){yield;}
	ExtendPlayer(1);
	PlaySE("se1UP.wav");
	while(GetScore<100000000){yield;}
	ExtendPlayer(1);
	PlaySE("se1UP.wav");
	while(GetScore<200000000){yield;}
	ExtendPlayer(1);
	PlaySE("se1UP.wav");
}

////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////アイテム部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
task CheckItem
{
let ItemCheck=0;//共通データの配列の長さをチェックする変数
let XY=[];//共通データの書き換えにワンクッション置くための変数
let ItemPerFrame=5;//１フレームあたりの最大アイテム生成数（処理落ち対策）
loop
{
	ItemCheck=length(GetCommonDataDefault("ItemXY",[]));//毎フレーム共通データの長さチェック
	if(ItemCheck>0)
	{//配列に中身がある（アイテム発生フラグ立っている）場合の処理
		loop(ItemPerFrame)
		{
			XY=GetCommonDataDefault("ItemXY",[]);//共通データ内容を変数に渡す
			Item(XY[0],XY[1],XY[2]);//アイテム生成。順番にX座標、Y座標、アイテムの種類
			loop(3)
			{
				XY=erase(XY, 0);
			}//生成したのでその要素を配列から削除
			if(length(XY)==0)
			{//削除後の配列が空になった場合
				SetCommonData("ItemXY",[]);//共通データを空にして
				break;//アイテム生成ループ脱出
		
			}
			else
			{
				SetCommonData("ItemXY",XY);
			}//配列が空でない場合共通データに変更後の配列を渡す
		}
	}
yield;
}
}

task Item(x,y,type)
{//アイテム設定
		let color="white";
		let dx=0;
		let dy=0;
		let dya=-2;
		let count=0;
		
		let scax=1;
		let scay=1;
		let speed=2;
		let angle=0;

		let collectline=160;
		let CollectOn=false;
		if(SelectedCharacter==DefinedPlayer3 || SelectedCharacter==DefinedPlayer4)
		{
			collectline=176;
		}
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgItem);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);

		let objv = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(objv, imgItem);
		ObjEffect_SetPrimitiveType(objv, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(objv, ADD); 
		ObjEffect_CreateVertex(objv, 4);
		ObjEffect_SetVertexXY(objv, 0, -5, -4);
		ObjEffect_SetVertexXY(objv, 1, 5,  -4);
		ObjEffect_SetVertexXY(objv, 2, 5, 4);
		ObjEffect_SetVertexXY(objv, 3,  -5,  4);
		
		ObjEffect_SetVertexUV(objv, 0,  113,  2);
		ObjEffect_SetVertexUV(objv, 1,  124, 2);
		ObjEffect_SetVertexUV(objv, 2, 124,  10);
		ObjEffect_SetVertexUV(objv, 3, 113, 10);
		Obj_SetPosition(objv,x,GetClipMinY+8);

		if(type==1)
		{
			ObjEffect_SetVertexXY(obj, 0, -6, -6);
			ObjEffect_SetVertexXY(obj, 1, 6,  -6);
			ObjEffect_SetVertexXY(obj, 2, 6, 6);
			ObjEffect_SetVertexXY(obj, 3,  -6,  6);
		
			ObjEffect_SetVertexUV(obj, 0,  59,  21);
			ObjEffect_SetVertexUV(obj, 1,  71, 21);
			ObjEffect_SetVertexUV(obj, 2, 71,  33);
			ObjEffect_SetVertexUV(obj, 3, 59, 33);
		}
		if(type==2)
		{
			ObjEffect_SetVertexXY(obj, 0, -6, -6);
			ObjEffect_SetVertexXY(obj, 1, 6,  -6);
			ObjEffect_SetVertexXY(obj, 2, 6, 6);
			ObjEffect_SetVertexXY(obj, 3,  -6,  6);
		
			ObjEffect_SetVertexUV(obj, 0,  2,  21);
			ObjEffect_SetVertexUV(obj, 1,  14, 21);
			ObjEffect_SetVertexUV(obj, 2, 14,  33);
			ObjEffect_SetVertexUV(obj, 3, 2, 33);
		}
		if(type==3)
		{
			ObjEffect_SetTexture(obj, imgPlayerAndBomb);
			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,  62,  320);
			ObjEffect_SetVertexUV(obj, 1,  77, 320);
			ObjEffect_SetVertexUV(obj, 2, 77,  335);
			ObjEffect_SetVertexUV(obj, 3, 62, 335);

			ObjEffect_SetVertexColor(obj,0,150,200,255,200);
			ObjEffect_SetVertexColor(obj,1,150,200,255,200);
			ObjEffect_SetVertexColor(obj,2,150,200,255,200);
			ObjEffect_SetVertexColor(obj,3,150,200,255,200);
			ObjEffect_SetScale(obj, 0.4,0.4);
		}
		if(type==4)
		{
			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==5)
		{
			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);
		}
		Obj_SetAutoDelete(obj,false);
		ObjEffect_SetAngle(obj, 0,0,angle);
		//ObjEffect_SetScale(obj, scax,scay);
		Obj_SetPosition(obj,x,y);

		while(!Obj_BeDeleted(obj))
		{
			ItemAlpha(Obj_GetY(obj),type,objv);
			Obj_SetPosition(obj,x+dx,y+dy);
			ObjEffect_SetAngle(obj, 0,0,angle);
			if(type==3){break;}
			if(GetCommonDataDefault("KEKKAI",false)==true)
			{
				speed=7.0;
				color="yellow";
				CollectOn=true;
				break;
			}
			if(count<120)
			{
				dya+=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(GetPlayerY<=collectline)
			{
				speed=7.0;
			//	color="yellow";
			//	CollectOn=true;//星仕様
				break;
			}
			if(Obj_GetY(obj)>=GetClipMaxY+16)
			{
				Obj_Delete(obj);
				Obj_Delete(objv);			
			}
			dy=dy+dya;
			count++;
			yield;
		}
		ObjEffect_SetAngle(obj, 0,0,0);
		let StandardItemScore;
		let GetItemScore;
			if(type==3)
			{
				speed=0.5;
				loop(15)
				{
				Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(-90),Obj_GetY(obj)+speed*sin(-90));
				wait(1);
				}
			}
		while(!Obj_BeDeleted(obj))
		{
			ItemAlpha(Obj_GetY(obj),type,objv);
			if(type==1 || type==2 ||type==4 || type==5)
			{
				speed+=0.2;
			}
			if(type==3)
			{
				speed=8;
			}	
			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)
				{
					let XY=GetCommonDataDefault("POWER",[]);//共通データ内容を変数に渡す
					XY=XY~[1];//
					SetCommonData("POWER",XY);//共通データに変更後の配列を渡す
				}
				if(type==2)
				{
					StandardItemScore=GetCommonDataDefault("BONUSPOINT",0);
					if(GetPlayerY<=collectline || CollectOn==true)
					{
						color="yellow";
						GetItemScore=StandardItemScore;
					}
					else
					{
						GetItemScore=StandardItemScore*(0.75-0.5*GetPlayerY/(GetClipMaxY-16));
					}
					GetItemScore=(trunc(GetItemScore/10))*10;
					DisPlayGetItemScore(Obj_GetX(obj),Obj_GetY(obj),GetItemScore,color);
					AddScore(GetItemScore);
				}
				if(type==3)
				{
					let XY=GetCommonDataDefault("BONUSITEM",[]);//共通データ内容を変数に渡す
					XY=XY~[1];//
					SetCommonData("BONUSITEM",XY);//共通データに変更後の配列を渡す
				}
				if(type==4)
				{
					ExtendPlayer(1);
					PlaySE("se1UP.wav");
				}
				if(type==5)
				{
					AddBomb(1);
				}
				Obj_Delete(obj);
				Obj_Delete(objv);
				PlaySE("seScore.wav");
			}
			yield;
		}
}

function ItemAlpha(y,type,objv)//アイテムが画面上部に行ったとき、矢印のアルファ値変更
{
	if(type==1)
	{
		if(y<=GetClipMinY)
		{
			ObjEffect_SetVertexColor(objv,0,255,255,150,150);
			ObjEffect_SetVertexColor(objv,1,255,255,150,150);
			ObjEffect_SetVertexColor(objv,2,100,255,150,150);
			ObjEffect_SetVertexColor(objv,3,100,255,150,150);
		}
		else
		{
			ObjEffect_SetVertexColor(objv,0,0,255,200,200);
			ObjEffect_SetVertexColor(objv,1,0,255,200,200);
			ObjEffect_SetVertexColor(objv,2,0,255,200,200);
			ObjEffect_SetVertexColor(objv,3,0,255,200,200);
		}
	}
	if(type==2)
	{
		if(y<=GetClipMinY)
		{
			ObjEffect_SetVertexColor(objv,0,255,150,150,255);
			ObjEffect_SetVertexColor(objv,1,255,150,150,255);
			ObjEffect_SetVertexColor(objv,2,255,150,150,255);
			ObjEffect_SetVertexColor(objv,3,255,150,150,255);
		}
		else
		{
			ObjEffect_SetVertexColor(objv,0,0,255,200,200);
			ObjEffect_SetVertexColor(objv,1,0,255,200,200);
			ObjEffect_SetVertexColor(objv,2,0,255,200,200);
			ObjEffect_SetVertexColor(objv,3,0,255,200,200);
		}
	}
	if(type==3)
	{
		if(y<=GetClipMinY)
		{
			ObjEffect_SetVertexColor(objv,0,255,150,255,150);
			ObjEffect_SetVertexColor(objv,1,255,150,255,150);
			ObjEffect_SetVertexColor(objv,2,255,150,255,150);
			ObjEffect_SetVertexColor(objv,3,255,150,255,150);
		}
		else
		{
			ObjEffect_SetVertexColor(objv,0,0,255,200,200);
			ObjEffect_SetVertexColor(objv,1,0,255,200,200);
			ObjEffect_SetVertexColor(objv,2,0,255,200,200);
			ObjEffect_SetVertexColor(objv,3,0,255,200,200);
		}
	}
	if(type==4)
	{
		if(y<=GetClipMinY)
		{
			ObjEffect_SetVertexColor(objv,0,255,255,150,255);
			ObjEffect_SetVertexColor(objv,1,255,255,150,255);
			ObjEffect_SetVertexColor(objv,2,100,255,150,255);
			ObjEffect_SetVertexColor(objv,3,100,255,150,255);
		}
		else
		{
			ObjEffect_SetVertexColor(objv,0,0,255,200,200);
			ObjEffect_SetVertexColor(objv,1,0,255,200,200);
			ObjEffect_SetVertexColor(objv,2,0,255,200,200);
			ObjEffect_SetVertexColor(objv,3,0,255,200,200);
		}
	}
	if(type==5)
	{
		if(y<=GetClipMinY)
		{
			ObjEffect_SetVertexColor(objv,0,255,100,255,100);
			ObjEffect_SetVertexColor(objv,1,255,100,255,100);
			ObjEffect_SetVertexColor(objv,2,255,100,255,100);
			ObjEffect_SetVertexColor(objv,3,255,100,255,100);
		}
		else
		{
			ObjEffect_SetVertexColor(objv,0,0,255,200,200);
			ObjEffect_SetVertexColor(objv,1,0,255,200,200);
			ObjEffect_SetVertexColor(objv,2,0,255,200,200);
			ObjEffect_SetVertexColor(objv,3,0,255,200,200);
		}
	}
}

task SCBItem//SCB獲得時にボーナスアイテムを出現させる
{
let DBonusItem;
alternative(SelectedDifficult)
case("Easy")
{
	DBonusItem=1;
}
case("Normal")
{
	DBonusItem=2;
}
case("Hard")
{
	DBonusItem=3;
}
case("Lunatic")
{
	DBonusItem=4;
}
let r=200;
	loop
	{
		while(!OnEnemySpell)
		{yield;}

		let SpellBonus;

		while(OnEnemySpell)
		{
			SpellBonus = GetSpellCardBonusScore();
			yield;
			if(GetEnemyLife() == 0){break;}
		}
		while(OnEnemySpell){yield;}
		wait(15);
		if(SpellBonus!=0)
		{
			ascent(let i in 0..10*DBonusItem+10*(StageProgress-1))
			{
				Item(GetPlayerX+r*cos(i*5),GetPlayerY+r*sin(i*5),3);
				Item(GetPlayerX+r*cos(72+i*5),GetPlayerY+r*sin(72+i*5),3);
				Item(GetPlayerX+r*cos(144+i*5),GetPlayerY+r*sin(144+i*5),3);
				Item(GetPlayerX+r*cos(216+i*5),GetPlayerY+r*sin(216+i*5),3);
				Item(GetPlayerX+r*cos(288+i*5),GetPlayerY+r*sin(288+i*5),3);
				wait(1);
			}
		}
		wait(300);
	}
}

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

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

		task PlayCharacterAndDifficult
		{
			alternative(SelectedDifficult)
			case("Easy")
			{
				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,NsFrequencyMarisaAEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaAEasy,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyMarisaBEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaBEasy,Frequency);		
				}
				case(DefinedPlayer5)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyOthersEasy,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyOthersEasy,Frequency);		
				}
			}
			case("Normal")
			{
				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,NsFrequencyMarisaANormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaANormal,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyMarisaBNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaBNormal,Frequency);		
				}
				case(DefinedPlayer5)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyOthersNormal,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyOthersNormal,Frequency);		
				}
			}
			case("Hard")
			{
				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,NsFrequencyMarisaAHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaAHard,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyMarisaBHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaBHard,Frequency);		
				}
				case(DefinedPlayer5)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyOthersHard,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyOthersHard,Frequency);		
				}
			}
			case("Lunatic")
			{
				alternative(SelectedCharacter)
				case(DefinedPlayer1)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuALunatic,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuALunatic,Frequency);		
				}
				case(DefinedPlayer2)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyReimuBLunatic,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyReimuBLunatic,Frequency);		
				}
				case(DefinedPlayer3)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyMarisaALunatic,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaALunatic,Frequency);		
				}
				case(DefinedPlayer4)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyMarisaBLunatic,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyMarisaBLunatic,Frequency);		
				}
				case(DefinedPlayer5)
				{
					let Frequency=GetCommonDataDefaultEx(NsScore,NsFrequencyOthersLunatic,0);
					Frequency++;
					SetCommonDataEx(NsScore,NsFrequencyOthersLunatic,Frequency);		
				}
			}
			SetCommonData("SELECTEDDIFFICULT",SelectedDifficult);//選択難易度を受け渡すため保存
			alternative(SelectedDifficult)
			case("Easy")
			{
				SetCommonData("BONUSPOINT",25000);
			}
			case("Normal")
			{
				SetCommonData("BONUSPOINT",50000);
			}
			case("Hard")
			{
				SetCommonData("BONUSPOINT",75000);
			}
			case("Lunatic")
			{
				SetCommonData("BONUSPOINT",100000);
			}
		}
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////ステータス表示部//////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
task DifficultDisplay
{
let num;
let dx;
	alternative(SelectedDifficult)
	case("Easy")
	{
		num=0;
		dx=24;
	}
	case("Normal")
	{
		num=1;
		dx=8;
	}
	case("Hard")
	{
		num=2;
		dx=24;
	}
	case("Lunatic")
	{
		num=3;
		dx=6;
	}
	case("Extra")
	{
		num=4;
		dx=0;
	}
	others
	{
		num=4;
		dx=0;
	}
loop
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgDifficult);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -7);
		ObjEffect_SetVertexXY(obj, 1, 88,  -7);
		ObjEffect_SetVertexXY(obj, 2, 88, 7);
		ObjEffect_SetVertexXY(obj, 3,  0,  7);
		
		ObjEffect_SetVertexUV(obj, 0,  5,  9+23*num);
		ObjEffect_SetVertexUV(obj, 1,  92, 9+23*num);
		ObjEffect_SetVertexUV(obj, 2, 92,  23+23*num);
		ObjEffect_SetVertexUV(obj, 3, 5, 23+23*num);
		ObjEffect_SetLayer(obj,8);
		Obj_SetPosition(obj,GetClipMaxX+64+dx,GetClipMinY+16);

		yield;
		Obj_Delete(obj);
}
}

task StatusDisplay
{
loop
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgDifficult);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, 0, -74);
		ObjEffect_SetVertexXY(obj, 1, 70,  -74);
		ObjEffect_SetVertexXY(obj, 2, 70, 74);
		ObjEffect_SetVertexXY(obj, 3,  0,  74);
		
		ObjEffect_SetVertexUV(obj, 0,  145,  8);
		ObjEffect_SetVertexUV(obj, 1,  215, 8);
		ObjEffect_SetVertexUV(obj, 2, 215,  156);
		ObjEffect_SetVertexUV(obj, 3, 145, 156);
		ObjEffect_SetLayer(obj,8);
		ObjEffect_SetScale(obj,1,1.2);
		Obj_SetPosition(obj,GetClipMaxX+20,GetClipMinY+120);

		yield;
		Obj_Delete(obj);
}
}

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);
	}
	if(GetCommonDataDefault("BombBonus",0)==1)
	{
		DisPlayBombStarHalf(bomb);
	}
		
yield;
}
}

task DisPlayPlayerStar(i)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgPlayerAndBomb);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ALPHA); 
		ObjEffect_CreateVertex(obj, 4);
		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,  2,  320);
		ObjEffect_SetVertexUV(obj, 1,  17, 320);
		ObjEffect_SetVertexUV(obj, 2, 17,  335);
		ObjEffect_SetVertexUV(obj, 3, 2, 335);
		ObjEffect_SetLayer(obj,8);
		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_SetScale(obj,0.9,0.9);
		Obj_SetPosition(obj,GetClipMaxX+100+16*i,GetClipMinY+105);
		yield;
		Obj_Delete(obj);
}

task DisPlayBombStar(i)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgPlayerAndBomb);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ALPHA); 
		ObjEffect_CreateVertex(obj, 4);
		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,  62,  320);
		ObjEffect_SetVertexUV(obj, 1,  77, 320);
		ObjEffect_SetVertexUV(obj, 2, 77,  335);
		ObjEffect_SetVertexUV(obj, 3, 62, 335);
		ObjEffect_SetLayer(obj,8);
		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_SetScale(obj,0.9,0.9);
		Obj_SetPosition(obj,GetClipMaxX+100+16*i,GetClipMinY+132);
		yield;
		Obj_Delete(obj);
}

task DisPlayBombStarHalf(i)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgPlayerAndBomb);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ALPHA); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -4, -8);
		ObjEffect_SetVertexXY(obj, 1, 4,  -8);
		ObjEffect_SetVertexXY(obj, 2, 4, 8);
		ObjEffect_SetVertexXY(obj, 3,  -4,  8);
		
		ObjEffect_SetVertexUV(obj, 0,  62,  320);
		ObjEffect_SetVertexUV(obj, 1,  70, 320);
		ObjEffect_SetVertexUV(obj, 2, 70,  335);
		ObjEffect_SetVertexUV(obj, 3, 62, 335);
		ObjEffect_SetLayer(obj,8);
		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_SetScale(obj,0.9,0.9);
		Obj_SetPosition(obj,GetClipMaxX+96+16*i,GetClipMinY+132);
		yield;
		Obj_Delete(obj);
}

task DisPlayScore
{
let EachHiScore=0;
	alternative(SelectedDifficult)
	case("Easy")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAEasy[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBEasy[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaAEasy[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaBEasy[0],0);		
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreOthersEasy[0],0);		
		}
	}
	case("Normal")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuANormal[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBNormal[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaANormal[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaBNormal[0],0);		
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreOthersNormal[0],0);		
		}
	}
	case("Hard")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAHard[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBHard[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaAHard[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaBHard[0],0);		
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreOthersHard[0],0);		
		}
	}
	case("Lunatic")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuALunatic[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBLunatic[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaALunatic[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaBLunatic[0],0);		
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreOthersLunatic[0],0);		
		}
	}
	case("Extra")
	{
		alternative(SelectedCharacter)
		case(DefinedPlayer1)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuAExtra[0],0);
		}
		case(DefinedPlayer2)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreReimuBExtra[0],0);
		}
		case(DefinedPlayer3)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaAExtra[0],0);
		}
		case(DefinedPlayer4)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreMarisaBExtra[0],0);		
		}
		case(DefinedPlayer5)
		{
			EachHiScore=GetCommonDataDefaultEx(NsScore,NsHiScoreOthersExtra[0],0);		
		}
	}
loop
{
if(GetScore>=EachHiScore)
{
	EachHiScore=GetScore;
}
DisPlayNumber(GetClipMaxX+210,GetClipMinY+42,NumToString(EachHiScore),0);
DisPlayNumber(GetClipMaxX+210,GetClipMinY+72,GetScore,0);
yield;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////インクルード部////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
#include_function ".\txt/data.txt"
#include_function ".\txt/stagedata.txt"
#include_function ".\txt/hiscore.txt"
#include_function ".\txt/MENU.txt"
#include_function ".\txt/MENUDRAW.txt"
#include_function ".\txt/SpellName.txt"
#include_function ".\stage1/STAGE1.txt"
#include_function ".\stage2/STAGE2.txt"
#include_function ".\stage3/STAGE3.txt"
#include_function ".\secret/SecretSpell.txt"

}