if(time==0){

BGsky=("\script\Images\Menu\MainSky.png");

SetCommonData("BlackScreenFade",255);
SetCommonData("Conversation",0);
SetCommonData("ResetPlayer",0);
SetCommonData("NextStage",0);

let xsize=640;
let ysize=480;
	EFsky=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFsky,320,240);
	ObjEffect_SetScale(EFsky,1,1);
	ObjEffect_SetLayer(EFsky,8); ObjEffect_SetTexture(EFsky,BGsky); ObjEffect_SetRenderState(EFsky,ALPHA);
	ObjEffect_SetPrimitiveType(EFsky,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFsky,4);
	ObjEffect_SetVertexXY(EFsky,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFsky,0,0,0);
	ObjEffect_SetVertexXY(EFsky,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFsky,1,xsize,0);
	ObjEffect_SetVertexXY(EFsky,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFsky,2,0,ysize);
	ObjEffect_SetVertexXY(EFsky,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFsky,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFsky,0,255,220,255,255); ObjEffect_SetVertexColor(EFsky,1,255,220,255,255);
	ObjEffect_SetVertexColor(EFsky,2,255,220,255,255); ObjEffect_SetVertexColor(EFsky,3,255,220,255,255);
	EFsun=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFsun,320,240);
	ObjEffect_SetScale(EFsun,1,1);
	ObjEffect_SetLayer(EFsun,8); ObjEffect_SetTexture(EFsun,BGsun); ObjEffect_SetRenderState(EFsun,ALPHA);
	ObjEffect_SetPrimitiveType(EFsun,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFsun,4);
	ObjEffect_SetVertexXY(EFsun,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFsun,0,0,0);
	ObjEffect_SetVertexXY(EFsun,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFsun,1,xsize,0);
	ObjEffect_SetVertexXY(EFsun,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFsun,2,0,ysize);
	ObjEffect_SetVertexXY(EFsun,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFsun,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFsun,0,255,255,255,255); ObjEffect_SetVertexColor(EFsun,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFsun,2,255,255,255,255); ObjEffect_SetVertexColor(EFsun,3,255,255,255,255);
	EFattic=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFattic,320,240);
	ObjEffect_SetScale(EFattic,1,1);
	ObjEffect_SetLayer(EFattic,8); ObjEffect_SetTexture(EFattic,BGattic); ObjEffect_SetRenderState(EFattic,ALPHA);
	ObjEffect_SetPrimitiveType(EFattic,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFattic,4);
	ObjEffect_SetVertexXY(EFattic,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFattic,0,0,0);
	ObjEffect_SetVertexXY(EFattic,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFattic,1,xsize,0);
	ObjEffect_SetVertexXY(EFattic,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFattic,2,0,ysize);
	ObjEffect_SetVertexXY(EFattic,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFattic,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFattic,0,255,255,255,255); ObjEffect_SetVertexColor(EFattic,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFattic,2,255,255,255,255); ObjEffect_SetVertexColor(EFattic,3,255,255,255,255);

