task TTitleScene{
	let bEndTitleScene = 0;
	_PlayBGM(1);

	ObjSprite2D_SetSourceRect(objTitleImage, 0, 0, 640, 480);
	ObjSprite2D_SetDestRect(objTitleImage, 0, 0, 640, 480);

	let objTitleText = ObjText_Create();
	ObjText_SetFontColorTop(objTitleText, 255, 255, 255);
	ObjText_SetFontColorBottom(objTitleText, 100, 100, 100);
	Obj_SetRenderPriority(objTitleText, 0.3);
	ObjText_SetFontType(objTitleText, "Russell Square Regular");
	ObjText_SetFontBorderWidth(objTitleText, 4);
	ObjText_SetFontBorderColor(objTitleText, 0,0,0);
	ObjText_SetFontBorderType(objTitleText, BORDER_FULL);
	ObjText_SetText(objTitleText, "Touhou Danmakufu Wars[r]  Koishi Komeji");
	ObjText_SetFontSize(objTitleText, 40);
	ObjText_SetFontBold(objTitleText, true);
	ObjRender_SetX(objTitleText, 48);
	ObjRender_SetY(objTitleText, 48);
	controlofthefuckingtitle;
	task controlofthefuckingtitle{
		let ta = 0;
		ascent(a in -30..1){
			ObjRender_SetX(objTitleText, 58+640-640*sin(90-90/30*a));
			yield;
		}
		while(bEndTitleScene == 0){
			ObjRender_SetX(objTitleText, 58+5*sin(ta));
			ta++;
			yield;
		}
		if(bEndTitleScene == 2){
			ascent(a in 1..31){
				ObjRender_SetX(objTitleText, 58+640*sin(90-90/30*a)-640);
				yield;
			}
		}
		Obj_Delete(objTitleText);
	}

	let selectIndex = 0;
	task TMenuItem(let index, let mx, let my, let text)
	{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontType(obj, "Russell Square Regular");
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 20);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 3);
			Obj_SetRenderPriorityI(obj, 30);
			ObjText_SetMaxWidth(obj,320);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my, text);
		let t = rand(0,360);
		ascent(a in -30..1){
			ObjRender_SetX(objText, mx+640-640*sin(90-90/30*a));
			yield;
		}
		while(bEndTitleScene == 0)
		{
			if(index == selectIndex){
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 255, 100, 100);
				ObjRender_SetX(objText, mx+5*cos(t));
			}
			else{
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 100, 100, 100);
				ObjRender_SetX(objText, mx+5*cos(t));
				t++;
			}
			yield;
		}
		if(bEndTitleScene == 2){
			ascent(a in 1..31){
				ObjRender_SetX(objText, mx+640*sin(90-90/30*a)-640);
				yield;
			}
		}
		Obj_Delete(objText);
	}

	let mx = 100;
	let texts = ["Start", "Replay", "Results", "Music Room", "Option", "Quit"];
	var countMenu = length(texts);
	let my = 40+24*(countMenu+3);
	ascent(var iText in 0 .. countMenu)
	{
		mx = -70+(iText%2)*60+120+floor(iText/2)*20;
		TMenuItem(iText, mx, my, texts[iText]);
		my += 24;
	}

	loop(30){if(GetVirtualKeyState(VK_OK) == KEY_FREE){loop(5){yield;}break;}yield;}

	let frameKeyHold = 0;
	while(!bEndTitleScene)
	{
		if(GetVirtualKeyState(VK_OK) == KEY_PUSH)
		{
			_PlaySE(5);
			if(selectIndex == 0){
				TStageScene("","Player");
				bEndTitleScene = 1;
			}
			if(selectIndex == countMenu-5){
				TReplaysScene();
				bEndTitleScene = 2;
			}
			if(selectIndex == countMenu-4){
				TResultsScene();
				bEndTitleScene = 2;
			}
			if(selectIndex == countMenu-3){
				TMusicRoomScene();
				bEndTitleScene = 2;
			}
			if(selectIndex == countMenu-2){
				TOptionScene();
				yield;
			}
			if(selectIndex == countMenu-1)
			{
                _PlaySE(6);
                SaveCommonDataAreaA2("Data",GetCurrentScriptDirectory ~ "data.dat");
                bEndTitleScene = 2;
                loop(1){yield;}
                ClosePackage();
                }
		}
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
	        _PlaySE(6);
            SaveCommonDataAreaA2("Data", GetCurrentScriptDirectory);
            bEndTitleScene = 2;
            loop(1){yield;}
            ClosePackage();
		}

		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex--;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex++;
		}
		else if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD || GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0)))
			{
				_PlaySE(4);
				selectIndex--;
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0)))
			{
				_PlaySE(4);
				selectIndex++;
			}
		}
		else
		{
			frameKeyHold = 0;
		}

		if(selectIndex < 0) 
		{
			selectIndex = countMenu - 1;
		}
		else
		{
			selectIndex %= countMenu;
		}

		yield;
	}
}

