SetCommonData("rank", "Normal"); 
CreateRenderTarget("tex");
CreateRenderTarget("target");
let path; let s=0; let stagestring="";
SetCommonData("stage", "0");

let pause=false;
ascent(i in 0..3){
SetAreaCommonData("graphic", i, 0);
}
let MainSTG = GetCurrentScriptDirectory;
let FuncSrc = GetCurrentScriptDirectory;
let frame = MainSTG~"/img/select00.png";
let MENU=0;
let MENU_TEXT2=[];
let DIF_TEXT=["Normal", "Hard"];
let MENU_COMMENT=[];
let objtex=[0, 0, 0, 0, 0, 0, 0];
let title=ObjPrim_Create(OBJ_SPRITE_2D);

let MENU_SELECT=0;
let aalpha=0;
let id=LoadScript(GetCurrentScriptDirectory~"/system/Default_Pause.txt");
InstallFont(MainSTG~"/system/COPRGTL.ttf");

let xa=250; let speed=0;
let start=false;
task MainMenu(MENU_TYPE){
alternative (MENU_TYPE)
case (0) {
}
case (1) {
MENU=1;
MainMenuA1;
}
case (2) {

}
yield;
}

task MenuReplay{
let rep;
MenuBG(3);
LoadReplayList;
GetValidReplayIndices;
loop(60){yield;}
let select=1;
KeyCheck;
let tex=["", "", "", "", "", "", "", "", "", "", ""];
ascent(i in 1..11){
if (IsValidReplayIndex(i)){
tex[i]=ToString(GetReplayInfo(i, REPLAY_USER_NAME)~"   "~GetReplayInfo(i, REPLAY_PLAYER_NAME)~"  "~IntToString(GetReplayInfo(i, REPLAY_TOTAL_SCORE)));}
else {tex[i]="No replay";}}
ascent(i in 1..length(tex)){DrawText(tex[i], i);}

task DrawText(string, number){
let ang=0;
let obj=ObjText_Create();
ObjText_SetFontSize(obj, 25);
ObjRender_SetPosition(obj, 32, 56+number*30, 0);
ObjText_SetFontBold(obj, false);
ObjText_SetFontType(obj, "メイリオ");
ObjText_SetFontBorderType(obj, BORDER_SHADOW);
ObjText_SetFontBorderWidth(obj, 2);
ObjText_SetFontBorderColor(obj, 40, 40, 40);
ObjText_SetText(obj, tex[number]);
while(!Obj_IsDeleted(obj)){
	if (select==number){
	ang+=8;
	ObjText_SetFontColorTop(obj, 220+35*sin(ang), 220+35*sin(ang), 220+35*sin(ang));
	ObjText_SetFontColorBottom(obj, 115+35*sin(ang), 115+35*sin(ang), 115+35*sin(ang));}
	else{
	ang=0;
	ObjText_SetFontColorTop(obj, 100, 100, 100);
	ObjText_SetFontColorBottom(obj, 100, 100, 100);
	}
if (MENU!=3){FadeOut;}
yield;}

function FadeOut{
let alpha=255;
loop(30){alpha-=255/30; ObjRender_SetAlpha(obj, alpha); yield;} Obj_Delete(obj);
}
}

task KeyCheck{
	loop(60){yield;}
	MENU_SELECT=0;
	while(MENU==3){
	if (GetVirtualKeyState(VK_DOWN)==KEY_PUSH){select++; if (select>length(tex)-1){select=1;}}
	if (GetVirtualKeyState(VK_UP)==KEY_PUSH){select--; if (select<1){select=length(tex)-1;}}
	if (GetVirtualKeyState(VK_BOMB)==KEY_PUSH){MENU=1; MainMenu(MENU);}
	if (GetVirtualKeyState(VK_SHOT)==KEY_PUSH){s=select; 
	alternative(GetReplayInfo(select, REPLAY_COMMENT))
	
	ReplayStage("1"); MENU=4;}
	yield;}
	}

}




