if(stage==6){

SetGraphicScale(1,1);
SetPerspectiveClip(0,2000);
SetAlpha(255);
SetViewTo(0,basev+viewv,viewh);
SetViewFrom(50,viewx,viewy);
WriteZBuffer(true);
UseZBuffer(true);

//END
	SetColor(0,0,0); 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);

if(bgphase==1){

SetFog(0,500,0,0,0);

let bgrepeat=0;
loop(4){
//FLOOR 1
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGfloor1); SetGraphicRect(0,0+vscroll,150,300+vscroll);
	SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat,0,0);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGfloor2); SetGraphicRect(0+vscroll,0,300+vscroll,300);
	SetGraphicAngle(90,90,90); DrawGraphic3D(bgrepeat,0,225); DrawGraphic3D(bgrepeat,0,525);
//CEILING 1
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGceiling1); SetGraphicRect(0,0+vscroll,150,300+vscroll);
	SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat,250,0);
bgrepeat-=300;
} //loop 4x

let bgrepeat=0;
loop(4){
//TREES
	SetColor(75,75,75);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGtree); SetGraphicRect(0,0,250,300);
	SetGraphicAngle(0,20,180);DrawGraphic3D(bgrepeat+220+scroll,150,-150);
	SetColor(255,255,255);
bgrepeat-=600;
} //loop 4x

//MOON
	SetFog(0,1000,0,0,0);
	SetAlpha(255); SetGraphicScale(0.2,0.2); SetTexture(BGmoon); SetGraphicRect(0,0,300,300);
	SetGraphicAngle(0,220,180); DrawGraphic3D(-300,300,-300);
	SetFog(0,500,0,0,0);

let bgrepeat=0;
loop(8){
//WALL 1
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall1a); SetGraphicRect(0,0,150,250);
	SetGraphicAngle(0,180,180); DrawGraphic3D(bgrepeat+scroll,125,-75);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall1b); SetGraphicRect(0,0,150,250);
	SetGraphicAngle(0,180,180); DrawGraphic3D(bgrepeat+150+scroll,125,-75);
bgrepeat-=300;
} //loop 8x
let bgrepeat=0;
loop(4){
//WALL 2
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall2a); SetGraphicRect(0,0,450,250);
	SetGraphicAngle(0,0,180); DrawGraphic3D(bgrepeat+300+scroll,125,75);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall2b); SetGraphicRect(0,0,150,250);
	SetGraphicAngle(0,0,180); DrawGraphic3D(bgrepeat+600+scroll,125,75);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGdoor); SetGraphicRect(0,0,300,250);
	SetGraphicAngle(0,doorangle,180); DrawGraphic3D(bgrepeat+535+scroll,125,75);

bgrepeat-=600;
} //loop 4x

} //bgphase 1

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

if(bgphase==2){

SetFog(0,600,0,0,0);

let bgrepeat=0;
loop(4){
//FLOOR 2
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGfloor2); SetGraphicRect(0,0,600,600);
	SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat+scroll,0,0);
//DEBRIS
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGdebris); SetGraphicRect(0,0,300,300);
	SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat-150+scroll,1,0);
bgrepeat-=300;
} //loop 4x

let bgrepeat=0;
loop(2){
//CEILING 2
	SetAlpha(255); SetGraphicScale(2,2); SetTexture(BGceiling2); SetGraphicRect(0,0,150,150);
	SetGraphicAngle(270,90,270); DrawGraphic3D(bgrepeat+scroll-450,250,150);
	SetGraphicAngle(90,90,90); DrawGraphic3D(bgrepeat+scroll-450,250,-150);
	SetGraphicAngle(270,90,90); DrawGraphic3D(bgrepeat+scroll-150,250,-150);
	SetGraphicAngle(90,90,270); DrawGraphic3D(bgrepeat+scroll-150,250,150);
bgrepeat-=600;
} //loop 2x

let bgrepeat=0;
loop(10){
//HORIZONTAL BEAM
	SetAlpha(255); SetGraphicScale(1,1.5); SetTexture(BGbeams1); SetGraphicRect(0,50,100,200);
	SetGraphicAngle(0,90,90);
	DrawGraphic3D(bgrepeat+75+scroll,220,-250); DrawGraphic3D(bgrepeat+75+scroll,220,-75);
	DrawGraphic3D(bgrepeat+75+scroll,220,250); DrawGraphic3D(bgrepeat+75+scroll,220,75);
//VERTICAL BEAM
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGbeams1); SetGraphicRect(0,0,100,250);
	SetGraphicAngle(0,90,180);
	DrawGraphic3D(bgrepeat+75+scroll,125,-200); DrawGraphic3D(bgrepeat+75+scroll,125,-100);
	DrawGraphic3D(bgrepeat+75+scroll,125,200); DrawGraphic3D(bgrepeat+75+scroll,125,100);