function TOptionScene(){
	let bEndTitleScene = false;
	let selectIndex = 0;

	task TMenuItem(let index, let mx, let my, let text)
	{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 20);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 3);
			Obj_SetRenderPriorityI(obj, 30);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my, text);
		let t = 0;
		while(!bEndTitleScene){
			if(index == selectIndex){
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 255, 100, 100);
			}
			else{
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 100, 100, 100);
			}
			if(text == "BGM"){
				ObjText_SetText(objText, text ~ " " ~ IntToString(GetAreaCommonData("Data","BGM",85)) ~ "%");
			}
			if(text == "SE"){
				ObjText_SetText(objText, text ~ "  " ~ IntToString(GetAreaCommonData("Data","SE",85)) ~ "%");
			}
			if(text == "Flashbomb"){
				ObjText_SetText(objText, text ~ " " ~ ["C","S","None"][GetAreaCommonData("Data","Flashbomb",0)]);
			}
			ObjRender_SetY(objText, 480-my*sin(t));
			t = min(90,t+90/15);
			yield;
		}
		loop(15){
			ObjRender_SetY(objText, 480-my*sin(t));
			t = min(180,t+90/15);
			yield;
		}
		Obj_Delete(objText);
	}

	let mx = 320;
	let texts = ["BGM", "SE","Flashbomb"];
	var countMenu = 2;
	let my = 40+24*(countMenu+2);
	ascent(var iText in 0 .. countMenu)
	{		TMenuItem(iText, mx, my, texts[iText]);
		my -= 24;
	}

	loop(30){if(GetVirtualKeyState(VK_OK) == KEY_FREE){loop(5){yield;}break;}yield;}

	let frameKeyHold = 0;
	let frameKeyHold2 = 0;
	loop
	{
		if(GetVirtualKeyState(VK_UP) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex--;
		}
		else if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex++;
		}
		else if(GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0)))
			{
				_PlaySE(4);
				selectIndex--;
			}
		}
		else if(GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0)))
			{
				_PlaySE(4);
				selectIndex++;
			}
		}
		else
		{
			frameKeyHold = 0;
		}
		if(selectIndex < 0) 
		{
			selectIndex = countMenu - 1;
		}
		else
		{
			selectIndex %= countMenu;
		}

		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
			_PlaySE(6);
			break;
		}
		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH)
		{
			_PlaySE(5);
			if(selectIndex == 0){
				let a = GetAreaCommonData("Data","BGM",85);
				SetAreaCommonData("Data","BGM", max(0,a-5));
			}
			else if(selectIndex == 1){
				let a = GetAreaCommonData("Data","SE",85);
				SetAreaCommonData("Data","SE", max(0,a-5));
			}
			else if(selectIndex == 2){
				let a = GetAreaCommonData("Data","Flashbomb",0);
				SetAreaCommonData("Data","Flashbomb", (a-1)%3);
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH)
		{
			_PlaySE(5);
			if(selectIndex == 0){
				let a = GetAreaCommonData("Data","BGM",85);
				SetAreaCommonData("Data","BGM", min(100,a+5));
				}
			else if(selectIndex == 1){
				let a = GetAreaCommonData("Data","SE",85);
				SetAreaCommonData("Data","SE", max(0,a+5));
			}
			else if(selectIndex == 2){
				let a = GetAreaCommonData("Data","Flashbomb",0);
				SetAreaCommonData("Data","Flashbomb", (a+1)%3);
			}
		}
		else if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD)
		{
			frameKeyHold2++;
			if(frameKeyHold2 == 30 || (frameKeyHold2 > 30 && (frameKeyHold2 % 10 == 0)))
			{
				_PlaySE(5);
				if(selectIndex == 0){
					let a = GetAreaCommonData("Data","BGM",85);
					SetAreaCommonData("Data","BGM", max(0,a-5));
					}
				else if(selectIndex == 1){
					let a = GetAreaCommonData("Data","SE",85);
					SetAreaCommonData("Data","SE", max(0,a-5));
				}
				else if(selectIndex == 2){
					let a = GetAreaCommonData("Data","Flashbomb",0);
					SetAreaCommonData("Data","Flashbomb", (a-1)%3);
				}
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD)
		{
			frameKeyHold2++;
			if(frameKeyHold2 == 30 || (frameKeyHold2 > 30 && (frameKeyHold2 % 10 == 0)))
			{
				_PlaySE(5);
				if(selectIndex == 0){
					let a = GetAreaCommonData("Data","BGM",85);
					SetAreaCommonData("Data","BGM", min(100,a+5));
					}
				else if(selectIndex == 1){
					let a = GetAreaCommonData("Data","SE",85);
					SetAreaCommonData("Data","SE", max(0,a+5));
				}
				else if(selectIndex == 3){
					let a = GetAreaCommonData("Data","Flashbomb",0);
					SetAreaCommonData("Data","Flashbomb", (a+1)%3);
				}
			}
		}
		else
		{
			frameKeyHold2 = 0;
		}

		yield;
	}
	bEndTitleScene = true;
}

