Code viewer for World: MineCraft+






// No actual World-Mind problem
// Just blank space for Three.js experiments 
// Ignores Mind actions


 
const	 	CLOCKTICK 	= 100;				// speed of run - move things every n milliseconds
const		MAXSTEPS 	= 1000;				// length of a run before final score
 


const ARMYSIZE = 30;       // an "army" of objects 

const objectsize = 300 ;

const WALKSTEP = 30;       // bounds of the random move per timestep 
                            // try 50 (vibrating sheet) versus 1000 (cloud)
         
const MAXPOS                = 4000 ;            // start things within these bounds                    
const startRadiusConst	 	= MAXPOS * 2 ;		// distance from centre to start the camera at
const maxRadiusConst 		= MAXPOS * 5 ;		// maximum distance from camera we will render things  


const SKYCOLOR 	= 0xffffff;				// a number, not a string 
 




function randomfloatAtoB ( A, B )			 
{
 return ( A + ( Math.random() * (B-A) ) );
}

function randomintAtoB ( A, B )			 
{
 return  ( Math.round ( randomfloatAtoB ( A, B ) ) );
}
  



function World() { 

    var THEARMY 	= new Array( ARMYSIZE );	



function initArmy()		 
{
 var t = 0;
 
 for ( var c=1 ; c <= ARMYSIZE  ; c++ )
 {
     
     // other use of comments - choice of different lines of code
     // "comment out" the code we're not using 
     
   //   var shape = new THREE.SphereGeometry ( objectsize, 10, 10 ); 
   	    var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  
  	var theobject  = new THREE.Mesh( shape );

  	theobject.position.x = randomintAtoB ( -MAXPOS, MAXPOS );   	
  	theobject.position.z = randomintAtoB ( -MAXPOS, MAXPOS );   	
  	theobject.position.y =  randomintAtoB ( -MAXPOS, MAXPOS );	
 
 	threeworld.scene.add(theobject);
	THEARMY[t] = theobject;	            	// save it for later
	t++; 
 }
}


function paintArmy()        // paint objects with random textures 
{
  var textureArray = [
 	( new THREE.ImageUtils.loadTexture( "/uploads/james/minecraftgreenore.jpg" ) ),
 	( new THREE.ImageUtils.loadTexture( "/uploads/james/stoneblock.jpg" ) ),
 	( new THREE.ImageUtils.loadTexture( "/uploads/james/dirt.jpg" ) )
 	
  	];
 	
 for ( var i = 0; i < textureArray.length; i++ )    // for all textures 
 { 
    textureArray[i].minFilter = THREE.LinearFilter;
 }
 
 for ( var i = 0; i < THEARMY.length; i++ )     // for all objects 
 { 
   if ( THEARMY[i] )
   { 
        var t = randomintAtoB ( 0, textureArray.length - 1 );     // random texture 
       //  var t = 1;
        THEARMY[i].material =  new THREE.MeshBasicMaterial ( { map: textureArray[t] } );   
   }
 }    	 
}


function moveArmy()		    // move all the objects 
{
 for ( var i = 0; i < THEARMY.length; i++ )
 { 
   if ( THEARMY[i] )
   { 
        THEARMY[i].position.x =  THEARMY[i].position.x + randomintAtoB(-WALKSTEP,WALKSTEP) ;        
        THEARMY[i].position.z =  THEARMY[i].position.z + randomintAtoB(-WALKSTEP,WALKSTEP) ;
        THEARMY[i].position.y =  THEARMY[i].position.y + randomintAtoB(-WALKSTEP,WALKSTEP) ;
        threeworld.scene.add( THEARMY[i] );
   }
 }
}


	this.endCondition;			 


this.newRun = function() 
{
  this.endCondition = false;

  threeworld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  ); 

 	  initArmy();
 	  paintArmy();  
	    // comment out for random coloured objects 	 
};



this.getState = function()
{
  return ( null );  
};


this.takeAction = function ( a )
{
  moveArmy();
};



this.endRun = function()
{
};


this.getScore = function()
{
 return 0;
};

}