bgrepeat-=150;
} //loop 10x

let bgrepeat=0;
loop(3){
//WALL 2
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall2a); SetGraphicRect(0,0,600,250);
	SetGraphicAngle(0,180,180); DrawGraphic3D(bgrepeat+scroll,125,-300); DrawGraphic3D(bgrepeat+scroll,125,300);
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall2a); SetGraphicRect(0,0,250,250);
	SetGraphicAngle(0,90,180); DrawGraphic3D(bgrepeat+scroll,125,-175); DrawGraphic3D(bgrepeat+scroll,125,175);
//DOOR
	SetAlpha(255); SetGraphicScale(0.75,1); SetTexture(BGwall2b); SetGraphicRect(0,0,150,250);
	SetGraphicAngle(0,90,180); DrawGraphic3D(bgrepeat+scroll,125,0);
bgrepeat-=600;
} //loop 3x

} //bgphase 2

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

if(bgphase==3){

SetColor(170+80*cos(eclipse*5),170+80*cos(eclipse*5),170+80*cos(eclipse*5));
let fog=600-150*cos(180+eclipse*5);

//MOON
	SetFog(0,fog*1.5,0,0,0);
	SetColor(255,170+80*cos(eclipse*5),170+80*cos(eclipse*5));
	SetAlpha(255); SetGraphicScale(0.2,0.2); SetTexture(BGmoon); SetGraphicRect(0,0,300,300);
	SetGraphicAngle(0,220,180); DrawGraphic3D(-150,300,-300);
	SetColor(255,255,255);

//ECLIPSE
	SetFog(0,fog,0,0,0);
	SetAlpha(255); SetGraphicScale(0.185,0.185); SetTexture(BGeclipse); SetGraphicRect(0,0,300,300);
	SetGraphicAngle(0,220,180); DrawGraphic3D(-98-eclipse,340-eclipse,-285);
let bgrepeat=0;
loop(8){
//FLOOR 3
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGfloor3); SetGraphicRect(0,0,300,300);
	SetGraphicAngle(90,90,0); DrawGraphic3D(bgrepeat+scroll,0,-300); DrawGraphic3D(bgrepeat+scroll,0,0); DrawGraphic3D(bgrepeat+scroll,0,300);
bgrepeat-=300;
} //loop 8x

let bgrepeat=0;
loop(4){
//CEILING 3
	SetAlpha(255); SetGraphicScale(2,2.5); SetTexture(BGceiling3a); SetGraphicRect(0,0,300,180);
	SetGraphicAngle(225,180,0); DrawGraphic3D(bgrepeat+scroll-450,300,150);
	SetGraphicAngle(225,180,0); DrawGraphic3D(bgrepeat+scroll+150,300,150);
	SetAlpha(255); SetGraphicScale(2,2.5); SetTexture(BGceiling3b); SetGraphicRect(0,0,300,180);
	SetGraphicAngle(135,180,0); DrawGraphic3D(bgrepeat+scroll-450,300,-150);
	SetGraphicAngle(135,180,0); DrawGraphic3D(bgrepeat+scroll+150,300,-150);
bgrepeat-=600;
} //loop 2x

let bgrepeat=0;
loop(20){
//HORIZONTAL BEAM
	SetAlpha(255); SetGraphicScale(1,3.5); SetTexture(BGbeams2); SetGraphicRect(0,50,100,200);
	SetGraphicAngle(0,90,45); DrawGraphic3D(bgrepeat-30+scroll,250,-150);
	SetGraphicAngle(0,90,135); DrawGraphic3D(bgrepeat-30+scroll,250,150);
	SetGraphicAngle(0,90,90); DrawGraphic3D(bgrepeat-30+scroll,200,0);
//VERTICAL BEAM
	SetAlpha(255); SetGraphicScale(1,2); SetTexture(BGbeams2); SetGraphicRect(0,50,100,200);
	SetGraphicAngle(0,90,180); DrawGraphic3D(bgrepeat-30+scroll,150,-150); DrawGraphic3D(bgrepeat-30+scroll,150,150);
bgrepeat-=300;
} //loop 20x

let bgrepeat=0;
loop(4){
//WALL 2
	SetAlpha(255); SetGraphicScale(1,1); SetTexture(BGwall2a); SetGraphicRect(0,0,600,150);
	SetGraphicAngle(0,180,180); DrawGraphic3D(bgrepeat+scroll,75,-300); DrawGraphic3D(bgrepeat+scroll,75,300);
bgrepeat-=600;
} //loop 4x

} //bgphase 3
}