task PlaySoundEffect(sound){
let se=ObjSound_Create;
ObjSound_Load(se, GetCurrentScriptDirectory~"system/se/"~sound~".wav");
ObjSound_SetVolumeRate(se, 40);
ObjSound_Play(se);
}
task Stage(stageid){
		loop(60){yield;}
		if (!IsReplay){SetCommonData("stage", stageid);}
		let string=ToString(stageid);
		descent(i in 1..length(string)){string=erase(string, i);}
		path=GetCurrentScriptDirectory~"stagescrap.txt";
		InitializeStageScene;
		
		SetStageIndex(stageid);
		SetStageMainScript(path);
		SetStagePlayerScript(GetCurrentScriptDirectory~"/player/pl_seija/pl_seija.txt");
		
		StartStageScene;

		while(GetStageSceneState!=STAGE_STATE_FINISHED){
		RenderToTextureA1("target", 0, 89, true);
		if(GetVirtualKeyState(VK_PAUSE) == KEY_PUSH)
		{PlaySoundEffect("se_pause");
			let resPause = RunPauseScene();
			alternative(resPause)
			case(RESULT_RETRY)
			{
				//最初からやり直ぁE
				if(!IsReplay())
				{
					//リトライ
					TerminateStageScene();
					MENU=4;
					Stage(stagestring);
					return;
				}
			}
			case(RESULT_END)
			{
			MENU=1; MainMenuA1;
			TerminateStageScene;
			}
		}
		
		yield;}
		FinalizeStageScene;
		
		if (GetStageSceneResult!=STAGE_RESULT_BREAK_OFF){
		let resEnd=RunEndScene;
		alternative(resEnd)
		case (RESULT_SAVE_REPLAY){
		StartScript(LoadScript(GetCurrentScriptDirectory~"/System/Default_ReplaySaveScene.txt"));
		}
		case (RESULT_RETRY){TerminateStageScene; 
		Stage(stagestring); return;}
		case (RESULT_END){
			MENU=1; MainMenuA1;
			TerminateStageScene;}}
}

task ReplayStage(stageid){
SetAreaCommonData("stage", 0, stageid);
		loop(60){yield;}
		let string=ToString(stageid);
		descent(i in 1..length(string)){string=erase(string, i);}
		path=GetCurrentScriptDirectory~"stagescrap.txt";
		InitializeStageScene;
		SetStageReplayFile(GetReplayInfo(s, REPLAY_FILE_PATH));
		SetStageIndex(stageid);
		SetStageMainScript(path);
		SetStagePlayerScript(GetCurrentScriptDirectory~"/player/pl_seija/pl_seija.txt");
		StartStageScene;
		while(GetStageSceneState!=STAGE_STATE_FINISHED){
		RenderToTextureA1("target", 0, 89, true);
		if(GetVirtualKeyState(VK_PAUSE) == KEY_PUSH)
		{PlaySoundEffect("se_pause");
			let resPause = RunPauseScene();
			alternative(resPause)
			case(RESULT_RETRY)
			{
				//最初からやり直ぁE
				
					//リトライ
					TerminateStageScene();
					MENU=4;
					ReplayStage(stageid);
					return;
			}
			case(RESULT_END)
			{
			MENU=1; MainMenuA1;
			TerminateStageScene;
			}
		}
		
		yield;}
		
		FinalizeStageScene;
	
		if (GetStageSceneResult!=STAGE_RESULT_BREAK_OFF){
		let resEnd=RunEndScene;
		alternative(resEnd)
		case (RESULT_SAVE_REPLAY){
		StartScript(LoadScript(GetCurrentScriptDirectory~"/System/Default_ReplaySaveScene.txt"));
		}
		case (RESULT_RETRY){TerminateStageScene; 
		MENU=4;
		ReplayStage(stageid); return;}
		case (RESULT_END){
			MENU=1; MainMenuA1;}}
		
}