let xsize=49;
let ysize=59;
let color=200;
	loop(2){
	butterfly=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(butterfly,680,cy);
	ObjEffect_SetScale(butterfly,1,1);
	ObjEffect_SetLayer(butterfly,8); ObjEffect_SetTexture(butterfly,GRbutterflywing); ObjEffect_SetRenderState(butterfly,ALPHA);
	ObjEffect_SetPrimitiveType(butterfly,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(butterfly,4);
	ObjEffect_SetVertexXY(butterfly,0,-xsize,-(ysize/2)); ObjEffect_SetVertexUV(butterfly,0,0,0);
	ObjEffect_SetVertexXY(butterfly,1,0,-(ysize/2)); ObjEffect_SetVertexUV(butterfly,1,xsize,0);
	ObjEffect_SetVertexXY(butterfly,2,-xsize,ysize/2); ObjEffect_SetVertexUV(butterfly,2,0,ysize);
	ObjEffect_SetVertexXY(butterfly,3,0,ysize/2); ObjEffect_SetVertexUV(butterfly,3,xsize,ysize);
	ObjEffect_SetVertexColor(butterfly,0,255,color,color,color); ObjEffect_SetVertexColor(butterfly,1,255,color,color,color);
	ObjEffect_SetVertexColor(butterfly,2,255,color,color,color); ObjEffect_SetVertexColor(butterfly,3,255,color,color,color);
	butterflywing=butterflywing~[butterfly];
	color+=50;
	}

let xsize=300;
let ysize=300;
	EFlight=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFlight,590,55);
	ObjEffect_SetScale(EFlight,5,5);
	ObjEffect_SetLayer(EFlight,8); ObjEffect_SetTexture(EFlight,BGlight); ObjEffect_SetRenderState(EFlight,ADD);
	ObjEffect_SetPrimitiveType(EFlight,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFlight,4);
	ObjEffect_SetVertexXY(EFlight,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFlight,0,0,0);
	ObjEffect_SetVertexXY(EFlight,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFlight,1,xsize,0);
	ObjEffect_SetVertexXY(EFlight,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFlight,2,0,ysize);
	ObjEffect_SetVertexXY(EFlight,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFlight,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFlight,0,255,255,255,255); ObjEffect_SetVertexColor(EFlight,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFlight,2,255,255,255,255); ObjEffect_SetVertexColor(EFlight,3,255,255,255,255);

let xsize=224;
let ysize=80;
let MAbarpos=0;
let MAbargraphicx=0;
let MAbargraphicy=0;
	loop(6){
	EFbar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFbar,420,65+MAbarpos);
	ObjEffect_SetScale(EFbar,1,1);
	ObjEffect_SetLayer(EFbar,8); ObjEffect_SetTexture(EFbar,BGbars); ObjEffect_SetRenderState(EFbar,ALPHA);
	ObjEffect_SetPrimitiveType(EFbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFbar,4);
	ObjEffect_SetVertexXY(EFbar,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,0,0+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,1,xsize+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFbar,2,0+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFbar,3,xsize+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexColor(EFbar,0,255,255,255,255); ObjEffect_SetVertexColor(EFbar,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFbar,2,255,255,255,255); ObjEffect_SetVertexColor(EFbar,3,255,255,255,255);
	EFbars1=EFbars1~[EFbar];
	MAbarpos+=70;
	MAbargraphicy+=80;
	}
let MAbarpos=0;
let MAbargraphicx=448;
let MAbargraphicy=0;
	loop(4){
	EFbar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFbar,320+450,120+MAbarpos);
	ObjEffect_SetScale(EFbar,1,1);
	ObjEffect_SetLayer(EFbar,8); ObjEffect_SetTexture(EFbar,BGbars); ObjEffect_SetRenderState(EFbar,ALPHA);
	ObjEffect_SetPrimitiveType(EFbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFbar,4);
	ObjEffect_SetVertexXY(EFbar,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,0,0+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,1,xsize+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFbar,2,0+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFbar,3,xsize+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexColor(EFbar,0,255,255,255,255); ObjEffect_SetVertexColor(EFbar,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFbar,2,255,255,255,255); ObjEffect_SetVertexColor(EFbar,3,255,255,255,255);
	EFbars3=EFbars3~[EFbar];
	MAbarpos+=80;
	MAbargraphicy+=80;
	}
let MAbarpos=0;
let MAbargraphicx=224;
let MAbargraphicy=0;
	loop(8){
	EFbar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFbar,320+450,50+MAbarpos);
	ObjEffect_SetScale(EFbar,1,1);
	ObjEffect_SetLayer(EFbar,8); ObjEffect_SetTexture(EFbar,BGbars); ObjEffect_SetRenderState(EFbar,ALPHA);
	ObjEffect_SetPrimitiveType(EFbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFbar,4);
	ObjEffect_SetVertexXY(EFbar,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,0,0+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFbar,1,xsize+MAbargraphicx,0+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFbar,2,0+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexXY(EFbar,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFbar,3,xsize+MAbargraphicx,ysize+MAbargraphicy);
	ObjEffect_SetVertexColor(EFbar,0,255,255,255,255); ObjEffect_SetVertexColor(EFbar,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFbar,2,255,255,255,255); ObjEffect_SetVertexColor(EFbar,3,255,255,255,255);
	EFbars2=EFbars2~[EFbar];
	MAbarpos+=55;
	MAbargraphicy+=80;
	}

