let CSD = GetCurrentScriptDirectory;

//textures

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

let texPillar = CSD ~ "sprite/concrete1.png";

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

let texLamp = CSD ~ "sprite/lamp.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,512,512);
        ObjRender_SetScaleXYZ(obj,0.35,0.35,0);
        ObjRender_SetZWrite (obj, true); 

       ObjRender_SetAngleXYZ(obj,90,0,0);
       ObjRender_SetPosition(obj,locX,locY,locZ);
}
//function to spawn wall
function makeWall(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texPillar);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,600,1117);
        ObjRender_SetScaleXYZ(obj,0.3,0.3,0);
        ObjRender_SetZWrite (obj, true); 

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

function makeWall2(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texPillar);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,600,1117);
        ObjRender_SetScaleXYZ(obj,0.3,0.3,0);
        ObjRender_SetZWrite (obj, true); 

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

function makeLamp(locX,locY,locZ) {
        let obj = ObjPrim_Create(OBJ_SPRITE_3D);
        ObjPrim_SetTexture(obj,texLamp);
        Obj_SetRenderPriorityI(obj,20);
        ObjSprite3D_SetSourceDestRect(obj,0,0,337,406);
        ObjRender_SetScaleXYZ(obj,0.35,0.35,0);
        ObjRender_SetZWrite (obj, true); 

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

makeWall(-120,-35,1410);
makeWall(300,-65,1110);
makeWall(0,-135,1010);

makeWall2(-30,-35,1498);
makeWall2(210,-65,1198);
makeWall2(0,-135,1010);


makeFloor(-120,130,1500);
makeFloor(300,100,1200);
makeFloor(0,30,1100);

makeLamp (-120,185,1500);
makeLamp (300,160,1200);
makeLamp (0,92,1100);




}

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(256);               //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 > 3000) {
          scroll = 0;

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

        yield; 
   }



}