function RunEndScene()
{

let endgame=true;
SetInvalidRenderPriorityA1(0, 89);


	task TVertex(r, var left, var top, var right, var bottom, size, alpha)
	{
	//刁Eɲ設宁E
	let frame = 30;
	let countH = 20; //刁Eɲ数
	let countV = 30; 
	let width = 640 / countH;
	let height = 480 / countV;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D); //2D頂点ブジェクト生戁E
	Obj_SetRenderPriorityI(obj, 90); //描画優先度を設宁E
	ObjPrim_SetTexture(obj, "target"); //チE¯スチャを設宁E
	ObjSprite2D_SetSourceRect(obj, 0, 0, 640, 480);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAlpha(obj, alpha);
	//ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj, size, size, 0);
	ObjRender_SetPosition(obj, 320, 240, 0);
	while(endgame==true){
	yield;}
	ClearInvalidRenderPriority;
	Obj_Delete(obj);
	}
		ascent(r in 0..6)
		{
			TVertex(r, 0, 0, 640, 480, 1+r/60, 100-r*100/6);
		}
		
	PauseStageScene(true);

	let pathScript = GetCurrentScriptDirectory ~ "system/Default_EndScene.txt";

	//--------------------------------
	//一時停止シーンンスクリプト起勁E
	let idScript = LoadScript(pathScript);
	StartScript(idScript);

	while(!IsCloseScript(idScript))
	{
		yield;
	}
	endgame=false;

	let res = GetScriptResult(idScript);
	return res;
}


function RunPauseScene()
{pause=true;
SetInvalidRenderPriorityA1(0, 89);
RenderToTextureA1("target", 0, 89, true);

	task TVertex(r, var left, var top, var right, var bottom, size, alpha)
	{
	//刁Eɲ設宁E
	let frame = 30;
	let countH = 20; //刁Eɲ数
	let countV = 30; 
	let width = 640 / countH;
	let height = 480 / countV;
	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D); //2D頂点ブジェクト生戁E
	Obj_SetRenderPriorityI(obj, 90); //描画優先度を設宁E
	ObjPrim_SetTexture(obj, "target"); //チE¯スチャを設宁E
	ObjSprite2D_SetSourceRect(obj, 0, 0, 640, 480);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAlpha(obj, alpha);
	//ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj, size, size, 0);
	ObjRender_SetPosition(obj, 320, 240, 0);
	while(pause==true){
	yield;}
	ClearInvalidRenderPriority;
	Obj_Delete(obj);
	}
		ascent(r in 0..6)
		{
			TVertex(r, 0, 0, 640, 480, 1+r/60, 100-r*100/6);
		}
		
	PauseStageScene(true);

	let pathScript = GetCurrentScriptDirectory ~ "system/Default_Pause.txt";

	//--------------------------------
	//一時停止シーンンスクリプト起勁E
	let idScript = LoadScript(pathScript);
	StartScript(idScript);

	while(!IsCloseScript(idScript))
	{
		yield;
	}
	pause=false;

	PauseStageScene(false);

	let res = GetScriptResult(idScript);
	return res;
}


task MenuBG(menu){
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/title_bk00.png");
ObjSprite2D_SetSourceRect(obj, 0, 0, 1280, 960);
ObjSprite2D_SetDestRect(obj, 0, 0, 640, 480);
Obj_SetRenderPriority(obj, 0.1);
while(MENU==menu){yield;}
loop(60){yield;}
Obj_Delete(obj);
}

task LoadingScreen{

LoadScreen; loop(120){yield;}
	MENU=1; 
	MainMenuA1;
}


task MenuBG2(menu){

		let t=0;
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/title_bk4.png");
ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);
ObjSprite2D_SetSourceRect(obj, 0,0,  1280, 960);
ObjRender_SetScaleXYZ(obj, 1, 1, 1);
ObjRender_SetAngleXYZ(obj,0,0,225);
ObjRender_SetColor(obj,186, 11, 92);
ObjSprite2D_SetDestCenter(obj);
ObjRender_SetAlpha(obj,130);
ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
Obj_SetRenderPriority(obj, 0.1);

while(MENU==menu){
t-=0.2;
ObjSprite2D_SetSourceRect(obj, 0+t, 0+t, 640+t, 480+t);
yield;}
loop(60){yield;}
Obj_Delete(obj);


}

