Code viewer for World: Online Tower Builder (clon...

// Cloned by John Lasis on 5 Dec 2022 from World "Online Tower Builder (clone by Colin Ekedigwe)" by Colin Ekedigwe 
// Please leave this clone trail here.
 


// Cloned by Colin Ekedigwe on 30 Nov 2022 from World "Online Tower Builder" by Joseph Adedayo 
// Please leave this clone trail here.
 

// online sockets 
//test  
// clean + submit
AB.newSplash (" <H2> PRESS SPACE TO START GAME ! </H2>");

 const SKYBOX_ARRAY = [										 
                "/uploads/starter/dawnmountain-xpos.png",
                "/uploads/starter/dawnmountain-xneg.png",
                "/uploads/starter/dawnmountain-ypos.png",
                "/uploads/starter/dawnmountain-yneg.png",
                "/uploads/starter/dawnmountain-zpos.png",
                "/uploads/starter/dawnmountain-zneg.png"
                ];
                
const boxcolor          = 'red';
const objectsize    = 5;                  // size of object   
const startRadius   = 400;                 // distance from centre we start the camera at
const maxRadius     = startRadius * 10;     // maximum distance from camera we render things 

var timer = true; 

// the object is a cube (each dimension equal): 
  
var higher = 0;
var higher2 = 0;
// Define what the World does at the start of a run: 

AB.socketStart();



AB.world.newRun = function() 
{
    // start a 3D scene: 
    ABWorld.init3d ( startRadius, maxRadius); 
    

    // add the object to the scene:
    
    AB.msg ( `<H2> PRESS SPACE TO START GAME ! </H2>` );

//function definition

function codingCourse() {
  console.log("TIME IS UP !");
  AB.msg ( `<H1> Your Score:  ${higher} </H1>  <H1> Opponent Score: ${higher2} </H1>  <H1> TIME IS UP ! </H1>` );
  timer = false;
}

   
     
    let items = ["black", "yellow", "green", "red", "pink", "purple", "orange"];

    

 
    document.body.onkeyup = function(e) {
     if ( ((e.key == " " || e.code == "Space" || e.keyCode == 32 )  && timer)
    ) {
    var boxcolor = items[Math.floor(Math.random()*items.length)];
    higher = higher + 5;
    var shape       = new THREE.SphereGeometry ( objectsize, objectsize, objectsize );
    var material    = new THREE.MeshBasicMaterial ( { color: boxcolor.toLowerCase() } );
    var theobject   = new THREE.Mesh ( shape, material );
    
    theobject.position.y = higher;

    AB.msg ( `<H1> Your Score:  ${higher} </H1>  <H1> Opponent Score: ${higher2} </H1>` );
       if (higher >= 5)
   {
    setTimeout(codingCourse, 10000);
    AB.removeSplash();  
   }
    ABWorld.scene.add ( theobject );
    sendscore(higher);
  }
}

    function sendscore(score)
{
  var theline = score;
  
  var data = 
  {
    line:       theline
  };
  
 // console.log(theline);
  AB.socketOut ( data );        // server gets this, and sends the data to all clients running this World
}

AB.socketIn = function(data)
{
   higher2 = data.line;
   console.log(higher2);
};


ABWorld.scene.background = new THREE.CubeTextureLoader().load ( SKYBOX_ARRAY,	function() 
	 { 
		ABWorld.render(); 
		AB.removeLoading();
		AB.runReady = true; 		
	 });
     
};