let xsize=30;
let ysize=46;
	loop(2){
	EFlock=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFlock,320,240);
	ObjEffect_SetScale(EFlock,1,1);
	ObjEffect_SetAngle(EFlock,0,0,25);
	ObjEffect_SetLayer(EFlock,8); ObjEffect_SetTexture(EFlock,GRlock); ObjEffect_SetRenderState(EFlock,ALPHA);
	ObjEffect_SetPrimitiveType(EFlock,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFlock,4);
	ObjEffect_SetVertexXY(EFlock,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFlock,0,0,0);
	ObjEffect_SetVertexXY(EFlock,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFlock,1,xsize,0);
	ObjEffect_SetVertexXY(EFlock,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFlock,2,0,ysize);
	ObjEffect_SetVertexXY(EFlock,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFlock,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFlock,0,255,120,120,120); ObjEffect_SetVertexColor(EFlock,1,255,120,120,120);
	ObjEffect_SetVertexColor(EFlock,2,255,120,120,120); ObjEffect_SetVertexColor(EFlock,3,255,120,120,120);
	EFlocks=EFlocks~[EFlock];
	}
if(GetCommonDataDefault("ExtraUnlocked",false)==true){ Obj_Delete(EFlocks[0]); }
if(GetCommonDataDefault("NightmareUnlocked",false)==true){ Obj_Delete(EFlocks[1]); }

let xsize=640;
let ysize=480;
	EFwoodbar=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFwoodbar,320,240);
	ObjEffect_SetScale(EFwoodbar,1,1);
	ObjEffect_SetLayer(EFwoodbar,8); ObjEffect_SetTexture(EFwoodbar,BGwoodbar); ObjEffect_SetRenderState(EFwoodbar,ALPHA);
	ObjEffect_SetPrimitiveType(EFwoodbar,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFwoodbar,4);
	ObjEffect_SetVertexXY(EFwoodbar,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFwoodbar,0,0,0);
	ObjEffect_SetVertexXY(EFwoodbar,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFwoodbar,1,xsize,0);
	ObjEffect_SetVertexXY(EFwoodbar,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFwoodbar,2,0,ysize);
	ObjEffect_SetVertexXY(EFwoodbar,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFwoodbar,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFwoodbar,0,255,255,255,255); ObjEffect_SetVertexColor(EFwoodbar,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFwoodbar,2,255,255,255,255); ObjEffect_SetVertexColor(EFwoodbar,3,255,255,255,255);

	EFumbrella=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFumbrella,320,240);
	ObjEffect_SetScale(EFumbrella,1,1);
	ObjEffect_SetLayer(EFumbrella,8); ObjEffect_SetTexture(EFumbrella,BGumbrella); ObjEffect_SetRenderState(EFumbrella,ALPHA);
	ObjEffect_SetPrimitiveType(EFumbrella,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFumbrella,4);
	ObjEffect_SetVertexXY(EFumbrella,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFumbrella,0,0,0);
	ObjEffect_SetVertexXY(EFumbrella,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFumbrella,1,xsize,0);
	ObjEffect_SetVertexXY(EFumbrella,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFumbrella,2,0,ysize);
	ObjEffect_SetVertexXY(EFumbrella,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFumbrella,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFumbrella,0,255,255,255,255); ObjEffect_SetVertexColor(EFumbrella,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFumbrella,2,255,255,255,255); ObjEffect_SetVertexColor(EFumbrella,3,255,255,255,255);

