function TPauseScript(){
	let bEndTitleScene = false;

	task TVertex(var index, var left, var top, var right, var bottom)
	{
		ObjPrim_SetVertexPosition(obj, index + 0, left, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 1, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 2, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 3, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 4, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 5, right, bottom, 0);

		ObjPrim_SetVertexUVT(obj, index + 0, left, top);
		ObjPrim_SetVertexUVT(obj, index + 1, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 2, right, top);
		ObjPrim_SetVertexUVT(obj, index + 3, right, top);
		ObjPrim_SetVertexUVT(obj, index + 4, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 5, right, bottom);

		//STGシーン内のみアニメーション
		if(true)
		{
			let alpha = 255;
			while(alpha >= 255)
			{
				ObjPrim_SetVertexAlpha(obj, index + 0, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 1, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 2, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 3, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 4, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 5, alpha);
				alpha -= 255 / frame;

				yield;
			}
		}
	}

	let frame = 30;
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjPrim_SetVertexCount(obj, 6);
	Obj_SetRenderPriorityI(obj, 3);
	ObjPrim_SetTexture(obj, GetCommonData("ImagePause","tru"));

	ascent(a in 0..1){TVertex(a*6, a*10,a*10,640-a*10,480-a*10);}

	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_SetFontType(obj, "Russell Square Regular");
			ObjText_SetText(obj, text);
			ObjText_SetFontSize(obj, 20);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBorderColor(obj,0, 0, 0);
			ObjText_SetFontBorderWidth(obj, 4);
			Obj_SetRenderPriorityI(obj, 100);
			ObjText_SetHorizontalAlignment(obj,ALIGNMENT_CENTER);
			ObjText_SetMaxWidth(obj,mx+mx);
			ObjRender_SetX(obj, mx-mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my, text);
		ascent(a in 1..31){
			ObjRender_SetAlpha(objText, 255*a/30);
			yield;
		}
		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);
			}
			yield;
		}
		Obj_Delete(objText);
	}

	let mx = GetStgFrameWidth/2;
	let my = GetStgFrameHeight/2-48;
	let texts = ["Close", "Repeat Stage", "Quit"];
	var countMenu = length(texts);
	ascent(var iText in 0 .. countMenu)
	{
		TMenuItem(iText, mx, my, texts[iText]);
		my += 32;
	}

	while(GetVirtualKeyState(VK_PAUSE) != KEY_FREE){yield;}

	let frameKeyHold = 0;
	loop
	{
		if(GetVirtualKeyState(VK_OK) == KEY_PULL){
			let listResult = [3,1,2];
			_PlaySE(8);
			wait(25);
			Obj_Delete(obj);
			bEndTitleScene = true;
			return listResult[selectIndex];
		}

		if(GetVirtualKeyState(VK_CANCEL) == KEY_PULL || GetVirtualKeyState(VK_PAUSE) == KEY_PULL)
		{
			_PlaySE(8);
			wait(25);
			Obj_Delete(obj);
			bEndTitleScene = true;
			return 0;
		}

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

		yield;
	}
}

function TEndScript(){
	let bEndTitleScene = false;

	task TVertex(var index, var left, var top, var right, var bottom)
	{
		ObjPrim_SetVertexPosition(obj, index + 0, left, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 1, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 2, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 3, right, top, 0);
		ObjPrim_SetVertexPosition(obj, index + 4, left, bottom, 0);
		ObjPrim_SetVertexPosition(obj, index + 5, right, bottom, 0);

		ObjPrim_SetVertexUVT(obj, index + 0, left, top);
		ObjPrim_SetVertexUVT(obj, index + 1, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 2, right, top);
		ObjPrim_SetVertexUVT(obj, index + 3, right, top);
		ObjPrim_SetVertexUVT(obj, index + 4, left, bottom);
		ObjPrim_SetVertexUVT(obj, index + 5, right, bottom);

		//STGシーン内のみアニメーション
		if(true)
		{
			let alpha = 255;
			while(alpha >= 255)
			{
				ObjPrim_SetVertexAlpha(obj, index + 0, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 1, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 2, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 3, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 4, alpha);
				ObjPrim_SetVertexAlpha(obj, index + 5, alpha);
				alpha -= 255 / frame;

				yield;
			}
		}
	}

	let frame = 30;
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLELIST);
	ObjPrim_SetVertexCount(obj, 6);
	Obj_SetRenderPriorityI(obj, 3);
	ObjPrim_SetTexture(obj, GetCommonData("ImagePause","tru"));

	ascent(a in 0..1){TVertex(a*6, a*10,a*10,640-a*10,480-a*10);}

	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_SetFontType(obj, "Russell Square Regular");
			ObjText_SetText(obj, text);
			ObjText_SetFontSize(obj, 20);
			ObjText_SetFontBold(obj, true);
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 100, 100, 100);
			ObjText_SetFontBorderType(obj, BORDER_FULL);
			ObjText_SetFontBorderColor(obj,0, 0, 0);
			ObjText_SetFontBorderWidth(obj, 4);
			Obj_SetRenderPriorityI(obj, 100);
			ObjText_SetHorizontalAlignment(obj,ALIGNMENT_CENTER);
			ObjText_SetMaxWidth(obj,mx+mx);
			ObjRender_SetX(obj, mx-mx);
			ObjRender_SetY(obj, my);
			return obj;
		}

		let objText = CreateTextObject(mx, my, text);
		ascent(a in 1..31){
			ObjRender_SetAlpha(objText, 255*a/30);
			yield;
		}
		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);
			}
			yield;
		}
		Obj_Delete(objText);
	}

	let mx = GetStgFrameWidth/2;
	let my = GetStgFrameHeight/2-48;
	let texts = ["Save Replay", "Repeat Stage", "Quit"];
	var countMenu = length(texts);
	ascent(var iText in 0 .. countMenu)
	{
		TMenuItem(iText, mx, my, texts[iText]);
		my += 32;
	}

	while(GetVirtualKeyState(VK_PAUSE) != KEY_FREE){yield;}

	let frameKeyHold = 0;
	loop
	{
		if(GetVirtualKeyState(VK_OK) == KEY_PULL){
			let listResult = [1,3,2];
			_PlaySE(8);
			wait(10);
			Obj_Delete(obj);
			bEndTitleScene = true;
			return listResult[selectIndex];
		}

		if(GetVirtualKeyState(VK_CANCEL) == KEY_PULL || GetVirtualKeyState(VK_PAUSE) == KEY_PULL)
		{
			_PlaySE(8);
			wait(10);
			Obj_Delete(obj);
			bEndTitleScene = true;
			return 2;
		}

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

		yield;
	}
}