task MenuTittle(menu){
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/MenuTittle.png");
ObjSprite2D_SetSourceRect(obj, 0, 0, 620, 320);
ObjSprite2D_SetDestRect(obj, 0, 0,620, 320);
ObjRender_SetScaleXYZ(obj,0.65,0.65,0.65);
ObjRender_SetPosition(obj,GetScreenWidth/2-200,GetScreenHeight/2-120,0);
Obj_SetRenderPriority(obj, 30);
ascent(i in 0..60){
	ObjRender_SetAlpha(obj,i/10*i);
	yield;
}
while(MENU==menu){yield;}

Obj_Delete(obj);
}

task Version(menu)
{

	let text;
	let objText = ObjText_Create();
	alternative (menu)
	ObjText_SetFontSize(objText, 11);
	ObjText_SetFontType(objText,  "メイリオ");
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255,255,255);
	ObjText_SetFontColorBottom(objText, 255,255,255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText,0,0,0);
	ObjText_SetFontBorderWidth(objText, 1);
	ObjText_SetHorizontalAlignment(objText, ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(objText, GetScreenWidth() - 8);
	Obj_SetRenderPriority(objText, 0.7);
	ObjRender_SetX(objText, 0);
	ObjRender_SetY(objText, GetScreenHeight() - 15);

	while(MENU==menu)
	{
		
		text="Version 1.00a";
		ObjText_SetText(objText, text);

		yield;
	}
	
	loop(60){yield;}
	Obj_Delete(objText);
}

task Sihoulette(menu){
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/aSihoulette1.png");
ObjSprite2D_SetSourceRect(obj, 0, 0, 840, 600);
ObjSprite2D_SetDestRect(obj, 0, 0, 840, 600);
ObjRender_SetScaleXYZ(obj,0.7,0.7,0.7);
ObjRender_SetPosition(obj,20,GetScreenHeight/2-40,0);
Obj_SetRenderPriority(obj, 0.1);
ObjRender_SetColor(obj,0,0,0);
ascent(i in 0..30){
	ObjRender_SetAlpha(obj,i/2*i);
	yield;
}

let obj2=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"/img/aSihoulette2.png");
ObjSprite2D_SetSourceRect(obj2, 0, 0, 950, 600);
ObjSprite2D_SetDestRect(obj2, 0, 0, 950, 600);
ObjRender_SetScaleXYZ(obj2,0.7,0.7,0.7);
ObjRender_SetPosition(obj2,12,GetScreenHeight/2-70,0);
Obj_SetRenderPriority(obj2, 0.1);
ObjRender_SetColor(obj2,0,0,0);
ascent(i in 0..30){
	ObjRender_SetAlpha(obj2,i/2*i);
	yield;
}

let obj3=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj3, GetCurrentScriptDirectory~"/img/aSihoulette3.png");
ObjSprite2D_SetSourceRect(obj3, 0, 0, 950, 600);
ObjSprite2D_SetDestRect(obj3, 0, 0, 950, 600);
ObjRender_SetScaleXYZ(obj3,0.7,0.7,0.7);
ObjRender_SetPosition(obj3,0,GetScreenHeight/2-160,0);
Obj_SetRenderPriority(obj3, 0.1);
ObjRender_SetColor(obj3,0,0,0);
ascent(i in 0..30){
	ObjRender_SetAlpha(obj3,i/2*i);
	yield;
}

let obj4=ObjPrim_Create(OBJ_SPRITE_2D);
alternative (menu)
ObjPrim_SetTexture(obj4, GetCurrentScriptDirectory~"/img/aSihoulette4.png");
ObjSprite2D_SetSourceRect(obj4, 0, 0, 950, 600);
ObjSprite2D_SetDestRect(obj4, 0, 0, 950, 600);
ObjRender_SetScaleXYZ(obj4,0.7,0.7,0.7);
ObjRender_SetPosition(obj4,0,GetScreenHeight/2-280,0);
Obj_SetRenderPriority(obj4, 0.1);
ObjRender_SetColor(obj4,0,0,0);
ascent(i in 0..30){
	ObjRender_SetAlpha(obj4,i/2*i);
	yield;
}
while(MENU==menu){yield;}
loop(60){yield;}
Obj_Delete(obj);
Obj_Delete(obj2);
Obj_Delete(obj3);
Obj_Delete(obj4);
}