let xsize=40;
let ysize=40;
let angle=0;
let scale=1;
	loop(6){
	EFselection=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFselection,320,240);
	ObjEffect_SetScale(EFselection,scale,scale);
	ObjEffect_SetLayer(EFselection,8); ObjEffect_SetTexture(EFselection,GRselection); ObjEffect_SetRenderState(EFselection,ALPHA);
	ObjEffect_SetPrimitiveType(EFselection,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFselection,4);
	ObjEffect_SetVertexXY(EFselection,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFselection,0,0,0);
	ObjEffect_SetVertexXY(EFselection,1,(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(EFselection,1,xsize,0);
	ObjEffect_SetVertexXY(EFselection,2,-xsize/2,ysize/2); ObjEffect_SetVertexUV(EFselection,2,0,ysize);
	ObjEffect_SetVertexXY(EFselection,3,(xsize/2),ysize/2); ObjEffect_SetVertexUV(EFselection,3,xsize,ysize);
	ObjEffect_SetVertexColor(EFselection,0,255,255,255,255); ObjEffect_SetVertexColor(EFselection,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFselection,2,255,255,255,255); ObjEffect_SetVertexColor(EFselection,3,255,255,255,255);
	MAselections=MAselections~[EFselection];
	MAselectionangle=MAselectionangle~[EFselection];
	MAselectionangle[length(MAselections)-1]=angle;
	angle+=30;
	scale-=0.1;
	}
}

SetCommonData("PlayMusic",10);

ObjEffect_SetVertexColor(EFlight,0,MAlightfade,255,255,255); ObjEffect_SetVertexColor(EFlight,1,MAlightfade,255,255,255);
ObjEffect_SetVertexColor(EFlight,2,MAlightfade,255,255,255); ObjEffect_SetVertexColor(EFlight,3,MAlightfade,255,255,255);
ObjEffect_SetAngle(EFlight,0,0,MAlightangle);
MAlightangle+=0.02;
if((time+180)%360==0){ MAlightangle=rand(0,360); }
MAlightfade=90+90*cos(time);
ObjEffect_SetVertexUV(EFbars2[6],0,0,80); ObjEffect_SetVertexUV(EFbars2[6],1,224,80);
ObjEffect_SetVertexUV(EFbars2[6],2,0,160); ObjEffect_SetVertexUV(EFbars2[6],3,224,160);
ObjEffect_SetVertexUV(EFbars2[7],0,0,160); ObjEffect_SetVertexUV(EFbars2[7],1,224,160);
ObjEffect_SetVertexUV(EFbars2[7],2,0,240); ObjEffect_SetVertexUV(EFbars2[7],3,224,240);

if(GetCommonDataDefault("ExtraUnlocked",false)==false){
	ObjEffect_SetVertexColor(EFumbrella,0,0,255,255,255); ObjEffect_SetVertexColor(EFumbrella,1,0,255,255,255);
	ObjEffect_SetVertexColor(EFumbrella,2,0,255,255,255); ObjEffect_SetVertexColor(EFumbrella,3,0,255,255,255);
}
if(GetCommonDataDefault("ExtraUnlocked",false)==true){
	ObjEffect_SetVertexColor(EFumbrella,0,255,255,255,255); ObjEffect_SetVertexColor(EFumbrella,1,255,255,255,255);
	ObjEffect_SetVertexColor(EFumbrella,2,255,255,255,255); ObjEffect_SetVertexColor(EFumbrella,3,255,255,255,255);
}

let i=0;
let lockpos=0;
while(i<length(EFlocks)){
	if(MAphasetime==0){ Obj_SetPosition(EFlocks[i],320+MAbarscroll,165+lockpos); }
	else{ Obj_SetPosition(EFlocks[i],700+MAbarscroll,165+lockpos); }
	lockpos+=70;
	i++;
}


