let CSD = GetCurrentScriptDirectory;

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

let texSeal = CSD ~ "sprite/seal.png";
let texSeal2 = CSD ~ "sprite/seal2.png";
//--------------------------------------------
//function to spawn a floor piece
function makeSeal(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texSeal);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,700,702);
        ObjRender_SetScaleXYZ(obj,0.3,0.3,0);
		ObjRender_SetBlendType(obj,BLEND_INV_DESTRGB);
        ObjRender_SetZWrite (obj, true); 

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

function makeSeal2(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texSeal2);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,600,592);
        ObjRender_SetScaleXYZ(obj,0.4,0.4,0);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
        ObjRender_SetZWrite (obj, true); 

       ObjRender_SetAngleXYZ(obj,180,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(100,2200,0,0,0);

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






makeSeal(20,50,50);
makeSeal2(-250,-50,50);
makeSeal2(280,-300,350);
makeSeal(-100,-200,800);
makeSeal2(-180,300,1000);
makeSeal(100,-200,50);
makeSeal2(300,700,300);
makeSeal(-300,40,800);
makeSeal2(180,50,1500);
makeSeal2(350,-700,50);





}

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 (85);
    SetCameraElevationAngle (-1);
    SetCameraRadius(64);

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

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



    loop {

       i = sin(f)*5;
       f+=0.5;
       scroll+=4;
      
       SetCameraRoll(0+i);
       SetCameraYaw(0+i/2);


       SetCameraFocusZ(-1000+scroll); 
       if(scroll > 4000) {
          scroll = 0;

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

        yield; 
   }



}