task TResultsScene(){
	let bEndTitleScene = false;

	let objTitleText = ObjText_Create();
	ObjText_SetFontColorTop(objTitleText, 255, 255, 255);
	ObjText_SetFontColorBottom(objTitleText, 100, 100, 100);
	Obj_SetRenderPriority(objTitleText, 0.3);
	ObjText_SetFontType(objTitleText, "Russell Square Regular");
	ObjText_SetFontBorderWidth(objTitleText, 3);
	ObjText_SetFontBorderColor(objTitleText, 0,0,0);
	ObjText_SetFontBorderType(objTitleText, BORDER_FULL);
	ObjText_SetText(objTitleText, "Result");
	ObjText_SetFontSize(objTitleText, 30);
	ObjText_SetFontBold(objTitleText, true);
	ObjRender_SetX(objTitleText, 48);
	ObjRender_SetY(objTitleText, 48);
	controlofthefuckingtitle;
	task controlofthefuckingtitle{
		let ta = 0;
		ascent(a in -30..1){
			ObjRender_SetX(objTitleText, 58+640-640*sin(90-90/30*a));
			yield;
		}
		while(!bEndTitleScene){
			ObjRender_SetX(objTitleText, 58+5*sin(ta));
			ta++;
			yield;
		}
		ascent(a in 1..31){
			ObjRender_SetX(objTitleText, 58+640*sin(90-90/30*a)-640);
			yield;
		}
		Obj_Delete(objTitleText);
	}

	let selectIndex = 0;
	task TMenuItem(let index, let mx, let my, let text)
	{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 20);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 2.5);
			Obj_SetRenderPriorityI(obj, 29);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my-selectIndex*20+(index%10)*20, text);
		let t = rand(0,360);
		ascent(a in -30..1){
			ObjRender_SetX(objText, mx+640-640*sin(90-90/30*a));
			yield;
		}
		let zy = 0;
		while(!bEndTitleScene)
		{
			if(index == selectIndex){
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 255, 100, 100);
			}
			else{
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 100, 100, 100);
				t++;
			}

			ObjRender_SetAlpha(objText,255);

			yield;
		}
		ascent(a in 1..31){
			ObjRender_SetX(objText, mx+640*sin(90-90/30*a)-640);
			yield;
		}
		Obj_Delete(objText);
	}

	let mx = 70;
	let def_array = [];
	let data_array = GetAreaCommonData("Data","Results",[0,0,0,0,0,0,0,0,0,0]);
	ascent(a in 0..20){def_array = def_array~[0];}
	ascent(a in 0..length(data_array)){
		let b = 0;
		let en = false;
		loop(20){
			if(data_array[a] > def_array[b] && !en){
				descent(c in 0..length(def_array)-b-1){def_array[b+1+c] = def_array[b+c];}
				def_array[b] = data_array[a];
				en = true;
			}
			b++;
		}
	}
	SetAreaCommonData("Data","Results",def_array);

	let texts = def_array;
	var countMenu = length(texts);
	ascent(var iText in 0 .. countMenu)
	{
		TMenuItem(iText, mx+floor(iText/10)*320, 160, rtos("00",IntToString(iText+1)) ~ " " ~ rtos("000000000000",texts[iText]));
	}

	loop(30){if(GetVirtualKeyState(VK_OK) == KEY_FREE){loop(5){yield;}break;}yield;}

	let frameKeyHold = 0;
	while(!bEndTitleScene)
	{
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
	        _PlaySE(6);
	       	TTitleScene;
            bEndTitleScene = true;
		}

		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex--;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex++;
		}
		else if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD || GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex--;
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex++;
			}
		}
		else
		{
			frameKeyHold = 0;
		}

		if(selectIndex < 0) 
		{
			selectIndex = countMenu - 1;
		}
		else
		{
			selectIndex %= countMenu;
		}

		yield;
	}
}