if(GetKeyState(VK_DOWN)==KEY_PUSH && MAphase==1 && (MAphasetime==0 || MAphasetime==30)){ MAselection++; PlaySE(SEmenumove1); }
if(GetKeyState(VK_UP)==KEY_PUSH && MAphase==1 && (MAphasetime==0 || MAphasetime==30)){ MAselection--; PlaySE(SEmenumove1); }
if(GetKeyState(VK_DOWN)==KEY_PUSH && MAphase==2 && MAphasetime2==0 && (MAphasetime==0 || MAphasetime==30)){ MAselection2++; PlaySE(SEmenumove1); }
if(GetKeyState(VK_UP)==KEY_PUSH && MAphase==2 && MAphasetime2==0 && (MAphasetime==0 || MAphasetime==30)){ MAselection2--; PlaySE(SEmenumove1); }
if(GetKeyState(VK_DOWN)==KEY_PUSH && MAphase==3 && MAphasetime2==30){ MAselection3++; PlaySE(SEmenumove1); }
if(GetKeyState(VK_UP)==KEY_PUSH && MAphase==3 && MAphasetime2==30){ MAselection3--; PlaySE(SEmenumove1); }
if(MAselection<1 && MAphase==1){ MAselection=6; } if(MAselection>6 && MAphase==1){ MAselection=1; }
if(MAselection2<1 && MAphase==2){ MAselection2=4; } if(MAselection2>4 && MAphase==2){ MAselection2=1; }
if(MAselection3<1 && MAphase==3){ MAselection3=8; } if(MAselection3>8 && MAphase==3){ MAselection3=1; }

if(MAphase==2){ if(MAdifficultybarscroll<340){ MAdifficultybarscroll+=15; } }
if(MAphase==1){ if(MAdifficultybarscroll>0){ MAdifficultybarscroll-=15; } }
if(MAphase==3 && MAselection==5){ if(MAstagebarscroll<340){ MAstagebarscroll+=15; } }
if(MAphase==2 && MAselection==5){ if(MAstagebarscroll>0){ MAstagebarscroll-=15; } }

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==2 && MAselection==1 && MAphasetime==30){ SetCommonData("Difficulty",MAselection2); PlaySE(SEmenuselect1); }
if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==2 && MAselection==5 && MAphasetime==30){ MAphase=3; MAselection3=1; PlaySE(SEmenuselect1); }

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==1){ MAphase=2; MAselection2=2; PlaySE(SEmenuselect1); }
if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==5){ MAphase=2; MAselection2=1; PlaySE(SEmenuselect1); }
if(GetKeyState(VK_BOMB)==KEY_PUSH && MAphase==2 && MAphasetime2==0){ MAphase=1; PlaySE(SEmenucancel1); }
if(GetKeyState(VK_BOMB)==KEY_PUSH && MAphase==3){ MAphase=2; PlaySE(SEmenucancel1); }


if(MAphase==2 && MAphasetime<30 && MAselection==1){ MAphasetime++; MAbarscrollx-=5; MAbarscrolly-=1.3; }
if(MAphase==2 && MAphasetime<30 && MAselection==5){ MAphasetime++; MAbarscrollx-=5; MAbarscrolly+=3.6; }
if(MAphase==1 && MAphasetime>0 && MAselection==1){ MAphasetime--; MAbarscrollx+=5; MAbarscrolly+=1.3; }
if(MAphase==1 && MAphasetime>0 && MAselection==5){ MAphasetime--; MAbarscrollx+=5; MAbarscrolly-=3.6; }
MAbarscale=1-(MAphasetime/60);

if(MAphase==3 && MAphasetime2<30){ MAphasetime2++; MAbarscrollx2-=5.15; MAbarscrolly2+=1.5; }
if(MAphase<3 && MAphasetime2>0){ MAphasetime2--; MAbarscrollx2+=5.15; MAbarscrolly2-=1.5; }
MAbarscale2=1-(MAphasetime2/60);


