
let MENU_END=0;
let MENU_TOP=1;
let MENU_LOCATION=2;
let MENU_MEMORY=3;
let MENU_TUNING=4;
let MENU_DIFFICULTY=5;


function GameMenu
{
	SetMusic(bgm[0],BGM_LOAD);
	SetMusic(bgm[0],BGM_PLAY);
	let menustate=1;
	let menu_from=MENU_TOP;
	let menu_number=0;
	let effect_l=2;
	
	let t_flg=memory_flg[9];
	
	
	Menu_BackGround(32,16,416,464);
	Menu_Text(t_flg);
	MenuState;
	Menu_Top(t_flg);
	
	SetMusic(bgm[0],BGM_FADEOUT_10);
	
	menu_flg=false;
	
	
	task MenuState
	{
		while(menu_flg)
		{
			ForbidShot(true);
			ForbidBomb(true);
			SetPlayerX(cenX);
			SetPlayerY(380);
			yield;
		}
		ForbidShot(false);
		ForbidBomb(false);
	}
	
	
	function Menu_Top(let trueflg)
	{
		let objlist=[];
		let max=5;
		if(trueflg){max=6;}
		ascent(a in 0..max)
		{
			let rect=[0,256,224,288];
			if(trueflg)
			{
				alternative(a)
				case(1){rect=[0,288,224,320];}
				case(2){rect=[0,320,144,352];}
				case(3){rect=[0,352,256,384];}
				case(4){rect=[0,384,80,416];}
				case(5){rect=[0,416,80,448];}
			}
			else
			{
				alternative(a)
				case(1){rect=[0,320,144,352];}
				case(2){rect=[0,352,256,384];}
				case(3){rect=[0,384,80,416];}
				case(4){rect=[0,416,80,448];}
			}
			
			let sx=60+a*30;
			let sy=80+a*45;
			
			let obj=[SetObjectText(sx,sy,rect,a,MENU_TOP)];
			objlist=objlist~obj;
		}
		while(menu_from>=MENU_TOP)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH){menu_number--;PlaySE(se[SE_MENU_SELECT]);}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){menu_number++;PlaySE(se[SE_MENU_SELECT]);}
			
			if(menu_number>=max){menu_number-=max;}
			else if(menu_number<0){menu_number+=max;}
			
			
			if(GetKeyState(VK_SHOT)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_DECIDE]);
				let GAMESTART=0;
				let PHANTASM=1;
				let LOCATION=2;
				let RESULT=3;
				let CONFIG=4;
				let EXIT=5;
				if(!trueflg)
				{
					LOCATION=1;
					RESULT=2;
					CONFIG=3;
					EXIT=4;
					PHANTASM=99;
				}
				alternative(menu_number)
				case(GAMESTART)		//FullSequenceOrder
				{
					SetEffect(GAMESTART);
					loop(30){yield;}
					if(tuning_difficulty==3)
					{
						menu_from=MENU_DIFFICULTY;
						
						Menu_Difficulty(objlist[GAMESTART],MENU_TOP);
					}
					else
					{
						menu_from=MENU_END;
						gamemode=tuning_difficulty;
					}
					menu_playstage=0;
				}
				case(PHANTASM)		//PhantasmagoriaTrues
				{
				}
				case(LOCATION)		//AreaLocation
				{
					SetEffect(LOCATION);
					loop(30){yield;}
					menu_from=MENU_LOCATION;
					let frame=Menu_Frame(Obj_GetX(objlist[LOCATION])-128,Obj_GetY(objlist[LOCATION]),2.5,1.5,MENU_LOCATION);
					Menu_Location(frame);
				}
				case(RESULT)		//Archivement of Memory
				{
					SetEffect(RESULT);
					loop(30){yield;}
					menu_from=MENU_MEMORY;
					let frame=Menu_Frame(-16,-16,6,4,MENU_MEMORY);
					
					Menu_Memory(frame);
				}
				case(CONFIG)		//Tuning
				{
					SetEffect(CONFIG);
					loop(30){yield;}
					menu_from=MENU_TUNING;
					let frame=Menu_Frame(Obj_GetX(objlist[CONFIG])+48,Obj_GetY(objlist[CONFIG])-64,2.4,1.8,MENU_TUNING);
					Menu_Tuning(frame);
				}
				case(EXIT)			//Away
				{
					SetEffect(EXIT);
					loop(60){yield;}
					SetClearFrameEffectEnable(false);
					ClearStage;
				}
			}
			
			task SetEffect(let number)
			{
				let rect=[0,256,256,288];
				if(trueflg)
				{
					alternative(number)
					case(1){rect=[0,288,224,320];}
					case(2){rect=[0,320,144,352];}
					case(3){rect=[0,352,256,384];}
					case(4){rect=[0,384,80,416];}
					case(5){rect=[0,416,80,448];}
				}
				else
				{
					alternative(number)
					case(1){rect=[0,320,144,352];}
					case(2){rect=[0,352,256,384];}
					case(3){rect=[0,384,80,416];}
					case(4){rect=[0,416,80,448];}
				}
				
				loop(effect_l)
				{
					SetObjectTextEffect(objlist[number],rect);
					yield;
				}
			}
			
			yield;
		}
		
		Menu_WhiteOut;
		wait(20);
	}
	
	
	
	
	function Menu_Location(let base)
	{
		menu_number=0;
		wait(15);
		let objlist=[];
		let max=9;
		ascent(a in 0..max)
		{
			let rect=[432,320,512,352];//1
			alternative(a)
			case(1){rect=[432,352,512,384];}//2
			case(2){rect=[432,384,512,416];}//3
			case(3){rect=[432,416,512,448];}//4
			case(4){rect=[432,448,512,480];}//5
			case(5){rect=[432,480,512,512];}//6
			
			case(6){rect=[256,416,416,448];}//u1
			case(7){rect=[256,448,416,480];}//u2
			case(8){rect=[256,480,416,512];}//u3
			let sx=Obj_GetX(base)-140;
			let sy=Obj_GetY(base)-75+a*32;
			if(a>=6)
			{
				sx=Obj_GetX(base)-10;
				sy=Obj_GetY(base)-75+(a-3)*32;
			}
			
			let obj=[SetObjectText(sx,sy,rect,a,MENU_LOCATION)];
			objlist=objlist~obj;
		}
		while(menu_from>=MENU_LOCATION)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH)
			{
				if(menu_number==0){menu_number+=6;}
				else if(menu_number==6){menu_number+=3;}
				menu_number--;
				PlaySE(se[SE_MENU_SELECT]);
			}
			if(GetKeyState(VK_DOWN)==KEY_PUSH)
			{
				if(menu_number==5){menu_number-=6;}
				else if(menu_number==8){menu_number-=3;}
				menu_number++;
				PlaySE(se[SE_MENU_SELECT]);
			}
			if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_PUSH)
			{
				if(menu_number<3){menu_number=6;}
				else if(menu_number<6){menu_number+=3;}
				else{menu_number-=3;}
				PlaySE(se[SE_MENU_SELECT]);
			}
			
			
			
			if(GetKeyState(VK_BOMB)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_CANCEL]);
				menu_from=MENU_TOP;
				menu_number=0;
				loop(10){yield;}
			}
			
			if(GetKeyState(VK_SHOT)==KEY_PUSH)
			{
				loop(1)
				{
					alternative(menu_number)
					case(0){if(!area1_standby){break;}}
					case(1){if(!area2_standby){break;}}
					case(2){if(!area3_standby){break;}}
					case(3){if(!area4_standby){break;}}
					case(4){if(!area5_standby){break;}}
					case(5){if(!area6_standby){break;}}
					case(6){if(!unseenarea1_standby){break;}}
					case(7){if(!unseenarea2_standby){break;}}
					case(8){if(!unseenarea3_standby){break;}}
					if(!memory_flg[menu_number]){break;}
					PlaySE(se[SE_MENU_DECIDE]);
					SetEffect(menu_number);
					loop(30){yield;}
					menu_playstage=menu_number+1;
					if(tuning_difficulty==3)
					{
						menu_from=MENU_DIFFICULTY;
						Menu_Difficulty(objlist[menu_number],MENU_LOCATION);
					}
					else
					{
						menu_from=MENU_END;
						gamemode=tuning_difficulty;
					}
				}
			}
			yield;
		}
		
		task SetEffect(let number)
		{
			let rect=[432,320,512,352];//1
			alternative(number)
			case(1){rect=[432,352,512,384];}//2
			case(2){rect=[432,384,512,416];}//3
			case(3){rect=[432,416,512,448];}//4
			case(4){rect=[432,448,512,480];}//5
			case(5){rect=[432,480,512,512];}//6
			
			case(6){rect=[256,416,416,448];}//u1
			case(7){rect=[256,448,416,480];}//u2
			case(8){rect=[256,480,416,512];}//u3
			
			loop(effect_l)
			{
				SetObjectTextEffect(objlist[number],rect);
				yield;
			}
		}
	}
	
	function Menu_Memory(let base)
	{
		let SCORE=0;
		let AREA=1;
		let STANDARD=2;
		let ADVANCED=3;
		let UNLIMITED=4;
		let PHANTASM=5;
		wait(15);
		local
		{
			let vx=240;let vy=24;
			let yp=16;
			//standard
			let sx=40;
			let sy=60;
			//if(!memory_flg[9]&&!memory_flg[10]){sy=180;}
			ObjectText(STANDARD,sx,sy-vy*2);
			ObjectText(SCORE,sx+60,sy-vy);
			ObjectText(AREA,sx+vx,sy-vy);
			ascent(a in 0..10)
			{
				Set(memory_highscore[a],sx,sy);
				Number(memory_highscore_stage[a],sx+vx,sy);
				sy+=yp;
			}
			
			//advanced
			sx=320+40;
			sy=60;
			//if(!memory_flg[9]&&!memory_flg[10]){sy=180;}
			ObjectText(ADVANCED,sx,sy-vy*2);
			ObjectText(SCORE,sx+60,sy-vy);
			ObjectText(AREA,sx+vx,sy-vy);
			ascent(a in 10..20)
			{
				Set(memory_highscore[a],sx,sy);
				Number(memory_highscore_stage[a],sx+vx,sy);
				sy+=yp;
			}
			
			//unlimited
			if(1)//if(memory_flg[10])
			{
				sx=40;
				if(!memory_flg[9]){sx=200;}
				sy=300;
				ObjectText(UNLIMITED,sx,sy-vy*2);
				ObjectText(SCORE,sx+60,sy-vy);
				ObjectText(AREA,sx+vx,sy-vy);
				ascent(a in 20..30)
				{
					Set(memory_highscore[a],sx,sy);
					Number(memory_highscore_stage[a],sx+vx,sy);
					sy+=yp;
				}
			}
				
			
			//phantasmagoria
			if(0)//if(memory_flg[9])
			{
				sx=320+40;
				sy=300;
				if(!memory_flg[10]){sx=200;}
				ObjectText(PHANTASM,sx,sy-vy*2);
				ObjectText(SCORE,sx+60,sy-vy);
				ObjectText(AREA,sx+vx,sy-vy);
				ascent(a in 30..40)
				{
					Set(memory_highscore[a],sx,sy);
					Number(memory_highscore_stage[a],sx+vx,sy);
					sy+=yp;
				}
			}
		}
		
		task Set(let scorenum,let sx,let sy)
		{
			let lp=floor(log10(scorenum))+1;
			let i=lp;
			loop(lp)
			{
				let leng=16;
				let posx=sx+(lp-i)*(leng/1.4);
				let posy=sy;
				let rc=(scorenum%(10^i)-scorenum%(10^(i-1)))/(10^(i-1));
				
				Number(rc,posx,posy);
				
				if((i)%4==1&&i>1)
				{
					Number(10,posx,posy);
				}
				i--;
			}
			if(scorenum==0)
			{
				Number(0,sx,sy);
			}
		}
		task ObjectText(let type,let sx,let sy)
		{
			let rect=[];
			alternative(type)
			case(SCORE){rect=[0,48,48,64];}
			case(AREA){rect=[448,32,496,48];}
			case(STANDARD){rect=[256,48,320,64];}
			case(ADVANCED){rect=[320,48,384,64];}
			case(UNLIMITED){rect=[384,48,448,64];}
			case(PHANTASM){rect=[448,48,512,64];}
			let obj=SetEffectObject(tex[TEX_SYSTEM],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
			Obj_SetPosition(obj,sx,sy);
			while(!Obj_BeDeleted(obj))
			{
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,255,255,255);
				}
				if(menu_from<MENU_MEMORY){Obj_Delete(obj);}
				yield;
			}
		}
		task Number(let num,let x,let y)
		{
			let obj=SetEffectObject(tex[TEX_SYSTEM],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			SetEffectObjectRect(obj,256+16*num,0,272+16*num,16);
			Obj_SetPosition(obj,x,y);
			while(!Obj_BeDeleted(obj))
			{
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,255,255,255);
				}
				if(menu_from<MENU_MEMORY){Obj_Delete(obj);}
				yield;
			}
		}
		
		
		while(menu_from>=MENU_MEMORY)
		{
			if(GetKeyState(VK_BOMB)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_CANCEL]);
				menu_from=MENU_TOP;
				menu_number=0;
				loop(10){yield;}
			}
			yield;
		}
	}
	
	
	
	function Menu_Tuning(let base)
	{
		menu_number=0;
		wait(15);
		let objlist=[];
		let max=5;
		ascent(a in 0..max)
		{
			let rect=[256,160,384,192];//difficulty
			alternative(a)
			case(1){rect=[256,192,384,224];}//lightmode
			case(2){rect=[256,224,384,256];}//playmusic
			case(3){rect=[256,256,384,288];}//continue
			case(4){rect=[256,288,384,320];}//datareset
			
			let sx=Obj_GetX(base)-120;
			let sy=Obj_GetY(base)-60+a*40;
			
			let obj=[SetObjectText(sx,sy,rect,a,MENU_TUNING)];
			objlist=objlist~obj;
			if(a<4){Select(a,sx,sy);}
		}
		
		let reset_trg=60;
		while(menu_from>=MENU_TUNING)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH){menu_number--;PlaySE(se[SE_MENU_SELECT]);}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){menu_number++;PlaySE(se[SE_MENU_SELECT]);}
			
			if(menu_number>=max){menu_number-=max;}
			else if(menu_number<0){menu_number+=max;}
			
			if(GetKeyState(VK_BOMB)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_CANCEL]);
				menu_from=MENU_TOP;
				menu_number=0;
				SetCommonData("Memory_ConfigData",memory_tuning);
				loop(10){yield;}
			}
			
			alternative(menu_number)
			case(0)
			{
				if(GetKeyState(VK_LEFT)==KEY_PUSH){tuning_difficulty--;PlaySE(se[SE_MENU_SELECT]);}
				if(GetKeyState(VK_RIGHT)==KEY_PUSH){tuning_difficulty++;PlaySE(se[SE_MENU_SELECT]);}
				
				tuning_difficulty=(tuning_difficulty+4)%4;
				memory_tuning[menu_number]=tuning_difficulty;
			}
			case(1)
			{
				if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_PUSH){tuning_lightmode++;PlaySE(se[SE_MENU_SELECT]);}
				tuning_lightmode=tuning_lightmode%2;
				memory_tuning[menu_number]=tuning_lightmode;
			}
			
			case(2)
			{
				if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_PUSH){tuning_playmusic++;PlaySE(se[SE_MENU_SELECT]);}
				tuning_playmusic=tuning_playmusic%2;
				memory_tuning[menu_number]=tuning_playmusic;
			}
			case(3)
			{
				if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_PUSH){tuning_continue++;PlaySE(se[SE_MENU_SELECT]);}
				tuning_continue=tuning_continue%2;
				memory_tuning[menu_number]=tuning_continue;
			}
			case(4)
			{
				if(GetKeyState(VK_SHOT)==KEY_HOLD){reset_trg--;}
				else{reset_trg=60;}
				
				if(reset_trg<0)
				{
					PlaySE(se[SE_MENU_DECIDE]);
					menu_from=MENU_TOP;
					menu_number=0;
					loop(20){yield;}
					MemoryReset;
				}
			}
			
			yield;
		}
		
		task Select(let num,let sx,let sy)
		{
			let obj=SetEffectObject(tex[TEX_SYSTEM],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			sx+=150;
			let rect=[];
			let alpha=255;
			while(!Obj_BeDeleted(obj))
			{
				alternative(num)
				case(0)
				{
					alternative(tuning_difficulty)
					case(0){rect=[400,160,512,192];}//Standard
					case(1){rect=[400,192,512,224];}//Advanced
					case(2){rect=[400,224,512,256];}//Unlimited
					case(3){rect=[400,256,512,288];}//Select
				}
				case(1)
				{
					if(tuning_lightmode){rect=[448,288,512,320];}
					else{rect=[384,288,448,320];}
				}
				case(2)
				{
					if(tuning_playmusic){rect=[448,288,512,320];}
					else{rect=[384,288,448,320];}
				}
				case(3)
				{
					if(tuning_continue){rect=[448,288,512,320];}
					else{rect=[384,288,448,320];}
				}
				if(num==menu_number){alpha=255;}
				else{alpha=48;}
				SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
				Obj_SetPosition(obj,sx+(rect[2]-rect[0])/2,sy+(rect[1]-rect[3])/2);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(menu_from<MENU_TUNING){Obj_Delete(obj);}
				yield;
			}
		}
	}
	
	
	
	function Menu_Difficulty(let base,let prev)
	{
		menu_number=0;
		let frame=Menu_Frame(Obj_GetX(base)-24,Obj_GetY(base),1,0.8,MENU_DIFFICULTY);
		wait(15);
		let objlist=[];
		let max=3;
		ascent(a in 0..max)
		{
			let rect=[400,160,512,192];
			alternative(a)
			case(1){rect=[400,192,512,224];}
			case(2){rect=[400,224,512,256];}
			let sx=Obj_GetX(frame)-55;
			let sy=Obj_GetY(frame)-18+a*36;
			
			let obj=[SetObjectText(sx,sy,rect,a,MENU_DIFFICULTY)];
			objlist=objlist~obj;
		}
		while(menu_from>=MENU_DIFFICULTY)
		{
			if(GetKeyState(VK_UP)==KEY_PUSH){menu_number--;PlaySE(se[SE_MENU_SELECT]);}
			if(GetKeyState(VK_DOWN)==KEY_PUSH){menu_number++;PlaySE(se[SE_MENU_SELECT]);}
			
			if(menu_number>=max){menu_number-=max;}
			else if(menu_number<0){menu_number+=max;}
			
			if(GetKeyState(VK_BOMB)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_CANCEL]);
				menu_from=prev;
				menu_number=0;
				loop(10){yield;}
			}
			
			if(GetKeyState(VK_SHOT)==KEY_PUSH)
			{
				PlaySE(se[SE_MENU_DECIDE]);
				gamemode=menu_number%3;
				SetEffect(gamemode);
				loop(30){yield;}
				menu_from=MENU_END;
			}
			yield;
		}
		
		task SetEffect(let number)
		{
			let rect=[400,160,512,192];
			alternative(number)
			case(1){rect=[400,192,512,224];}
			case(2){rect=[400,224,512,256];}
			
			loop(effect_l)
			{
				SetObjectTextEffect(objlist[number],rect);
				yield;
			}
		}
	}
	
	
	
	function SetObjectText(let x,let y,let rect,let number,let state)
	{
		let obj=SetEffectObject(tex[TEX_SYSTEM],8);
		SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
		ObjEffect_SetRenderState(obj,ALPHA);
		Obj_SetPosition(obj,x+(rect[2]-rect[0])/2,y+(rect[1]-rect[3])/2);
		Run(obj);
		return obj;
		
		task Run(let obj)
		{
			let alpha=80;
			while(!Obj_BeDeleted(obj))
			{
				if(menu_from==state)
				{
					if(menu_number==number){alpha=240;}
					else{alpha=80;}
				}
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(menu_from<state){Obj_Delete(obj);}
				yield;
			}
		}
	}
	
	task SetObjectTextEffect(let baseobj,let rect)
	{
		let obj=SetEffectObject(tex[TEX_SYSTEM],8);
		SetEffectObjectRect(obj,rect[0],rect[1],rect[2],rect[3]);
		ObjEffect_SetRenderState(obj,ADD);
		Obj_SetPosition(obj,Obj_GetX(baseobj),Obj_GetY(baseobj));
		
		let xscale=1;
		let alpha=200;
		while(!Obj_BeDeleted(obj))
		{
			ObjEffect_SetScale(obj,xscale,1);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
			}
			xscale+=0.05;
			alpha-=10;
			if(alpha<10){Obj_Delete(obj);}
			yield;
		}
	}
	
	
	task Menu_Text(let trueflg)
	{
		Back;
		Text;
		task Text
		{
			let obj=SetEffectObject(tex[TEX_MENUTEXT],8);
			ObjEffect_SetRenderState(obj,ALPHA);
			Obj_SetPosition(obj,256,480-32);
			while(!Obj_BeDeleted(obj))
			{
				let rc=14;
				alternative(menu_from)
				case(MENU_TOP)
				{
					if(trueflg)
					{
						alternative(menu_number)
						case(0){rc=0;}
						case(1){rc=1;}
						case(2){rc=2;}
						case(3){rc=3;}
						case(4){rc=4;}
						case(5){rc=5;}
					}
					else
					{
						alternative(menu_number)
						case(0){rc=0;}
						case(1){rc=2;}
						case(2){rc=3;}
						case(3){rc=4;}
						case(4){rc=5;}
					}
				}
				case(MENU_DIFFICULTY)
				{
					alternative(menu_number)
					case(0){rc=6;}
					case(1){rc=7;}
					case(2){rc=8;}
				}
				case(MENU_TUNING)
				{
					alternative(menu_number)
					case(0){rc=9;}
					case(1){rc=10;}
					case(2){rc=11;}
					case(3){rc=12;}
					case(4){rc=13;}
				}
				
				SetEffectObjectRect(obj,0,64*rc,512,64+64*rc);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,255,255,255);
				}
				
				if(!menu_flg){Obj_Delete(obj);}
				yield;
			}
		}
		
		task Back
		{
			let obj=SetEffectObject(tex[TEX_MENUTEXT],8);
			SetEffectObjectRect(obj,0,960,512,1024);
			ObjEffect_SetRenderState(obj,SUBTRACT);
			Obj_SetPosition(obj,320,480-32);
			while(!Obj_BeDeleted(obj))
			{
				let color=128;
				ObjEffect_SetScale(obj,2,1);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,255,color,color,color);
				}
				if(menu_from==MENU_END){Obj_Delete(obj);}
				yield;
			}
		}
	}
	
	function Menu_Frame(let x,let y,let xscale,let yscale,let state)
	{
		let obj=SetEffectObject(tex[TEX_SYSTEM],8);
		SetEffectObjectRect(obj,128,128,256,256);
		ObjEffect_SetRenderState(obj,ALPHA);
		Run;
		return obj;
		task Run
		{
			let alpha=220;
			let limit=10;
			let count=0;
			let xsc=0;
			let ysc=0;
			while(!Obj_BeDeleted(obj))
			{
				let sx=x+64*xsc;
				let sy=y+64*ysc;
				Obj_SetPosition(obj,sx,sy);
				ObjEffect_SetScale(obj,xsc,ysc);
				
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(menu_from<state)
				{
					xsc-=xscale/limit;
					ysc-=yscale/limit;
					if(count>=limit){Obj_Delete(obj);}
					count++;
				}
				else
				{
					if(xsc<xscale){xsc+=xscale/limit;}
					if(ysc<yscale){ysc+=yscale/limit;}
				}
				yield;
			}
		}
	}
	
	task Menu_WhiteOut
	{
		loop(8)
		{
			WhiteOut;
			wait(2);
		}
		task WhiteOut
		{
			let obj=SetEffectObject(tex[TEX_WHITE],7);
			SetEffectObjectRect(obj,0,0,320,240);
			ObjEffect_SetRenderState(obj,ADD);
			Obj_SetPosition(obj,cenX,cenY);
			
			let count=0;
			let scale=1;
			let alpha=16;
			while(alpha>2)
			{
				ObjEffect_SetScale(obj,scale,scale);
				ascent(a in 0..4)
				{
					ObjEffect_SetVertexColor(obj,a,alpha,255,255,255);
				}
				if(count>40){alpha-=10;}
				else if(alpha<250){alpha+=2;}
				scale+=0.2;
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}
	
	task Menu_BackGround(let left,let up,let right,let down)
	{
		let obj=SetEffectObject(tex[TEX_FRAMEBACK],7);
		ObjEffect_SetRenderState(obj,ALPHA);
		
		let sx=left+(right-left)/2;
		let sy=up+(down-up)/2;
		let color=255;
		Obj_SetPosition(obj,sx,sy);
		
		let frame_y=0;
		while(!Obj_BeDeleted(obj))
		{
			
			SetEffectObjectRect(obj,left,up+frame_y,right,down+frame_y);
			ascent(a in 0..4)
			{
				ObjEffect_SetVertexColor(obj,a,255,color,color,color);
			}
			frame_y+=-1;
			if(!menu_flg){Obj_Delete(obj);}
			yield;
		}
	}
}
