if(stage==7){

//Background Extra Stage

SetAlpha(255);
SetViewTo(0,100,0);
SetViewFrom(100,viewx,viewy);
WriteZBuffer(true);
UseZBuffer(true);

if(bgphase==1){

SetPerspectiveClip(0,3000);
SetFog(700,1200,220,240,255);

//END
	SetColor(220,240,255); SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGend); 	SetGraphicRect(0,0,3000,2000);
	SetGraphicAngle(0,90,0); DrawGraphic3D(-1400,0,0);
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,0,-1400);
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,0,1400);
	SetGraphicAngle(90,90,0); DrawGraphic3D(0,700,0);
	SetColor(255,255,255);

let bgrepeat=0;
loop(6){
//SKY
	SetAlpha(255); SetGraphicScale(2,2); SetTexture(BGsky);
	SetGraphicRect(0,0,300,300); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,200,600); DrawGraphic3D(bgrepeat,200,0); DrawGraphic3D(bgrepeat,200,-600);
	bgrepeat-=600;
	}

let bgrepeat=0;
loop(3){
//SAND
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGsand);
	SetGraphicRect(0,0+vscroll,100,400+vscroll); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,0,0);
//DUNES 1
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGdunes1);
	SetGraphicRect(0,0+vscroll,200,400+vscroll); SetGraphicAngle(115,0,270); DrawGraphic3D(bgrepeat,30,-120); //E
	SetGraphicRect(0,0-vscroll,200,400-vscroll); SetGraphicAngle(115,180,270); DrawGraphic3D(bgrepeat,30,120); //W
//DUNES 2
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGdunes2);
	SetGraphicRect(0,0+vscroll,400,400+vscroll); SetGraphicAngle(100,0,270); DrawGraphic3D(bgrepeat,105,-400); //E
	SetGraphicRect(0,0-vscroll,400,400-vscroll); SetGraphicAngle(100,180,270); DrawGraphic3D(bgrepeat,105,400); //W
	bgrepeat-=400;
}

//GRASS 1
let h=160;
loop(3){
let i=0;
	while(i<length(grass1)){
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGgrass1);
	SetGraphicRect(0,0,150,100);
	SetGraphicAngle(0,40,180);
	if(grass1[i]<=200 && grassrandomx1[i]<0){ DrawGraphic3D(grass1[i],50-((grassrandomx1[i]*0.7)+80-(h/2.5)),grassrandomx1[i]-h); }
	SetGraphicAngle(0,160,180);
	if(grass1[i]<=200 && grassrandomx1[i]>0){ DrawGraphic3D(grass1[i],50+((grassrandomx1[i]*0.7)-80+(h/2.5)),grassrandomx1[i]+h); }
	i++;
	}
h-=80;
}

//GRASS 2
let h=160;
loop(3){
let i=0;
	while(i<length(grass2)){
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGgrass2);
	SetGraphicRect(0,0,150,100);
	SetGraphicAngle(0,30,180);
	if(grass2[i]<=200 && grassrandomx2[i]<0){ DrawGraphic3D(grass2[i],50-((grassrandomx2[i]*0.7)+80-(h/2.5)),grassrandomx2[i]-h); }
	SetGraphicAngle(0,150,180);
	if(grass2[i]<=200 && grassrandomx2[i]>0){ DrawGraphic3D(grass2[i],50+((grassrandomx2[i]*0.7)-80+(h/2.5)),grassrandomx2[i]+h); }
	i++;
	}
h-=80;
}

let bgrepeat=0;
loop(3){
//FENCE 1
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGfence1);
	SetGraphicRect(0+vscroll,0,400+vscroll,150); SetGraphicAngle(180,0,0); DrawGraphic3D(bgrepeat,110,-170); //E
	SetGraphicRect(0-vscroll,0,400-vscroll,150); SetGraphicAngle(180,180,0); DrawGraphic3D(bgrepeat,110,170); //W

	bgrepeat-=400;
}

} //bgphase 1

//==============================================================================================

if(bgphase==2){

SetPerspectiveClip(0,3000);
SetFog(700,1400,220,240,255);

//END
	SetColor(220,240,255); SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGend); 	SetGraphicRect(0,0,3000,2000);
	SetGraphicAngle(0,90,0); DrawGraphic3D(-1400,0,0);
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,0,-1400);
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,0,1400);
	SetGraphicAngle(90,90,0); DrawGraphic3D(0,700,0);
	SetColor(255,255,255);

let bgrepeat=0;
loop(6){
//SKY
	SetAlpha(255); SetGraphicScale(2,2); SetTexture(BGsky);
	SetGraphicRect(0,0,300,300); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,200,600); DrawGraphic3D(bgrepeat,200,0); DrawGraphic3D(bgrepeat,200,-600);
	bgrepeat-=600;
	}

let bgrepeat=0;
loop(3){
//WATER 2
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGwater2);
	SetGraphicRect(0,0+vscroll,400,400+vscroll); SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat,0,-500); DrawGraphic3D(bgrepeat,0,-900);

//WATER 1
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGwater1);
	SetGraphicRect(0,0+vscroll,400,400+vscroll); SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat,0,-100);