let i=0;
while(i<(length(EFbars1))){
	if(i==MAselection-1 && MAphase==1){
		ObjEffect_SetVertexColor(EFbars1[i],0,255,255,255,255); ObjEffect_SetVertexColor(EFbars1[i],1,255,255,255,255);
		ObjEffect_SetVertexColor(EFbars1[i],2,255,255,255,255); ObjEffect_SetVertexColor(EFbars1[i],3,255,255,255,255);
	}
	if((i!=MAselection-1) || (i==1 && GetCommonDataDefault("ExtraUnlocked",false)==false) || (i==2 && GetCommonDataDefault("NightmareUnlocked",false)==false)){
		ObjEffect_SetVertexColor(EFbars1[i],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars1[i],1,255,120,120,120);
		ObjEffect_SetVertexColor(EFbars1[i],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars1[i],3,255,120,120,120);
	}
	
	if(MAselection==1){
		ObjEffect_SetScale(EFbars1[0],MAbarscale,MAbarscale);
		Obj_SetPosition(EFbars1[0],420+MAbarscrollx,65+MAbarscrolly);
		if(i>0){ ObjEffect_SetScale(EFbars1[i],MAbarscale*2-1,MAbarscale*2-1); }
	}
	if(MAselection==5){
		ObjEffect_SetScale(EFbars1[4],MAbarscale,MAbarscale);
		Obj_SetPosition(EFbars1[4],420+MAbarscrollx,345+MAbarscrolly);
		if(i!=4){ ObjEffect_SetScale(EFbars1[i],MAbarscale*2-1,MAbarscale*2-1); }
	}
i++;
}

let i=0;
while(i<(length(EFbars3))){
	if(i==MAselection2-1 && MAphase==2){
	ObjEffect_SetVertexColor(EFbars3[i],0,255,255,255,255); ObjEffect_SetVertexColor(EFbars3[i],1,255,255,255,255);
	ObjEffect_SetVertexColor(EFbars3[i],2,255,255,255,255); ObjEffect_SetVertexColor(EFbars3[i],3,255,255,255,255);
	}
	if((i!=MAselection2-1) && MAphase==2){
	ObjEffect_SetVertexColor(EFbars3[i],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars3[i],1,255,120,120,120);
	ObjEffect_SetVertexColor(EFbars3[i],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars3[i],3,255,120,120,120);
	}
	
	Obj_SetX(EFbars3[i],320+450-MAdifficultybarscroll);
	
	if(MAselection==5 && MAphasetime>=30){
	if(MAselection2==1){
		Obj_SetPosition(EFbars3[0],425+MAbarscrollx2,120+(MAbarscrolly2*6.35));
		ObjEffect_SetScale(EFbars3[0],MAbarscale2,MAbarscale2);
		ObjEffect_SetScale(EFbars3[1],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[2],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[3],MAbarscale2*2-1,MAbarscale2*2-1);
		}
	if(MAselection2==2){
		Obj_SetPosition(EFbars3[1],425+MAbarscrollx2,200+(MAbarscrolly2*4.52));
		ObjEffect_SetScale(EFbars3[0],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[1],MAbarscale2,MAbarscale2);
		ObjEffect_SetScale(EFbars3[2],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[3],MAbarscale2*2-1,MAbarscale2*2-1);
	}
	if(MAselection2==3){
		Obj_SetPosition(EFbars3[2],425+MAbarscrollx2,280+(MAbarscrolly2*2.78));
		ObjEffect_SetScale(EFbars3[0],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[1],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[2],MAbarscale2,MAbarscale2);
		ObjEffect_SetScale(EFbars3[3],MAbarscale2*2-1,MAbarscale2*2-1);
		}
	if(MAselection2==4){
		Obj_SetPosition(EFbars3[3],425+MAbarscrollx2,360+(MAbarscrolly2*1));
		ObjEffect_SetScale(EFbars3[0],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[1],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[2],MAbarscale2*2-1,MAbarscale2*2-1);
		ObjEffect_SetScale(EFbars3[3],MAbarscale2,MAbarscale2);
		}
	}
i++;
}
	
