task Bg{
	
	let centerX = GetStgFrameWidth/2;
	let centerY = GetStgFrameHeight/2;
	
	Bg1;
	/*task Bg1{

		SetCameraPerspectiveClip(20,1024*4);
		SetFogEnable(true);
		SetFogParam(512*1.4,1024,0,0,0);

		SetCameraAzimuthAngle(-90);
		SetCameraElevationAngle(30);

		let z = 0;
		let fog = -512;

		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetMainStgScriptDirectory ~ "img/bg/fog.png");
		ObjSprite2D_SetSourceRect(obj,0,0,640,480);
		ObjSprite2D_SetDestRect(obj,0,0,640,480);
		Obj_SetRenderPriority(obj,0.16);
		ObjRender_SetColor(obj,255/3,63/3,255/3);

		let objst = ObjPrim_Create(OBJ_PRIMITIVE_3D);
		ObjPrim_SetPrimitiveType(objst,PRIMITIVE_TRIANGLELIST);
		ObjPrim_SetVertexCount(objst,12*36);
		ObjPrim_SetTexture(objst,GetMainStgScriptDirectory ~ "img/bg/ref0.png");
		Obj_SetRenderPriority(objst,0.18);
		ascent(a in 0..36){
			CreateRectangle(objst,a*12, [0,256+((a*2+1)*16)],[256,256+((a*2+2)*16)], [-128,(1+a)*32,(a)*48],[128,(1+a)*32,(a)*48],[-128,(1+a)*32,(1+a)*48],[128,(1+a)*32,(1+a)*48]);
			CreateRectangle(objst,a*12+6, [0,256+((a*2)*16)],[256,256+((a*2+1)*16)], [-128,a*32,a*48],[128,a*32,a*48],[-128,(1+a)*32,a*48],[128,(1+a)*32,a*48]);
		}
		ObjRender_SetPosition(objst,0,0,300);

		let objst2 = ObjPrim_Create(OBJ_PRIMITIVE_3D);
		ObjPrim_SetPrimitiveType(objst2,PRIMITIVE_TRIANGLELIST);
		ObjPrim_SetVertexCount(objst2,24);
		ObjPrim_SetTexture(objst2,GetMainStgScriptDirectory ~ "img/bg/fog.png");
		Obj_SetRenderPriority(objst2,0.19);
		ObjRender_SetPosition(objst2,0,0,300);
		ascent(a in 0..12){ObjPrim_SetVertexColor(objst2,a,255/5,63/5,255/5);}
		CreateRectangle(objst2,0, [0,0],[1,1],
			[-128,(1.5)*32,0],[-128,(37.5)*32,(36)*48],
			[-168,(1.5)*32,0],[-168,(37.5)*32,(36)*48]);
		CreateRectangle(objst2,6, [0,0],[1,1],
			[128,(1.5)*32,0],[128,(37.5)*32,(36)*48],
			[168,(1.5)*32,0],[168,(37.5)*32,(36)*48]);

		let objst3 = ObjPrim_Create(OBJ_PRIMITIVE_3D);
		ObjPrim_SetPrimitiveType(objst3,PRIMITIVE_TRIANGLELIST);
		ObjPrim_SetVertexCount(objst3,24);
		ObjPrim_SetTexture(objst3,GetMainStgScriptDirectory ~ "img/bg/fog.png");
		Obj_SetRenderPriority(objst3,0.17);
		ObjRender_SetPosition(objst3,0,0,300);
		ascent(a in 0..24){ObjPrim_SetVertexColor(objst3,a,255/10,63/10,255/10);}
		CreateRectangle(objst3,0, [0,0],[1,1],
			[-128,(-1.5)*32,0],[-128,(37.5-3)*32,(36)*48],
			[-128,(1.5)*32,0],[-128,(37.5)*32,(36)*48]);
		CreateRectangle(objst3,6, [0,0],[1,1],
			[128,(-1.5)*32,0],[128,(37.5-3)*32,(36)*48],
			[128,(1.5)*32,0],[128,(37.5)*32,(36)*48]);
		CreateRectangle(objst3,12, [0,0],[1,1],
			[-168,(-1.5)*32,0],[-168,(37.5-3)*32,(36)*48],
			[-168,(1.5)*32,0],[-168,(37.5)*32,(36)*48]);
		CreateRectangle(objst3,18, [0,0],[1,1],
			[168,(-1.5)*32,0],[168,(37.5-3)*32,(36)*48],
			[168,(1.5)*32,0],[168,(37.5)*32,(36)*48]);

		descent(a in -2..9){
			CreateFloweers(-128*2.2,256*2.5+256/3*(a-3),256*1.8+256*3/2/3*a,0,-40,180);
			CreateFloweers(128*2.2,256*2.5+256/3*(a-3),256*1.8+256*3/2/3*a,180,40,0);
		}

		SetCameraAzimuthAngle(-90);
		SetCameraElevationAngle(20);

		while(true){

			SetCameraFocusXYZ(0,256*1.3+(z%256),256*1.8+(z%256)*3/2);

			SetFogParam(512*1.4+fog,1024+fog,255/2*(512+fog)/512,63/2*(512+fog)/512,255/2*(512+fog)/512);
			ObjRender_SetColor(obj,255/2*(512+fog)/512,63/2*(512+fog)/512,255/2*(512+fog)/512);

			SetCameraAzimuthAngle(-90-10*(GetPlayerX-320)/320);

			z+=288/80;
			fog = min(0,fog+512/60);

			yield;
		}

		task CreateRectangle(obj,i, pa,pb, p1,p2,p3,p4){
			ObjPrim_SetVertexUVT(obj,i+0,pa[0],pa[1]);
			ObjPrim_SetVertexUVT(obj,i+1,pb[0],pa[1]);
			ObjPrim_SetVertexUVT(obj,i+2,pa[0],pb[1]);

			ObjPrim_SetVertexUVT(obj,i+3,pb[0],pb[1]);
			ObjPrim_SetVertexUVT(obj,i+4,pb[0],pa[1]);
			ObjPrim_SetVertexUVT(obj,i+5,pa[0],pb[1]);

			ObjPrim_SetVertexPosition(obj,i+0,p1[0],p1[1],p1[2]);
			ObjPrim_SetVertexPosition(obj,i+1,p2[0],p2[1],p2[2]);
			ObjPrim_SetVertexPosition(obj,i+2,p3[0],p3[1],p3[2]);

			ObjPrim_SetVertexPosition(obj,i+3,p4[0],p4[1],p4[2]);
			ObjPrim_SetVertexPosition(obj,i+4,p2[0],p2[1],p2[2]);
			ObjPrim_SetVertexPosition(obj,i+5,p3[0],p3[1],p3[2]);
		}

		task CreateFloweers(x,y,z,an,an2,an3){
			let obj = ObjPrim_Create(OBJ_SPRITE_3D);
			ObjPrim_SetTexture(obj,GetMainStgScriptDirectory ~ "img/bg/ref1.png");
			Obj_SetRenderPriority(obj,0.16);
			ObjRender_SetPosition(obj,x,y,z);
			ObjRender_SetAngleXYZ(obj,an,an2,an3);
			ObjRender_SetScaleXYZ(obj,1.8,1.8,0);
			ObjSprite3D_SetSourceDestRect(obj,1,1,240,240);
			ObjRender_SetColor(obj,160,160,160);
		}
	}*/

	task Bg1{
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj,GetMainStgScriptDirectory ~ "img/bg/bg24.png");
		ObjSprite2D_SetSourceRect(obj,0,0,1280,720);ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj,480/720,480/720,0);
		ObjRender_SetPosition(obj,320,240,0);
		Obj_SetRenderPriority(obj,0.21);
	}
}
