task TPlayerScene(previousMenu){
	let bEndScene = false;
	let playerDescribtion = "";
	let pathPlayerImage = dir ~ "./Image/player_menu.png";
	let pathTitle = dir ~ "./Image/menu.png";

	let objTitleImage = ObjPrim_Create(OBJ_SPRITE_2D); 
	Obj_SetRenderPriorityI(objTitleImage, 20);
	ObjPrim_SetTexture(objTitleImage, pathTitle);
	ObjSprite2D_SetSourceRect(objTitleImage, 0, 0, 800, 600);
	ObjSprite2D_SetDestRect(objTitleImage, 0, 0, 640, 480);
	ObjRender_SetAlpha(objTitleImage,120);

	let objTitleText = ObjText_Create();
	ObjText_SetFontType(objTitleText,"Blogger Sans");
	ObjText_SetText(objTitleText, "Player select");
	ObjText_SetFontSize(objTitleText, 50);
	ObjText_SetFontColorTop(objTitleText, 255, 255, 255);
	ObjText_SetFontColorBottom(objTitleText, 255, 255, 255);
	Obj_SetRenderPriorityI(objTitleText, 30);
	ObjRender_SetX(objTitleText, 135);
	ObjRender_SetY(objTitleText, 20);
	
	let objReimu = ObjPrim_Create(OBJ_SPRITE_2D); 
	Obj_SetRenderPriorityI(objReimu, 21);
	ObjPrim_SetTexture(objReimu, pathPlayerImage);
	ObjSprite2D_SetSourceRect(objReimu, 0, 0, 190, 240);
	ObjSprite2D_SetDestCenter(objReimu);
	ObjRender_SetPosition(objReimu,90,160,0);
	ObjRender_SetAlpha(objReimu,0);
	
	let objMarisa = ObjPrim_Create(OBJ_SPRITE_2D); 
	Obj_SetRenderPriorityI(objMarisa, 21);
	ObjPrim_SetTexture(objMarisa, pathPlayerImage);
	ObjSprite2D_SetSourceRect(objMarisa, 190, 0, 380, 240);
	ObjSprite2D_SetDestCenter(objMarisa);
	ObjRender_SetPosition(objMarisa,90,160,0);
	ObjRender_SetAlpha(objMarisa,0);
	
	let objPlayerText = ObjText_Create();
	ObjText_SetFontType(objPlayerText,"Blogger Sans");
	ObjText_SetText(objPlayerText, playerDescribtion);
	ObjText_SetFontSize(objPlayerText, 25);
	ObjText_SetFontColorTop(objPlayerText, 255, 255, 200);
	ObjText_SetFontColorBottom(objPlayerText, 255, 200, 128);
	Obj_SetRenderPriorityI(objPlayerText, 30);
	ObjRender_SetX(objPlayerText, 130);
	ObjRender_SetY(objPlayerText, 300);

	let INDEX_REIMU_A = 0;
	let INDEX_REIMU_B = 1;
	let INDEX_REIMU_C = 2;
	let INDEX_MARISA_A = 3;
	let INDEX_MARISA_B = 4;
	let INDEX_MARISA_C = 5;
	let selectIndexPlayer = 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_SetFontSize(obj, 30);
			ObjText_SetFontType(obj,"Blogger Sans");
			ObjText_SetFontColorTop(obj, 255, 255, 255);
			ObjText_SetFontColorBottom(obj, 255, 255, 255);
			Obj_SetRenderPriorityI(obj, 30);
			ObjRender_SetX(obj, mx);
			ObjRender_SetY(obj, my);
			return obj;}

		let scaleSS = 0;
		let difText = CreateTextObject(555,435,dif);
		let objText = CreateTextObject(mx, my, text);
			loop(20){
				ObjRender_SetScaleX(objText,scaleSS);
				ObjRender_SetScaleX(difText,scaleSS);
				ObjRender_SetScaleX(objPlayerText,scaleSS);
				ObjRender_SetScaleX(objTitleText,scaleSS);
			scaleSS+=0.05;yield;}

	let move1 = 0;
	let moveA = 0;
	let move2 = 0;
	let moveB = 0;
	let scale = 1;
	
	let alphaR = 0;
	let alphaM = 0;
		
	while(!bEndScene){
		ObjText_SetText(objPlayerText, playerDescribtion);
		ObjRender_SetAlpha(objReimu,alphaR);
		ObjRender_SetAlpha(objMarisa,alphaM);
		alternative(selectIndexPlayer)
			case(INDEX_REIMU_A){ alphaR+=6;alphaM-=8;
				playerDescribtion = "Standard Type[r][r]Shot: Homing Amulet - Persuasion Needle[r]
						Spell: Divine Spirit \"Fantasy Seal\"[r]    Dream Sign \"Evil-Sealing Circle\"[r]    Border World \"Hakurei Danmaku Barrier\"";}
			case(INDEX_REIMU_B){ alphaR+=6;alphaM-=8;
				playerDescribtion = "Youkai Extermination Type[r][r]Shot: Youkai Buster - Extermination[r]
						Spell: Divine Art \"Demon Binding Ring\"[r]    Holy Relic \"Yin-Yang Demon God Orb\"[r]    Dream Land \"Super Duplex Barrier\"";}
			case(INDEX_REIMU_C){ alphaR+=6;alphaM-=8;
				playerDescribtion = "Amulet Type[r][r]Shot: Spread Amulet - Hakurei Amulet[r]
						Spell: Spirit Sign \"Fantasy Seal -Spread-\"[r]    Spirit Sign \"Fantasy Seal -Marred-\"[r]    \"Fantasy Heaven\"";}
			case(INDEX_MARISA_A){ alphaR-=6;alphaM+=8;
				playerDescribtion = "Standard Type[r][r]Shot: Magic Napalm - Magic Missile[r]
						Spell: Light Blast \"Shoot the Moon\"[r]    Magic Waste \"Deep Ecological Bomb\"[r]    Black Magic \"Event Horizon\"";}
			case(INDEX_MARISA_B){ alphaR-=6;alphaM+=8;
				playerDescribtion = "Laser Type[r][r]Shot: Illusion Laser - Mini Spark[r]
						Spell: Love Storm \"Starlight Typhoon\"[r]    Love Sign \"Master Spark\"[r]    Perversion \"Sure-Fire Master Spark\"";}
			case(INDEX_MARISA_C){ alphaR-=6;alphaM+=8;
				playerDescribtion = "Star Type[r][r]Shot: Gravity Star - Magic Star[r]
						Spell: Ritual Sign \"Orreries Sun\"[r]    Magic Sign \"Milky Way\"[r]    \"Blazing Star\"";}

			if(alphaR <= 0){alphaR = 0;}
			if(alphaR >= 255){alphaR = 255;}
			if(alphaM <= 0){alphaM = 0;}
			if(alphaM >= 255){alphaM = 255;}
			
		if(index == selectIndexPlayer){
			ObjRender_SetAlpha(objText,255);
			ObjRender_SetPosition(objText,mx-move1,my,0);
			move2=0;
			moveB=0;
			move1=15*sin(moveA);
			if(move1<4){moveA+=10;}}
		else{
			ObjRender_SetAlpha(objText,155);
			ObjRender_SetPosition(objText,mx-move1+move2,my,0);
			move1=0;
			moveA=0;
			move2=4*sin(moveB);
			if(move2<4){moveB+=10;}}
		
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
			loop(20){
				ObjRender_SetAlpha(objReimu,alphaR);
				ObjRender_SetAlpha(objMarisa,alphaM);
				ObjRender_SetScaleX(objPlayerText,scale);
				ObjRender_SetScaleX(objText,scale);
				ObjRender_SetScaleX(difText,scale);
				alphaR-=13;alphaM-=13;
				scale-=0.05;yield;}}
		yield;}
		
	Obj_Delete(objPlayerText);
	Obj_Delete(objReimu);
	Obj_Delete(objMarisa);
	Obj_Delete(objText);
	Obj_Delete(difText);}

	let mx = 150;
	let my = 80;
	let texts = ["Reimu Hakurei A","Reimu Hakurei B","Reimu Hakurei C",
				"Marisa Kirisame A","Marisa Kirisame B","Marisa Kirisame C"];
	var countMenu = length(texts);
	ascent(var iText in 0 .. countMenu){
		TMenuItem(iText, mx, my, texts[iText]);
		my+=30;}

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

	let startStage = false;
	let frameKeyHold = 0;
	loop{
		if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){
			SE(se_cancel);
			let scale = 1;
			let alpha = 120;
			loop(20){
				ObjRender_SetAlpha(objTitleImage,alpha);
				ObjRender_SetScaleX(objTitleText,scale);
				ObjRender_SetScaleX(objPlayerText,scale);
				scale-=0.05;alpha+=255/20;yield;}
			Obj_Delete(objTitleImage);
			Obj_Delete(objTitleText);
			Obj_Delete(objPlayerText);
			TTitleScene;
			bEndScene = true;
			return;}

		if(GetVirtualKeyState(VK_OK) == KEY_PUSH){
			if(selectIndexPlayer == INDEX_REIMU_A){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Reimu by plasmaflame22/Reimu_A.txt";
				T3StageScene("");
				startStage = true;}
				
			else if(selectIndexPlayer == INDEX_REIMU_B){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Reimu by plasmaflame22/Reimu_B.txt";
				T3StageScene("");
				startStage = true;}
				
			else if(selectIndexPlayer == INDEX_REIMU_C){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Reimu by plasmaflame22/Reimu_C.txt";
				T3StageScene("");
				startStage = true;}

			else if(selectIndexPlayer == INDEX_MARISA_A){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Marisa by plasmaflame22/Marisa_A.txt";
				T3StageScene("");
				startStage = true;}
				
			else if(selectIndexPlayer == INDEX_MARISA_B){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Marisa by plasmaflame22/Marisa_B.txt";
				T3StageScene("");
				startStage = true;}
				
			else if(selectIndexPlayer == INDEX_MARISA_C){
				SE(se_ok); TChoise; wait(85);
				pathPlayer = dir ~ "Player/Marisa by plasmaflame22/Marisa_C.txt";
				T3StageScene("");
				startStage = true;}
			break;}

		if(GetVirtualKeyState(VK_UP) == KEY_PUSH){selectIndexPlayer--;
			SE(se_select);}

		else if(GetVirtualKeyState(VK_DOWN) == KEY_PUSH){selectIndexPlayer++;
			SE(se_select);}

		else if(GetVirtualKeyState(VK_UP) == KEY_HOLD){
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0))){
				SE(se_select);
				selectIndexPlayer--;}}

		else if(GetVirtualKeyState(VK_DOWN) == KEY_HOLD){
			frameKeyHold++;
			if(frameKeyHold == 30 || (frameKeyHold > 30 && (frameKeyHold % 10 == 0))){
				SE(se_select);
				selectIndexPlayer++;}}

		else{frameKeyHold = -1;}
		if(selectIndexPlayer < 0) {selectIndexPlayer = countMenu-1;}
		else{selectIndexPlayer %= countMenu;}
		yield;}
	bEndScene = true;
	Obj_Delete(objTitleImage);
	Obj_Delete(objTitleText);
	Obj_Delete(objPlayerText);}

task TChoise{
	let path = GetCurrentScriptDirectory ~ "./Image/black.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,35);
	ObjPrim_SetTexture(obj,path);
	ObjSprite2D_SetSourceRect(obj,0,0,640,480);
	ObjSprite2D_SetDestRect(obj,0,0,640,480);
	let alpha = 0;
	loop(86){
		ObjRender_SetAlpha(obj,alpha);
		alpha+=3;yield;}
	Obj_Delete(obj);}