let i=0;
while(i<(length(EFbars2))){
	if(i==MAselection3-1 && MAphase==3){
	ObjEffect_SetVertexColor(EFbars2[i],0,255,255,255,255); ObjEffect_SetVertexColor(EFbars2[i],1,255,255,255,255);
	ObjEffect_SetVertexColor(EFbars2[i],2,255,255,255,255); ObjEffect_SetVertexColor(EFbars2[i],3,255,255,255,255);
	}
	if((i!=MAselection3-1) && MAphase==3){
	ObjEffect_SetVertexColor(EFbars2[i],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[i],1,255,120,120,120);
	ObjEffect_SetVertexColor(EFbars2[i],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[i],3,255,120,120,120);
	}
		
	if(GetCommonDataDefault("ExtraUnlocked",false)==false){
	ObjEffect_SetVertexColor(EFbars2[6],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[6],1,255,120,120,120);
	ObjEffect_SetVertexColor(EFbars2[6],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[6],3,255,120,120,120);
	}
	
	if(i>=GetCommonDataDefault("StageUnlocked",0) && i<6){
	ObjEffect_SetVertexColor(EFbars2[i],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[i],1,255,120,120,120);
	ObjEffect_SetVertexColor(EFbars2[i],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[i],3,255,120,120,120);
	}
	
	if(GetCommonDataDefault("NightmareUnlocked",false)==false){
	ObjEffect_SetVertexColor(EFbars2[7],0,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[7],1,255,120,120,120);
	ObjEffect_SetVertexColor(EFbars2[7],2,255,120,120,120); ObjEffect_SetVertexColor(EFbars2[7],3,255,120,120,120);
	}
	
	Obj_SetX(EFbars2[i],320+450-MAstagebarscroll);
i++;
}


let i=0;
while(i<(length(MAselections))){
	if(MAphasetime==0 && MAphase==1){
	Obj_SetPosition(MAselections[i],420+100*cos(MAselectionangle[i]),65+((MAselection-1)*70)+30*sin(MAselectionangle[i]));
	}
	else{ Obj_SetPosition(MAselections[i],-50,-50); }
	if(MAphasetime==30 && MAphasetime2==0 && MAphase==2){
	Obj_SetPosition(MAselections[i],420+100*cos(MAselectionangle[i]),120+((MAselection2-1)*80)+30*sin(MAselectionangle[i]));
	}
	if(MAphasetime2==30 && MAphase==3){
	Obj_SetPosition(MAselections[i],420+100*cos(MAselectionangle[i]),50+((MAselection3-1)*55)+30*sin(MAselectionangle[i]));
	}

	MAselectionangle[i]=MAselectionangle[i]-5;
i++;
}


ObjEffect_SetScale(butterflywing[1],(1+0.8*cos(time*25))*butterflysize,2*butterflysize);
ObjEffect_SetScale(butterflywing[0],(0.4+0.3*cos(time*25))*butterflysize,2*butterflysize);

let i=0;
	loop(2){
	ObjEffect_SetAngle(butterflywing[i],0,butterflydirection*180,30);
	Obj_SetPosition(butterflywing[i],butterflycorex,butterflycorey);
	let butterflyx=Obj_GetX(butterflywing[i]);
	i++;
	}
butterflycorex+=butterflyspeed*cos(butterflyangle+(butterflydirection*180));
butterflycorey+=butterflyspeed*sin(butterflyangle+(butterflydirection*180));
if(butterflycorex>800){ butterflycorex-=5; butterflydirection++; butterflysize=rand(0.5,0.7); butterflyspeed=rand(1.5,3); }
if(butterflycorex<-160){ butterflycorex+=5; butterflydirection++; butterflysize=rand(0.5,0.7); butterflyspeed=rand(1.5,3); }
if(butterflycorey>=80 && (butterflycorex>810 || butterflycorex<-150)){ butterflycorey=rand(cy-150,cy+150); }
if(butterflycorey<=400 && (butterflycorex>810 || butterflycorex<-150)){ butterflycorey=rand(cy-150,cy+150); }