task TReplaysScene(){
	let bEndTitleScene = 0;
	LoadReplayList();
	let listValidReplayIndex = GetValidReplayIndices();
	let maxcount = length(listValidReplayIndex);

	let objTitleText = ObjText_Create();
	ObjText_SetFontColorTop(objTitleText, 255, 255, 255);
	ObjText_SetFontColorBottom(objTitleText, 100, 100, 100);
	Obj_SetRenderPriority(objTitleText, 0.3);
	ObjText_SetFontType(objTitleText, "Russell Square Regular");
	ObjText_SetFontBorderWidth(objTitleText, 3);
	ObjText_SetFontBorderColor(objTitleText, 0,0,0);
	ObjText_SetFontBorderType(objTitleText, BORDER_FULL);
	ObjText_SetText(objTitleText, "Replays");
	ObjText_SetFontSize(objTitleText, 30);
	ObjText_SetFontBold(objTitleText, true);
	ObjRender_SetX(objTitleText, 48);
	ObjRender_SetY(objTitleText, 48);
	controlofthefuckingtitle;
	task controlofthefuckingtitle{
		let ta = 0;
		ascent(a in -30..1){
			ObjRender_SetX(objTitleText, 58+640-640*sin(90-90/30*a));
			yield;
		}
		while(bEndTitleScene == 0){
			ObjRender_SetX(objTitleText, 58+5*sin(ta));
			ta++;
			yield;
		}
		if(bEndTitleScene == 2){
			ascent(a in 1..31){
				ObjRender_SetX(objTitleText, 640*sin(90-90/30*a)-640);
				yield;
			}
		}
		Obj_Delete(objTitleText);
	}

	let selectIndex = 0;
	task TMenuItem(let index, let mx, let my, let text)
	{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 15);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 2.5);
			Obj_SetRenderPriorityI(obj, 29);
			ObjRender_SetX(obj, 0);
			ObjRender_SetY(obj, my);
			ObjText_SetMaxWidth(obj,640);
			ObjText_SetHorizontalAlignment(obj,ALIGNMENT_CENTER);
			return obj;
		}

		let objText = CreateTextObject(mx, my+selectIndex*20+index*20, text[(index+selectIndex)%length(text)]);
		let t = rand(0,360);
		ascent(a in -30..1){
			ObjRender_SetX(objText,640-640*sin(90-90/30*a));
			yield;
		}
		while(bEndTitleScene == 0)
		{
			if(0 == index){
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 255, 100, 100);
			}
			else{
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 100, 100, 100);
			}

			ObjText_SetText(objText,text[(index+selectIndex)%length(text)]);
			
			yield;
		}
		if(bEndTitleScene == 2){
			ascent(a in 1..31){
				ObjRender_SetX(objText, 640*sin(90-90/30*a)-640);
				yield;
			}
		}
		Obj_Delete(objText);
	}

	let texts = [];
	ascent(a in 0..100){
		if(a < maxcount){
			let indexReplay = listValidReplayIndex[a];
			if(IsValidReplayIndex(indexReplay)){
				let text = "";
				text = rtos("000", indexReplay) ~ " ";
				text = text ~ vtos("-8s", GetReplayInfo(indexReplay, REPLAY_USER_NAME)) ~ " ";
				text = text ~ rtos("000000000000", GetReplayInfo(indexReplay, REPLAY_TOTAL_SCORE)) ~ " ";
				text = text ~ GetReplayInfo(indexReplay, REPLAY_DATE_TIME) ~ " ";
				texts = texts ~ [text];			
			}	
			else{
				let text = "";
				text = rtos("000", 0) ~ " ";
				text = text ~ "--------" ~ " ";
				text = text ~ rtos("000000000000", 000000000000) ~ " ";
				text = text ~ "----/--/-- --:--" ~ " ";
				texts = texts ~ [text];			
			}
		}
			else{
				let text = "";
				text = rtos("000", 0) ~ " ";
				text = text ~ "--------" ~ " ";
				text = text ~ rtos("000000000000", 000000000000) ~ " ";
				text = text ~ "----/--/-- --:--" ~ " ";
				texts = texts ~ [text];			
			}
	}
	var countMenu = length(texts);
	ascent(var iText in 0 .. 16)
	{
		TMenuItem(iText, 0, 120, texts);
	}

	loop(30){if(GetVirtualKeyState(VK_OK) == KEY_FREE){loop(5){yield;}break;}yield;}

	let frameKeyHold = 0;
	while(bEndTitleScene == 0)
	{
		if(GetVirtualKeyState(VK_OK) == KEY_PULL)
		{
		 	_PlaySE(5);
			let indexList = selectIndex;
			if(indexList < maxcount) 
			{
				let result = listValidReplayIndex[indexList];
				let pathPlayer2 = GetReplayInfo(result, REPLAY_PLAYER_NAME);
				let pathReplay = GetReplayInfo(result, REPLAY_FILE_PATH);
				TStageScene(pathReplay,pathPlayer2);
				bEndTitleScene = 1;
			}
		}
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
	       	_PlaySE(6);
	       	TTitleScene;
           bEndTitleScene = 2;
		}

		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex--;
			if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH){
				selectIndex-=9;
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex++;
			if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH){
				selectIndex+=9;
			}
		}
		else if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD || GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex--;
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex++;
			}
		}
		else
		{
			frameKeyHold = 0;
		}

		if(selectIndex < 0) 
		{
			selectIndex = countMenu - 1;
		}
		else
		{
			selectIndex %= countMenu;
		}

		yield;
	}
}

