let CSD = GetCurrentScriptDirectory;


let texFog = CSD ~ "sprite/fog.png";


let texFloor = CSD ~ "sprite/space.png";





//--------------------------------------------
//function to spawn a floor piece
function makeFloor(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texFloor);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,600,600);
        ObjRender_SetScaleXYZ(obj,4,4,0);
        ObjRender_SetZWrite (obj, true); 

       ObjRender_SetAngleXYZ(obj,90,0,0);
       ObjRender_SetPosition(obj,locX,locY,locZ);
	  
}





function makeFog(locX,locY,locZ,red,green,blue) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texFog);
        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);


    ObjSprite3D_SetBillboard(obj, true); //makes this object face camera no matter where the camera is facing 
}

//--------------------------------
task renderStage {

//enable the fog

SetFogEnable(true);

//set begining and end of fog and color
SetFogParam(1000,2000,0,0,0);

makeFog(0,0,2048,344,255,255);

makeFloor(0,10,2400);
makeFloor(0,10,1200);
makeFloor(0,10,0);
makeFloor(0,10,-1200);



//------






}

task scrollStage{


 let i = 0;
 let f = 0;
 let scroll = 0;


  //set the minimum and maximum render distance for your camera
    SetCameraPerspectiveClip(16,4096);


 //azimuth camera
    SetCameraAzimuthAngle (-90);
    SetCameraElevationAngle (0);
    SetCameraRadius(64);

 //focus camera
     SetCameraFocusX(0);                //left or right
    SetCameraFocusY(1000);               //up or down
    SetCameraFocusZ(-512+scroll);         //depth forward and back 

 // ? camera    
     SetCameraYaw(0);
     SetCameraPitch(60);
     SetCameraRoll(0);   



    loop {

       i = sin(f)*25;
       f+=0.5;
       scroll+=4;
      
       


       SetCameraFocusZ(-600+scroll); 
       if(scroll > 1200) {
          scroll = 0;

        }
        scroll+=2; //speed of the counting

        yield; 
   }
   }