if(time%20==0){ butterflyangle=rand(-60,60); }

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==4){
	mainmenu=2;
	time=0;
	frame=0;
	SetCommonData("Difficulty",2);
	PlaySE(SEmenuselect1);
} //select type

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==2 && MAphasetime==30){
	mainmenu=2;
	time=0;
	frame=0;
} //main game

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==3 && MAphasetime2==30 && MAselection3<7 && GetCommonDataDefault("StageUnlocked",0)>=MAselection3){
	mainmenu=2;
	time=0;
	frame=0;
	SetCommonData("Difficulty",MAselection2);
	SetCommonData("InStagePractise",1);
	PlaySE(SEmenuselect1);
} //stage practise
if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==3 && MAphasetime2==30 && MAselection3==7 && GetCommonDataDefault("ExtraUnlocked",false)==true){
	mainmenu=2;
	time=0;
	frame=0;
	SetCommonData("Difficulty",MAselection2);
	SetCommonData("InStagePractise",1);
	PlaySE(SEmenuselect1);
} //extra practise
if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==3 && MAphasetime2==30 && MAselection3==8 && GetCommonDataDefault("NightmareUnlocked",false)==true){
	mainmenu=2;
	time=0;
	frame=0;
	SetCommonData("Difficulty",MAselection2);
	SetCommonData("InStagePractise",1);
	PlaySE(SEmenuselect1);
} //nightmare practise


if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==6){ mainmenu=4; time=0; frame=0; PlaySE(SEmenuselect1); }

if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==2 && GetCommonDataDefault("ExtraUnlocked",false)==true){ mainmenu=2; time=0; frame=0; SetCommonData("Difficulty",5); }
if(GetKeyState(VK_SHOT)==KEY_PUSH && MAphase==1 && MAselection==3 && GetCommonDataDefault("NightmareUnlocked",false)==true){ mainmenu=2; time=0; frame=0; SetCommonData("Difficulty",6); }


SetPlayerX(cx);
SetPlayerY(400);

SetCommonData("InEvent",1);
SetCommonData("ItemSpawn",0);

if(mainmenu!=1){
	Obj_Delete(EFsky);
	Obj_Delete(EFsun);
	Obj_Delete(EFattic);
	Obj_Delete(EFlight);
	Obj_Delete(EFbar);
	Obj_Delete(EFwoodbar);
	Obj_Delete(EFumbrella);

	let i=0; while(i<length(MAselections)){ Obj_Delete(MAselections[i]); i++; }
	let i=0; while(i<length(MAselectionangle)){ Obj_Delete(MAselectionangle[i]); i++; }
	let i=0; while(i<length(butterflywing)){ Obj_Delete(butterflywing[i]); i++; }
	let i=0; while(i<length(EFlocks)){ Obj_Delete(EFlocks[i]); i++; }
	let i=0; while(i<length(EFbars1)){ Obj_Delete(EFbars1[i]); i++; }
	let i=0; while(i<length(EFbars2)){ Obj_Delete(EFbars2[i]); i++; }
	let i=0; while(i<length(EFbars3)){ Obj_Delete(EFbars3[i]); i++; }

	while(length(MAselections)>0){ MAselections=erase(MAselections,0); }
	while(length(MAselectionangle)>0){ MAselectionangle=erase(MAselectionangle,0); }
	while(length(butterflywing)>0){ butterflywing=erase(butterflywing,0); }
	while(length(EFlocks)>0){ EFlocks=erase(EFlocks,0); }
	while(length(EFbars1)>0){ EFbars1=erase(EFbars1,0); }
	while(length(EFbars2)>0){ EFbars2=erase(EFbars2,0); }
	while(length(EFbars3)>0){ EFbars3=erase(EFbars3,0); }
	
	SetCommonData("Power",0);
	SetCommonData("Points",0);
	if(GetScore>0){ AddScore(-GetScore); }
	if(GetGraze>0){ AddGraze(-GetGraze); }
	while(GetPlayerLife>3){ ExtendPlayer(-1); }
	while(GetPlayerBomb>3){ AddBomb(-1); }
	SetCommonData("ResetPlayer",1);
	SetCommonData("SpellcardPractise",0);
}