task LoadScreen{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);
ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/transition.png");
ObjSprite2D_SetDestRect(obj, 0, 0, 640, 480);
let alpha=0; let k=0;
loop(30){alpha+=255/30; 
ObjSprite2D_SetSourceRect(obj, k, k, 640+k, 480+k);
k++;
ObjRender_SetAlpha(obj, alpha); yield;}
loop(90){
ObjSprite2D_SetSourceRect(obj, k, k, 640+k, 480+k);
k++; yield;}
loop(30){
ObjSprite2D_SetSourceRect(obj, k, k, 640+k, 480+k);
k++; alpha-=255/30; ObjRender_SetAlpha(obj, alpha); yield;}
Obj_Delete(obj);
}


task PlayBGMs{
yield;
let objSound=ObjSound_Create;
ObjSound_Load(objSound, GetCurrentScriptDirectory~"/system/bgm/tittle.ogg");
ObjSound_SetLoopEnable(objSound, true);
ObjSound_SetSoundDivision(objSound, SOUND_BGM);
ObjSound_SetRestartEnable(objSound, true);
ObjSound_Play(objSound);
while(MENU==1||MENU==2){yield;}
Obj_Delete(objSound);
}


task MainMenuA1{
NotifyEventAll(EV_USER+11, 0);
PlayBGMs;
let sel=0;
let s2=0;
Version(1);
MenuBG(1);
MenuBG2(1);
loop(40){yield;}
//Sihoulette(1);
loop(60){yield;}		//threshold
MenuTittle(1);
loop(60){yield;}
Selections;
KeyCheck;
	task Selections{
	let k=0;
	let obj=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	let obj2=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	let plane=ObjPrim_Create(OBJ_SPRITE_2D);
	let tex=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	let tex2=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	let diftex=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	let diftex2=[ObjPrim_Create(OBJ_SPRITE_2D), ObjPrim_Create(OBJ_SPRITE_2D)];
	
	ascent(i in 0..3){ObjPrim_SetTexture(obj[i], GetCurrentScriptDirectory~"/system/img/mainmenu.png");
	ObjPrim_SetTexture(obj2[i], GetCurrentScriptDirectory~"/system/img/mainmenu.png");
	ObjPrim_SetTexture(tex[i], GetCurrentScriptDirectory~"/system/img/mainmenu.png");
	ObjPrim_SetTexture(tex2[i], GetCurrentScriptDirectory~"/system/img/mainmenu.png");}
	ascent(i in 0..2){ObjPrim_SetTexture(diftex[i], GetCurrentScriptDirectory~"/system/img/mainmenu.png");}
	
	ObjPrim_SetTexture(plane, GetCurrentScriptDirectory~"/system/img/mainmenu.png");
	ObjSprite2D_SetSourceRect(plane, 0, 512, 256, 768);
	ObjSprite2D_SetDestCenter(plane);
	ObjRender_SetPosition(plane, 150, 256, 0);
	
	ObjSprite2D_SetSourceRect(obj[0], 0, 0, 256, 256);
	ObjSprite2D_SetSourceRect(obj2[0], 256, 0, 512, 256);
	ObjSprite2D_SetSourceRect(tex[0], 512, 0, 768, 128);
	ObjSprite2D_SetSourceRect(tex2[0], 512, 128, 768, 256);
	
	
	ObjRender_SetPosition(obj[0], 110+250, 350+26, 0);					/////// GameStartPos
	ObjRender_SetPosition(obj2[0], 110+250, 350+26, 0);
	ObjRender_SetPosition(tex[0], 110+250, 350+26, 0);
	ObjRender_SetPosition(tex2[0], 110+250, 350+26, 0);
	ObjRender_SetScaleXYZ(tex[0],1.1,1.1,1.1);
	ObjRender_SetScaleXYZ(tex2[0],1.1,1.1,1.1);
	alphamenu(tex2[0]);alphamenu(tex[0]);
	
	ObjSprite2D_SetSourceRect(obj[1], 0, 256, 128, 384);
	ObjSprite2D_SetSourceRect(obj2[1], 128, 256, 256, 384);
	ObjSprite2D_SetSourceRect(tex[1], 512, 256, 768, 320);
	ObjSprite2D_SetSourceRect(tex2[1], 512, 320, 768, 384);
	
	
	ObjRender_SetPosition(obj[1], 100+230, 385+20, 0);						/////Replay Pos
	ObjRender_SetPosition(obj2[1], 100+230, 385+20, 0);
	ObjRender_SetPosition(tex[1], 100+230, 385+20, 0);
	ObjRender_SetPosition(tex2[1], 100+230, 385+20, 0);
	ObjRender_SetScaleXYZ(tex[1],1.2,1.2,1.2);
	ObjRender_SetScaleXYZ(tex2[1],1.2,1.2,1.2);
	alphamenu(tex2[1]);alphamenu(tex[1]);
	
	ObjSprite2D_SetSourceRect(obj[2], 0, 256, 128, 384);
	ObjSprite2D_SetSourceRect(obj2[2], 128, 256, 256, 384);
	ObjSprite2D_SetSourceRect(tex[2], 512, 384, 640, 448);
	ObjSprite2D_SetSourceRect(tex2[2], 512, 448, 640, 512);
	
	ObjRender_SetPosition(obj[2], 115+220, 425+15, 0);					/////Quit Pos
	ObjRender_SetPosition(obj2[2], 115+220, 425+15, 0);
	ObjRender_SetPosition(tex[2], 115+220, 425+15, 0);
	ObjRender_SetPosition(tex2[2], 115+220, 425+15, 0);
	ObjRender_SetScaleXYZ(tex[2],1.1,1.1,1.1);
	ObjRender_SetScaleXYZ(tex2[2],1.1,1.1,1.1);
	alphamenu(tex2[2]);alphamenu(tex[2]);
	
	ObjSprite2D_SetSourceRect(diftex[0], 512, 512, 768, 576);
	ObjSprite2D_SetSourceRect(diftex[1], 512, 640, 768, 704);
	
	ObjRender_SetPosition(diftex[0], 200, 350-20, 0);		//////////////Difficulty Position
	ObjRender_SetPosition(diftex[1], 450, 351-20, 0);
	ObjRender_SetScaleXYZ(diftex[0],1.5,1.5,1.5);
	ObjRender_SetScaleXYZ(diftex[1],1.5,1.5,1.5);
	alphamenu(diftex[0]);alphamenu(diftex[1]);
	
	task alphamenu(obj){
		ascent(i in 0..60){
	ObjRender_SetAlpha(obj,i/10*i);
	yield;
}
	}
	
	
	ascent(i in 0..3){ObjSprite2D_SetDestCenter(obj[i]);
	if (i<2){ObjSprite2D_SetDestCenter(diftex[i]);}
	ObjSprite2D_SetDestCenter(obj2[i]);
	ObjSprite2D_SetDestCenter(tex[i]);
	ObjSprite2D_SetDestCenter(tex2[i]);}
	let ang=0;
	let alpha=255; let angle=[0, 0, 0];
	while(MENU==1){
	k++;
	if (MENU_SELECT==0){
	if (sel==0){ObjSprite2D_SetSourceRect(diftex[0], 512, 576, 768, 640); ObjSprite2D_SetSourceRect(diftex[1], 512, 640, 768, 704);}
	if (sel==1){ObjSprite2D_SetSourceRect(diftex[0], 512, 512, 768, 576); ObjSprite2D_SetSourceRect(diftex[1], 512, 704, 768, 768);}
	ang+=9; ObjRender_SetPosition(plane, 150, 256+8*sin(ang), 0); ObjSprite2D_SetSourceRect(plane, 256, 512, 512, 768);}
	else{ang=0; ObjRender_SetPosition(plane, 150, 256, 0); ObjSprite2D_SetSourceRect(plane, 0, 512, 256, 768);
	ObjSprite2D_SetSourceRect(diftex[0], 512, 512, 768, 576);
	ObjSprite2D_SetSourceRect(diftex[1], 512, 640, 768, 704);}
	ascent(i in 0..3){
	if (MENU_SELECT==i){
	if (k%30==0){Ripple(ObjRender_GetX(obj[i]), ObjRender_GetY(obj[i]));}
	angle[i]=angle[i]+0.25; Obj_SetVisible(obj2[i], true); Obj_SetVisible(tex2[i], true);}			//true and false
	else{angle[i]=0; Obj_SetVisible(obj2[i], false); Obj_SetVisible(tex2[i], false);}
	ObjRender_SetAngleXYZ(obj[i], 0, 0, angle[i]);
	}
	yield;}
	ascent(i in 0..3){Obj_Delete(tex[i]); Obj_Delete(obj[i]); Obj_Delete(tex2[i]); Obj_Delete(obj2[i]);}
	ascent(i in 0..2){Obj_Delete(diftex[i]); Obj_Delete(diftex2[i]);}
	Obj_Delete(plane);
	}
	
	task Ripple(x, y){
	let sca=0; let alpha=240;
	let ripple=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(ripple, GetCurrentScriptDirectory~"/system/img/mainmenu.png");
	ObjSprite2D_SetSourceRect(ripple, 256, 256, 512, 512);
	ObjSprite2D_SetDestCenter(ripple);
	ObjRender_SetPosition(ripple, x, y, 0);
	while(MENU==1){
	alpha-=4; sca+=0.03; ObjRender_SetScaleXYZ(ripple, sca, sca/1.5, sca); ObjRender_SetAlpha(ripple, alpha);
	if (alpha<0){Obj_Delete(ripple);}
	yield;}
	Obj_Delete(ripple);
	}
	
	task KeyCheck{
	loop(30){yield;}
	MENU_SELECT=0;
	while(MENU==1){
	
	if (MENU_SELECT==0){
	
	if (GetVirtualKeyState(VK_RIGHT)==KEY_PUSH){sel++; if (sel>1){sel=1;}}
	if (GetVirtualKeyState(VK_LEFT)==KEY_PUSH){sel--; if (sel<0){sel=0;}}}

	if (GetVirtualKeyState(VK_DOWN)==KEY_PUSH){PlaySoundEffect("se_select00");MENU_SELECT++;
	if (MENU_SELECT>2){MENU_SELECT=2;}
	
	}
	
	if (GetVirtualKeyState(VK_UP)==KEY_PUSH){PlaySoundEffect("se_select00");MENU_SELECT--;
	if (MENU_SELECT<0){MENU_SELECT=0;}
	}
	
	if (GetVirtualKeyState(VK_LEFT)==KEY_PUSH){MENU_SELECT--;
	if (MENU_SELECT<0){MENU_SELECT=0;}
	
	}
	if (GetVirtualKeyState(VK_BOMB)==KEY_PUSH&&MENU_SELECT!=2){PlaySoundEffect("se_cancel00");MENU_SELECT=2;}
	if (GetVirtualKeyState(VK_SHOT)==KEY_PUSH){PlaySoundEffect("se_boon01");
	MENU=MENU_SELECT+1;
		alternative(MENU_SELECT)
		case (0){
		SetCommonData("rank", DIF_TEXT[sel]);
		MainMenuA2;
		}
		case(1){
		MENU=3;
		MenuReplay;
		}
		case (2){PlaySoundEffect("se_cancel00");loop(30){yield;};ClosePackage;}
	
	}
	yield;}
	}
	
	
}

task MainMenuA2{

LoadScreen;
	MENU=4;
	loop(60){yield;}
	
	Stage("1");
}