
let CSD = GetCurrentScriptDirectory;


let texRoche = CSD ~ "background/Roche.png";
let texChuteDeau = CSD ~ "background/ChuteDeau.png";
let texfogBG = CSD ~ "background/fog.png";


function makeFogBG(locX,locY,locZ,red,green,blue) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texfogBG);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite3D_SetSourceDestRect(obj,0,0,4096,4096);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
	
	ObjRender_SetColor(obj,red,green,blue);
	
	ObjSprite3D_SetBillboard(obj,true);
}


function makeRoche(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texRoche);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,512);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetAngleXYZ(obj,0,0,180);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}

function makeRoche2(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texRoche);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,512);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetAngleXYZ(obj,180,0,0);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}

function makeChuteDeau(locX,locY,locZ) {
	let bX = locX;
	let cY = locY;
	let dZ = locZ;
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texChuteDeau);
	Obj_SetRenderPriorityI(obj,21);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,512);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetAngleXYZ(obj,0,0,180);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
	chute(obj,bX,cY,dZ);
}

task renderStage {

	SetFogEnable(true);
	
	SetFogParam(1536,2048,230,195,130);

	makeFogBG(0,0,2560,255,255,255);
	
	makeChuteDeau(0,1536,10);
	makeChuteDeau(0,1024,10);
	makeChuteDeau(0,512,10);
	makeChuteDeau(0,0,10);
	makeChuteDeau(0,-512,10);
	
	makeRoche(0,1536,300);
	makeRoche(0,1024,300);
	makeRoche(0,512,300);
	makeRoche(0,0,300);
	makeRoche(0,-512,300);
	
	makeRoche2(-510,1536,300);
	makeRoche2(-510,1024,300);
	makeRoche2(-510,512,300);
	makeRoche2(-510,0,300);
	makeRoche2(-510,-512,300);
	
	makeRoche2(512,1536,300);
	makeRoche2(512,1024,300);
	makeRoche2(512,512,300);
	makeRoche2(512,0,300);
	makeRoche2(512,-512,300);
	
}

task chute(aaa,bX,cY,dZ) {
	let chut = 0;
	loop {
		ObjRender_SetPosition(aaa,bX,cY+chut,dZ);
		chut -=16;
		if(chut < -512) {
		chut = 0;
		}
		yield;
	}
}


task scrollStage {
	let scroll = 0;
	let i = 0;
	let f = 0;

	SetCameraPerspectiveClip(16,4096);
	
	
	SetCameraAzimuthAngle(-90);
	SetCameraElevationAngle(12);
	SetCameraRadius(16);
	SetCameraFocusX(0);
	SetCameraFocusY(-512+scroll);
	SetCameraFocusZ(-600);
	
	
	loop {
		i = sin(f)*25;
		f+=0.5;
		scroll+=4;
		
		SetCameraRoll(0+i/3);
		SetCameraYaw(0+i/4);
		
		SetCameraFocusY(0+scroll);
		if(scroll > 512) {
		scroll = 0;
		}
		
		yield;
	}
}