//SAND
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGsand);
	SetGraphicRect(0,0+vscroll,200,400+vscroll);
	SetGraphicAngle(95,180,90); DrawGraphic3D(bgrepeat,10,197);
	SetGraphicAngle(100,180,90); DrawGraphic3D(bgrepeat,35,392);
	SetGraphicAngle(105,180,90); DrawGraphic3D(bgrepeat,75,572);

//WAVES
SetRenderState(ALPHA);
let fade=0;
	loop(40){
	SetAlpha(fade); SetGraphicScale(1,1);
	SetTexture(BGwaves);
	SetGraphicRect(0+fade-(hscroll/2)+50*cos(hscroll),0+vscroll,(400/40)+fade-(hscroll/2)+50*cos(hscroll),400+vscroll); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,0,0-fade);
	SetGraphicRect(0+fade-(hscroll/2)+50*cos(hscroll+30),50+vscroll,(400/40)+fade-(hscroll/2)+50*cos(hscroll+30),450+vscroll); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,0,0-fade);
	SetAlpha(15);
	SetGraphicRect(0-(hscroll/2)+50*cos(hscroll+30),50+vscroll,400-(hscroll/2)+50*cos(hscroll+30),450+vscroll); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,0,-400);
	SetGraphicRect(0-(hscroll/2)+50*cos(hscroll+30),50+vscroll,400-(hscroll/2)+50*cos(hscroll+30),450+vscroll); SetGraphicAngle(90,90,0);
	DrawGraphic3D(bgrepeat,0,-800);
	fade+=400/40;
	}
SetColor(255,255,255); SetRenderState(ALPHA);

	bgrepeat-=400;
}

} //bgphase 2

//==============================================================================================

if(bgphase==3){

SetPerspectiveClip(0,3000);
SetFog(1000,1500,220,240,255);

//END
	SetColor(220,240,255); SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGend); SetGraphicRect(0,0,3000,2000);
	SetColor(255,255,255);
	SetGraphicAngle(0,90,0); DrawGraphic3D(-1400,0,0); //N
	SetGraphicAngle(180,0,0); DrawGraphic3D(0,0,-1400); //E
	SetGraphicAngle(0,90,0); DrawGraphic3D(1400,0,0); //S
	SetGraphicAngle(180,180,0); DrawGraphic3D(0,0,1400); //W

//FLOOR CENTER
	SetAlpha(255); SetGraphicScale(1,1);
	SetTexture(BGfloor1);
	SetGraphicRect(0,0,400,400); SetGraphicAngle(90,90,0);
	DrawGraphic3D(0,0,0); //C
	DrawGraphic3D(-400,0,0); //N
	DrawGraphic3D(400,0,0); //S
	DrawGraphic3D(0,0,-400); //E
	DrawGraphic3D(0,0,400); //W

//FLOOR CORNER
	SetGraphicRect(1,1,399,399); SetTexture(BGfloor2);
	SetGraphicAngle(90,90,0); DrawGraphic3D(-400,0,-400); //NE
	SetGraphicAngle(270,90,180); DrawGraphic3D(-400,0,400); //NW
	SetGraphicAngle(270,90,0); DrawGraphic3D(400,0,-400); //SE
	SetGraphicAngle(90,90,180); DrawGraphic3D(400,0,400); //SW

//FENCE
	SetTexture(BGfence2);
	SetGraphicRect(0,0,400,400);
	SetGraphicAngle(0,90,180); DrawGraphic3D(-600,200,0); //N
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,200,600); //W
	SetGraphicAngle(0,90,180); DrawGraphic3D(600,200,0); //S
	SetGraphicAngle(0,180,180); DrawGraphic3D(0,200,-600); //E
	SetGraphicAngle(0,180+45,180); DrawGraphic3D(-400,200,-400); //NE 
	SetGraphicAngle(0,180-45,180);DrawGraphic3D(-400,200,400);  //NW
	SetGraphicAngle(0,180-45,180); DrawGraphic3D(400,200,-400); //SE
	SetGraphicAngle(0,180+45,180); DrawGraphic3D(400,200,400); //SW

//CEILING
	SetAlpha(255); SetGraphicScale(2,2);
	SetTexture(BGceiling);
	SetGraphicRect(1,1,399,399);

	SetGraphicAngle(245,90,0); DrawGraphic3D(-600,350,0); //N
	SetGraphicAngle(-115,0,0); DrawGraphic3D(0,350,-400); //E
	SetGraphicAngle(-65,90,180); DrawGraphic3D(600,350,0); //S
	SetGraphicAngle(115,0,0); DrawGraphic3D(0,350,400); //W

	SetGraphicAngle(245,45,0); DrawGraphic3D(-300,350,-200); //NE
	SetGraphicAngle(245,-45,0); DrawGraphic3D(300,350,-200); //SE
	SetGraphicAngle(115,45,0); DrawGraphic3D(300,350,200); //SW
	SetGraphicAngle(-65,-45,180); DrawGraphic3D(-300,350,200); //NW

	SetGraphicScale(1,1);

} //bgphase 3

}