
let CSD = GetCurrentScriptDirectory;


let texFloor = CSD ~ "background/Boss2parterreAutomne.png";
let texFloor2 = CSD ~ "background/Boss2TerreAutomne.png";
let texWall = CSD ~ "background/Boss2arbre.png";
let texFeuille = CSD ~ "background/feuille.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 to spawn a floor piece
function makeFloor1(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texFloor);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,512);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetAngleXYZ(obj,90,0,0);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}

function makeFloor2(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texFloor2);
	Obj_SetRenderPriorityI(obj,20);
	ObjSprite3D_SetSourceDestRect(obj,0,0,2048,2048);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetZWrite(obj,true);
	
	ObjRender_SetAngleXYZ(obj,90,0,0);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}


function makeWall1(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texWall);
	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,40,180);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}

function makeWall2(locX,locY,locZ) {
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,texWall);
	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,140,180);
	
	ObjRender_SetPosition(obj,locX,locY,locZ);
}

task renderStage {

	SetFogEnable(true);
	
	SetFogParam(1536,2048,70,30,30);

	makeFogBG(0,0,2560,255,255,255);
	
	makeFloor1(0,0,2560);
	makeFloor1(0,0,2048);
	makeFloor1(0,0,1536);
	makeFloor1(0,0,1024);
	makeFloor1(0,0,512);
	makeFloor1(0,0,0);
	
	makeFloor2(0,-1,2560);
	makeFloor2(0,-1,2048);
	makeFloor2(0,-1,1536);
	makeFloor2(0,-1,1024);
	makeFloor2(0,-1,512);
	makeFloor2(0,-1,0);
	
	makeWall2(-256,256,2560);
	makeWall2(-256,256,2048);
	makeWall2(-256,256,1536);
	makeWall2(-256,256,1024);
	makeWall2(-256,256,512);
	makeWall2(-256,256,0);
	
	makeWall1(256,256,2560);
	makeWall1(256,256,2048);
	makeWall1(256,256,1536);
	makeWall1(256,256,1024);
	makeWall1(256,256,512);
	makeWall1(256,256,0);
	
}

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

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