task TMusicRoomScene(){
	let bEndTitleScene = false;

	let objTitleText = ObjText_Create();
	ObjText_SetFontColorTop(objTitleText, 255, 255, 255);
	ObjText_SetFontColorBottom(objTitleText, 100, 100, 100);
	Obj_SetRenderPriority(objTitleText, 0.3);
	ObjText_SetFontType(objTitleText, "Russell Square Regular");
	ObjText_SetFontBorderWidth(objTitleText, 3);
	ObjText_SetFontBorderColor(objTitleText, 0,0,0);
	ObjText_SetFontBorderType(objTitleText, BORDER_FULL);
	ObjText_SetText(objTitleText, "Music Room");
	ObjText_SetFontSize(objTitleText, 30);
	ObjText_SetFontBold(objTitleText, true);
	ObjRender_SetX(objTitleText, 48);
	ObjRender_SetY(objTitleText, 48);
	controlofthefuckingtitle;
	task controlofthefuckingtitle{
		let ta = 0;
		ascent(a in -30..1){
			ObjRender_SetX(objTitleText, 58+640-640*sin(90-90/30*a));
			yield;
		}
		while(!bEndTitleScene){
			ObjRender_SetX(objTitleText, 58+5*sin(ta));
			ta++;
			yield;
		}
		ascent(a in 1..31){
			ObjRender_SetX(objTitleText, 58+640*sin(90-90/30*a)-640);
			yield;
		}
		Obj_Delete(objTitleText);
	}

	let selectIndex = 0;
	task TMenuItem(let index, let mx, let my, let text)
	{
		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontType(obj, "Russell Square Regular");
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 15);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 2);
			Obj_SetRenderPriorityI(obj, 29);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my-selectIndex*15+index*15, text);
		let t = rand(0,360);
		ascent(a in -30..1){
			ObjRender_SetX(objText, mx+640-640*sin(90-90/30*a));
			yield;
		}
		let zy = 0;
		while(!bEndTitleScene)
		{
			if(index == selectIndex){
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 255, 100, 100);
			}
			else{
				ObjText_SetFontColorTop(objText, 255, 255, 255);
				ObjText_SetFontColorBottom(objText, 100, 100, 100);
			}

			ObjRender_SetAlpha(objText,255);
			if(zy != selectIndex){
				ObjRender_AddPatternA1(objText,mx, my-selectIndex*15+index*15,5);
				zy = selectIndex;
			}

			ascent(a in 0..5){
				if(my-selectIndex*15+index*15 <= my-(a+2)*15 && my-selectIndex*15+index*15 > my-(a+3)*15){
					ObjRender_SetAlpha(objText,255/5*(5-a));
				}
				else if(my-selectIndex*15+index*15 <= my-(5+2)*15){
					ObjRender_SetAlpha(objText,0);
				}
			}

			yield;
		}
		ascent(a in 1..31){
			ObjRender_SetX(objText, mx+640*sin(90-90/30*a)-640);
			yield;
		}
		Obj_Delete(objText);
	}
	task TTextBox(x,y,x2,y2, let text){
		let obj = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(obj,lineobj);
		ObjSpriteList2D_SetSourceRect(obj,0,0,1,1);
		ObjRender_SetAlpha(obj,180);
		ObjRender_SetColor(obj,0,0,0);
		Obj_SetRenderPriorityI(obj, 30);

		function CreateTextObject(let mx, let my, let text)
		{
			let obj = ObjText_Create();
			ObjText_SetText(obj, text);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontType(obj, "Russell Square Regular");
			ObjText_SetFontBorderColor(obj, 0,0,0);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontSize(obj, 15);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontBorderWidth(obj, 2);
			Obj_SetRenderPriorityI(obj, 31);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let xr = (x2-x)/2;
		let yr = (y2-y)/2;

		ascent(a in -30..1){
			let xl = -640*sin(90-90/30*a)+640;

			ObjSpriteList2D_ClearVertexCount(obj);

			ObjSpriteList2D_SetDestRect(obj,x+xl,y+yr+3,
				x2+xl,y+yr-3);
			ObjSpriteList2D_AddVertex(obj);

			yield;
		}

		let objText = CreateTextObject(x+10, y+10, "");
		let t = 0;
		while(!bEndTitleScene)
		{
			ObjSpriteList2D_ClearVertexCount(obj);

			ObjSpriteList2D_SetDestRect(obj,x,y+yr+(yr*min(1,t/10)-3)+3,
				x2,y+yr-(yr*min(1,t/10)-3)-3);
			ObjSpriteList2D_AddVertex(obj);

			if(t > 10){ObjText_SetText(objText, BGMNameList[selectIndex] ~ "[r]" ~ BGMTextList[selectIndex]);}

			t++;

			yield;
		}
		Obj_Delete(objText);
		ascent(a in 1..31){
			let xl = 640*sin(90-90/30*a)-640;
			ObjSpriteList2D_ClearVertexCount(obj);
			ObjSpriteList2D_SetDestRect(obj,x+xl,y,x2+xl,y2);
			ObjSpriteList2D_AddVertex(obj);
			yield;
		}
		Obj_Delete(obj);
	}

	let mx = 30;
	let texts = BGMNameList;
	var countMenu = length(texts);
	ascent(var iText in 0 .. countMenu)
	{
		TMenuItem(iText, mx, 160, texts[iText]);
	}
	TTextBox(250,240,640,480, "as");

	loop(30){if(GetVirtualKeyState(VK_OK) == KEY_FREE){loop(5){yield;}break;}yield;}

	let frameKeyHold = 0;
	while(!bEndTitleScene)
	{
		if(GetVirtualKeyState(VK_OK) == KEY_PUSH)
		{
			_PlaySE(5);
			_PlayBGM(0);
			loop(20){yield;}
			_PlayBGM(selectIndex+1);
		}
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
	       	_PlaySE(6);
	       	TTitleScene;
            bEndTitleScene = true;
		}

		if(GetVirtualKeyState(VK_LEFT) == KEY_PUSH || GetVirtualKeyState(VK_UP) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex--;
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_PUSH || GetVirtualKeyState(VK_DOWN) == KEY_PUSH)
		{
			_PlaySE(4);
			selectIndex++;
		}
		else if(GetVirtualKeyState(VK_LEFT) == KEY_HOLD || GetVirtualKeyState(VK_UP) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex--;
			}
		}
		else if(GetVirtualKeyState(VK_RIGHT) == KEY_HOLD || GetVirtualKeyState(VK_DOWN) == KEY_HOLD)
		{
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 5 == 0)))
			{
				_PlaySE(4);
				selectIndex++;
			}
		}
		else
		{
			frameKeyHold = 0;
		}

		if(selectIndex < 0) 
		{
			selectIndex = countMenu - 1;
		}
		else
		{
			selectIndex %= countMenu;
		}

		yield;
	}
}

task ObjRender_AddPatternA1(obj,x2,y2,t){
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
	let r = GetDis(x,y,x2,y2);
	let ang = GetAngA3(x,y,x2,y2);
	ascent(a in 1..t+1){
		ObjRender_SetPosition(obj,x+r*cos(-90+a/t*90)*cos(ang),y+r*cos(-90+a/t*90)*sin(ang),0);
		yield;
	}
	function GetAngA3(x1,y1,x2,y2){return atan2(y2-y1,x2-x1);}
	function GetDis(x1,y1,x2,y2){return((|((x2-x1)^2+(y2-y1)^2)^(1/2)|));}
}