Code viewer for World: Denis Craft(main world)


//would like to thank you for this project as it has been the most fun I've had programming so far in this course!

//this game is enjoyable for people as it allows them to be creative. Adding a score also gives the game a purpose which is more enjoyable.




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

const  SCREENSHOT_STEP = 50;    

var count = 0;
const squaresize = 100;


const objectsize = 200 ;

const MAXPOS                = 4000 ;                                 
const startRadiusConst	 	= MAXPOS * 0.5 ;		// distance from centre to start the camera at
const maxRadiusConst 		= MAXPOS * 5 ;		// maximum distance from camera we will render things  

const show3d = true;
const SKYCOLOR 	= 0xFFFFFF;				// a number, not a string 
 
var self = this;


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

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

//this function causes world to sleep for a given time
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}





function World() { 

var x, y, z;        // current location 
var ei, ej, ai, aj, si, sj;
var textureArray;


function init()		 
{
    //contains images used in this project
   textureArray = [
 	( new THREE.ImageUtils.loadTexture( "/uploads/starter/minecraft.1.jpg" ) ),
 	( new THREE.ImageUtils.loadTexture( "/uploads/starter/minecraft.2.jpg" ) ),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/150px-minecraft_tree.png" ) ),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/35f18e942ef894c743d9363a61a36c60.jpg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/sheep.png")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/cow_.jpg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/tall_grass.png")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/images.jpeg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/flat800x800070f.jpg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/25e5472cf4a3ce96b2b3223408677e03.jpg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/door.jpeg")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/window.png")),
 	( new THREE.ImageUtils.loadTexture( "/uploads/2tczkf6z/chimney.jpeg"))
 	];
 	
 for ( var i = 0; i < textureArray.length; i++ )    // for all textures 
 { 
    textureArray[i].minFilter = THREE.LinearFilter;
 }
 
 
 x = 0;
 y = 0;
 z = 0;

//these for loops create the world of boxes presented when you run

 for ( var i = 1; i <= 10; i++ )      
 {
     var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	 var  theobject  = new THREE.Mesh( shape );

 // console.log(i);
 
 	theobject.position.x =  objectsize * i;    	
  	theobject.position.z =  0; 	
  	theobject.position.y =  0;	
 
 	threeworld.scene.add(theobject);
    paintThis ( theobject,0 );
    
    makeSideRow ( 	theobject.position.x, 	theobject.position.y );
 }
 
  
  // stairs:
  
     for ( i = 1; i <= 10; i++ )      
 {
      shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	  theobject  = new THREE.Mesh( shape );

 	theobject.position.x =  (objectsize*10) + (objectsize * i);    	
  	theobject.position.z =  0; 	
  	theobject.position.y =  0;	
 
 	threeworld.scene.add(theobject);
    paintThis ( theobject,0 );
    
    makeSideRow ( 	theobject.position.x, 	theobject.position.y );
 }
 
    
    //  exercise - make stairs up and stairs down 
  
}


//used also to make beginning world
function makeSideRow ( x, y )          // put 2nd for loop in separate function
{
       for ( var i = 1; i <= 20; i++ )      
 {
      var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	  var theobject  = new THREE.Mesh( shape );
    
 	theobject.position.x =  x;    	
  	theobject.position.z =  objectsize * i ; 	
  	theobject.position.y =  y;	
 
 	threeworld.scene.add(theobject);
    paintThis ( theobject,0 );
     
    
 }
}
//this function when called draws a box that contains an image of a minecraft pig

function drawPig(){
     var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var pig  = new THREE.Mesh( shape );
  	pig.position.x = x;    
  pig.position.y = y;
  pig.position.z = z;
  threeworld.scene.add(pig); paintThis (pig,3);
  count++;
  updateStatusAfter();

 
}

//when called this function draws a box that contains an image of a minecraft sheep
function drawSheep(){
     var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var sheep  = new THREE.Mesh( shape1 );
  	sheep.position.x = x;    
  sheep.position.y = y;
  sheep.position.z = z;
  threeworld.scene.add(sheep); paintThis (sheep,4);
  count++;
  updateStatusAfter();

 
}
//when called this function creates a box with an image of a minecraft cow
function drawCow(){
     var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var cow = new THREE.Mesh( shape1 );
  cow.position.x = x;     
  cow.position.y = y;
  cow.position.z = z;
  threeworld.scene.add(cow); paintThis (cow,5);
  count++;
  updateStatusAfter();

 
}
//this function creates a cow at an already defined posistion
function starterCow(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var cow1 = new THREE.Mesh( shape1 );
  cow1.position.x = 600;     
  cow1.position.y = 200;
  cow1.position.z = 400;
  threeworld.scene.add(cow1); paintThis (cow1,5);
  count++;
  updateStatusAfter();
}
//this function creates a tree at an already defined posistion
function starterTree(){
    var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
    var tree  = new THREE.Mesh( shape );
       var tree1  = new THREE.Mesh( shape );
       var tree2  = new THREE.Mesh( shape );
       tree.position.x = 2400;
       tree.position.y = 200;
      tree.position.z = 1200; 
       threeworld.scene.add(tree); paintThis (tree,2);
          count++;
          sleep(1000);
          
                    
          function well(){
        
        
        tree1.position.x = 2400;
       tree1.position.y = 400;
      tree1.position.z = 1200; threeworld.scene.add(tree1); paintThis (tree1,2); 
        count++;
        tree2.position.x = 2400;
       tree2.position.y = 600;
      tree2.position.z = 1200;threeworld.scene.add(tree2); paintThis (tree2,2);
        count++; updateStatusAfter();
}
well();
}
//this function creates a pig at an already defined posistion
function starterPig(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var pig1 = new THREE.Mesh( shape1 );
  pig1.position.x = 600;     
  pig1.position.y = 200;
  pig1.position.z = 800;
  threeworld.scene.add(pig1); paintThis (pig1,3);
  count++;
  updateStatusAfter();
}
//this function creates a sheep at a given posistion
function starterSheep(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var sheep1 = new THREE.Mesh( shape1 );
  sheep1.position.x = 1000;    
  sheep1.position.y = 200;
  sheep1.position.z = 800;
  threeworld.scene.add(sheep1); paintThis (sheep1,4);
  count++;
  updateStatusAfter();
}

//this function creates an object with an image of minecraft grass
function drawGrass(){
     var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var grass = new THREE.Mesh( shape1 );
  grass.position.x = x;    
  grass.position.y = y;
  grass.position.z = z;
  threeworld.scene.add(grass); paintThis (grass,6);

  updateStatusAfter();

 
}
//creates grass at a given location
function starterGrass(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var Grass1 = new THREE.Mesh( shape1 );
  Grass1.position.x = 1000;     
  Grass1.position.y = 200;
  Grass1.position.z = 400;
  threeworld.scene.add(Grass1); paintThis (Grass1,6);

  updateStatusAfter();
}
//draws a fence
function drawFence(){
     var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var fence = new THREE.Mesh( shape1 );
  fence.position.x = x;     
  fence.position.y = y;
  fence.position.z = z;
  threeworld.scene.add(fence); paintThis (fence,7);
  count++;
  updateStatusAfter();

 
}
//used to draw stone
function drawStone(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var stone = new THREE.Mesh( shape1 );
  stone.position.x = x;     
  stone.position.y = y;
  stone.position.z = z;
  threeworld.scene.add(stone); paintThis (stone,8);

  updateStatusAfter();
}
//this function when called creates a castle at a given posistion
function drawCastle(){
     var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var castle1 = new THREE.Mesh( shape1 );
  	var castle3 = new THREE.Mesh( shape1 );
  	var castle5 = new THREE.Mesh( shape1 );
  	var castle6 = new THREE.Mesh( shape1 );
  	var castle7 = new THREE.Mesh( shape1 );
  	var castle8 = new THREE.Mesh( shape1 );
  	var castle9 = new THREE.Mesh( shape1 );
  	var castle10 = new THREE.Mesh( shape1 );
  	var castle11 = new THREE.Mesh( shape1 );
  	var castle12 = new THREE.Mesh( shape1 );
  	var castle13 = new THREE.Mesh( shape1 );
  	var castle14 = new THREE.Mesh( shape1 );
  	var castle15 = new THREE.Mesh( shape1 )
  	var castle16 = new THREE.Mesh( shape1 );


 castle1.position.x = 2400;     
  castle1.position.y =200;
  castle1.position.z = 1600;
  threeworld.scene.add(castle1); paintThis (castle1,9);
  updateStatusAfter();
    
  castle3.position.x = 2400;     
  castle3.position.y =200;
  castle3.position.z = 1800;
  threeworld.scene.add(castle3); paintThis (castle3,9);
  updateStatusAfter();
  
  castle5.position.x = 2400;     
  castle5.position.y =200;
  castle5.position.z = 2400;
  threeworld.scene.add(castle5); paintThis (castle5,9);
  updateStatusAfter();
  castle6.position.x = 2400;      
  castle6.position.y =200;
  castle6.position.z = 2600;
  threeworld.scene.add(castle6); paintThis (castle6,9);
  updateStatusAfter();
  castle7.position.x = 2600;      
  castle7.position.y =200;
  castle7.position.z = 2600;
  threeworld.scene.add(castle7); paintThis (castle7,9);
  updateStatusAfter();
  castle8.position.x = 2800;     
  castle8.position.y =200;
  castle8.position.z = 2600;
  threeworld.scene.add(castle8); paintThis (castle8,9);
  updateStatusAfter();
  castle9.position.x = 2800;     
  castle9.position.y =200;
  castle9.position.z = 1600;
  threeworld.scene.add(castle9); paintThis (castle9,9);
  updateStatusAfter();
  castle10.position.x = 2600;     
  castle10.position.y =200;
  castle10.position.z = 1600;
  threeworld.scene.add(castle10); paintThis (castle10,9);
  updateStatusAfter();

  //----------------------------------
  castle11.position.x = 3000;      
  castle11.position.y =200;
  castle11.position.z = 1600;
  threeworld.scene.add(castle11); paintThis (castle11,9);
  updateStatusAfter();
  castle12.position.x = 3000;      
  castle12.position.y =200;
  castle12.position.z = 1800;
  threeworld.scene.add(castle12); paintThis (castle12,9);
  updateStatusAfter();
  castle13.position.x = 3000;      
  castle13.position.y =200;
  castle13.position.z = 2000;
  threeworld.scene.add(castle13); paintThis (castle13,9);
  updateStatusAfter();
  castle14.position.x = 3000;     
  castle14.position.y =200;
  castle14.position.z = 2200;
  threeworld.scene.add(castle14); paintThis (castle14,9);
  updateStatusAfter();
  castle15.position.x = 3000;     
  castle15.position.y =200;
  castle15.position.z = 2400;
  threeworld.scene.add(castle15); paintThis (castle15,9);
  updateStatusAfter();
  castle16.position.x = 3000;     
  castle16.position.y =200;
  castle16.position.z = 2600;
  threeworld.scene.add(castle16); paintThis (castle16,9);
  updateStatusAfter();

//----------second level----------------

var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
var chimneyShape = new THREE.BoxGeometry( 40, objectsize, 40 );
var smokeShape = new THREE.BoxGeometry( 10, 40, 10 );

  	var castlea = new THREE.Mesh( shape1 );
  	var castleb = new THREE.Mesh( shape1 );
  	var castlec = new THREE.Mesh( shape1 );
  	var castled = new THREE.Mesh( shape1 );
  	var castlee = new THREE.Mesh( shape1 );
  	var castlef = new THREE.Mesh( shape1 );
  	var castleg = new THREE.Mesh( shape1 );
  	var castleh = new THREE.Mesh( shape1 );
  	var castlei = new THREE.Mesh( shape1 );
  	var castlej = new THREE.Mesh( shape1 );
  	var castlek = new THREE.Mesh( shape1 );
  	var castlel = new THREE.Mesh( shape1 );
  	var castlem = new THREE.Mesh( shape1 )
  	var castlen = new THREE.Mesh( shape1 );
  	var window1 = new THREE.Mesh( shape1 );
  	var window2 = new THREE.Mesh( shape1 );
  	var door1 = new THREE.Mesh( shape1 );
  	var door2 = new THREE.Mesh( shape1 );
  	var door3 = new THREE.Mesh( shape1 );
  	var door4 = new THREE.Mesh( shape1 );


 castlea.position.x = 2400;     // default position is current position - going to then move it 
  castlea.position.y =400;
  castlea.position.z = 1600;
  threeworld.scene.add(castlea); paintThis (castlea,9);
  updateStatusAfter();
    
  castleb.position.x = 2400;     // default position is current position - going to then move it 
  castleb.position.y =400;
  castleb.position.z = 1800;
  threeworld.scene.add(castleb); paintThis (castleb,9);
  updateStatusAfter();
  
  
  //windows for the castle 
  window1.position.x = 2395;     // default position is current position - going to then move it 
  window1.position.y =350;
  window1.position.z = 1700;
  threeworld.scene.add(window1); paintThis (window1,11);
  updateStatusAfter();
  
    window2.position.x = 2395;     // default position is current position - going to then move it 
  window2.position.y =350;
  window2.position.z = 2500;
  threeworld.scene.add(window2); paintThis (window2,11);
  updateStatusAfter();
  //door for the castle
  door1.position.x = 2390;     // default position is current position - going to then move it 
  door1.position.y =200;
  door1.position.z = 2000;
  threeworld.scene.add(door1); paintThis (door1,10);
  updateStatusAfter();
  
  door2.position.x = 2390;     // default position is current position - going to then move it 
  door2.position.y =200;
  door2.position.z = 2200;
  threeworld.scene.add(door2); paintThis (door2,10);
  updateStatusAfter();
  
  
  door3.position.x = 2390;     // default position is current position - going to then move it 
  door3.position.y =400;
  door3.position.z = 2000;
  threeworld.scene.add(door3); paintThis (door3,10);
  updateStatusAfter();
  
  door4.position.x = 2390;     // default position is current position - going to then move it 
  door4.position.y =400;
  door4.position.z = 2200;
  threeworld.scene.add(door4); paintThis (door4,10);
  updateStatusAfter();
  
  
  
  
  castlec.position.x = 2400;     // default position is current position - going to then move it 
  castlec.position.y =400;
  castlec.position.z = 2400;
  threeworld.scene.add(castlec); paintThis (castlec,9);
  updateStatusAfter();
  castled.position.x = 2400;     // default position is current position - going to then move it 
  castled.position.y =400;
  castled.position.z = 2600;
  threeworld.scene.add(castled); paintThis (castled,9);
  updateStatusAfter();
  castlee.position.x = 2600;     // default position is current position - going to then move it 
  castlee.position.y =400;
  castlee.position.z = 2600;
  threeworld.scene.add(castlee); paintThis (castlee,9);
  updateStatusAfter();
  castlef.position.x = 2800;     // default position is current position - going to then move it 
  castlef.position.y =400;
  castlef.position.z = 2600;
  threeworld.scene.add(castlef); paintThis (castlef,9);
  updateStatusAfter();
  castleg.position.x = 2800;     // default position is current position - going to then move it 
  castleg.position.y =400;
  castleg.position.z = 1600;
  threeworld.scene.add(castleg); paintThis (castleg,9);
  updateStatusAfter();
  castleh.position.x = 2600;     // default position is current position - going to then move it 
  castleh.position.y =400;
  castleh.position.z = 1600;
  threeworld.scene.add(castleh); paintThis (castleh,9);
  updateStatusAfter();

  //----------------------------------
  castlei.position.x = 3000;     // default position is current position - going to then move it 
  castlei.position.y =400;
  castlei.position.z = 1600;
  threeworld.scene.add(castlei); paintThis (castlei,9);
  updateStatusAfter();
  castlej.position.x = 3000;     // default position is current position - going to then move it 
  castlej.position.y =400;
  castlej.position.z = 1800;
  threeworld.scene.add(castlej); paintThis (castlej,9);
  updateStatusAfter();
  castlek.position.x = 3000;     // default position is current position - going to then move it 
  castlek.position.y =400;
  castlek.position.z = 2000;
  threeworld.scene.add(castlek); paintThis (castlek,9);
  updateStatusAfter();
  castlel.position.x = 3000;     // default position is current position - going to then move it 
  castlel.position.y =400;
  castlel.position.z = 2200;
  threeworld.scene.add(castlel); paintThis (castlel,9);
  updateStatusAfter();
  castlem.position.x = 3000;     // default position is current position - going to then move it 
  castlem.position.y =400;
  castlem.position.z = 2400;
  threeworld.scene.add(castlem); paintThis (castlem,9);
  updateStatusAfter();
  castlen.position.x = 3000;     // default position is current position - going to then move it 
  castlen.position.y =400;
  castlen.position.z = 2600;
  threeworld.scene.add(castlen); paintThis (castlen,9);
  updateStatusAfter();

//the roof vars are used to create the roof of the castle
var roof1 = new THREE.Mesh( shape1 );
roof1.position.x = 3000;     // default position is current position - going to then move it 
  roof1.position.y =600;
  roof1.position.z = 2600;
  threeworld.scene.add(roof1); paintThis (roof1,8);
  updateStatusAfter();
  var roof2 = new THREE.Mesh( shape1 );
roof2.position.x = 3000;     // default position is current position - going to then move it 
  roof2.position.y =600;
  roof2.position.z = 2400;
  threeworld.scene.add(roof2); paintThis (roof2,8);
  updateStatusAfter();

var roof3 = new THREE.Mesh( shape1 );
roof3.position.x = 3000;     // default position is current position - going to then move it 
  roof3.position.y =600;
  roof3.position.z = 2200;
  threeworld.scene.add(roof3); paintThis (roof3,8);
  updateStatusAfter();

var roof4 = new THREE.Mesh( shape1 );
roof4.position.x = 3000;     // default position is current position - going to then move it 
  roof4.position.y =600;
  roof4.position.z = 2000;
  threeworld.scene.add(roof4); paintThis (roof4,8);
  updateStatusAfter();

var roof5 = new THREE.Mesh( shape1 );
roof5.position.x = 3000;     // default position is current position - going to then move it 
  roof5.position.y =600;
  roof5.position.z = 1800;
  threeworld.scene.add(roof5); paintThis (roof5,8);
  updateStatusAfter();

var roof6 = new THREE.Mesh( shape1 );
roof6.position.x = 3000;     // default position is current position - going to then move it 
  roof6.position.y =600;
  roof6.position.z = 1600;
  threeworld.scene.add(roof6); paintThis (roof6,8);
  updateStatusAfter();
  
var roof7 = new THREE.Mesh( shape1 );
roof7.position.x = 2800;     // default position is current position - going to then move it 
  roof7.position.y =600;
  roof7.position.z = 1600;
  threeworld.scene.add(roof7); paintThis (roof7,8);
  updateStatusAfter();

var roof8 = new THREE.Mesh( shape1 );
roof8.position.x = 2600;     // default position is current position - going to then move it 
  roof8.position.y =600;
  roof8.position.z = 1600;
  threeworld.scene.add(roof8); paintThis (roof8,8);
  updateStatusAfter();
  
var roof9 = new THREE.Mesh( shape1 );
roof9.position.x = 2400;     // default position is current position - going to then move it 
  roof9.position.y =600;
  roof9.position.z = 1600;
  threeworld.scene.add(roof9); paintThis (roof9,8);
  updateStatusAfter();

  var roof10 = new THREE.Mesh( shape1 );
roof10.position.x = 2400;     // default position is current position - going to then move it 
  roof10.position.y =600;
  roof10.position.z = 2400;
  threeworld.scene.add(roof10); paintThis (roof10,8);
  updateStatusAfter();

var roof11 = new THREE.Mesh( shape1 );
roof11.position.x = 2400;     // default position is current position - going to then move it 
  roof11.position.y =600;
  roof11.position.z = 2200;
  threeworld.scene.add(roof11); paintThis (roof11,8);
  updateStatusAfter();

var roof12 = new THREE.Mesh( shape1 );
roof12.position.x = 2400;     // default position is current position - going to then move it 
  roof12.position.y =600;
  roof12.position.z = 2000;
  threeworld.scene.add(roof12); paintThis (roof12,8);
  updateStatusAfter();

var roof13 = new THREE.Mesh( shape1 );
roof13.position.x = 2400;     // default position is current position - going to then move it 
  roof13.position.y =600;
  roof13.position.z = 1800;
  threeworld.scene.add(roof13); paintThis (roof13,8);
  updateStatusAfter();

var roof14 = new THREE.Mesh( shape1 );
roof14.position.x = 2400;     // default position is current position - going to then move it 
  roof14.position.y =600;
  roof14.position.z = 2600;
  threeworld.scene.add(roof14); paintThis (roof14,8);
  updateStatusAfter();
  
  //creates a chimney for the castle
  var chimney1 = new THREE.Mesh( chimneyShape );
chimney1.position.x = 2400;     // default position is current position - going to then move it 
  chimney1.position.y =800;
  chimney1.position.z = 2400;
  threeworld.scene.add(chimney1); paintThis (chimney1,12);
  updateStatusAfter();

//creates smoke which is placed above the chimney
  var smoke = new THREE.Mesh( smokeShape );
smoke.position.x = 2400;     // default position is current position - going to then move it 
  smoke.position.y =1100;
  smoke.position.z = 2400;
  threeworld.scene.add(smoke); paintThis (smoke,8);
  updateStatusAfter();

  var smoke7 = new THREE.Mesh( smokeShape );
smoke7.position.x = 2400;     // default position is current position - going to then move it 
  smoke7.position.y =1000;
  smoke7.position.z = 2400;
  threeworld.scene.add(smoke7); paintThis (smoke7,8);
  updateStatusAfter();
    var smoke1 = new THREE.Mesh( smokeShape );
smoke1.position.x = 2400;     // default position is current position - going to then move it 
  smoke1.position.y =1200;
  smoke1.position.z = 2400;
  threeworld.scene.add(smoke1); paintThis (smoke1,8);
  updateStatusAfter();
    var smoke2 = new THREE.Mesh( smokeShape );
smoke2.position.x = 2400;     // default position is current position - going to then move it 
  smoke2.position.y =1300;
  smoke2.position.z = 2400;
  threeworld.scene.add(smoke2); paintThis (smoke2,8);
  updateStatusAfter();
    var smoke3 = new THREE.Mesh( smokeShape );
smoke3.position.x = 2400;     // default position is current position - going to then move it 
  smoke3.position.y =1400;
  smoke3.position.z = 2400;
  threeworld.scene.add(smoke3); paintThis (smoke3,8);
  updateStatusAfter();


//------side of roof
var roof15 = new THREE.Mesh( shape1 );
roof15.position.x = 2800;     // default position is current position - going to then move it 
  roof15.position.y =600;
  roof15.position.z = 1600;
  threeworld.scene.add(roof15); paintThis (roof15,8);
  updateStatusAfter();

var roof16 = new THREE.Mesh( shape1 );
roof16.position.x = 2600;     // default position is current position - going to then move it 
  roof16.position.y =600;
  roof16.position.z = 1600;
  threeworld.scene.add(roof16); paintThis (roof16,8);
  updateStatusAfter();
  
var roof17 = new THREE.Mesh( shape1 );
roof17.position.x = 2400;     // default position is current position - going to then move it 
  roof17.position.y =600;
  roof17.position.z = 1600;
  threeworld.scene.add(roof17); paintThis (roof17,8);
  updateStatusAfter();



//--------------------------------------------

var roof18 = new THREE.Mesh( shape1 );
roof18.position.x = 2800;     // default position is current position - going to then move it 
  roof18.position.y =600;
  roof18.position.z = 2600;
  threeworld.scene.add(roof18); paintThis (roof18,8);
  updateStatusAfter();

var roof19 = new THREE.Mesh( shape1 );
roof19.position.x = 2600;     // default position is current position - going to then move it 
  roof19.position.y =600;
  roof19.position.z = 2600;
  threeworld.scene.add(roof19); paintThis (roof19,8);
  updateStatusAfter();
  
var roof20 = new THREE.Mesh( shape1 );
roof20.position.x = 2400;     // default position is current position - going to then move it 
  roof20.position.y =600;
  roof20.position.z = 2600;
  threeworld.scene.add(roof20); paintThis (roof20,8);
  updateStatusAfter();



 
}

//creates a fence in a given location
function starterFence1(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var fence1 = new THREE.Mesh( shape1 );
  	var fence2 = new THREE.Mesh( shape1 );
  	var fence3 = new THREE.Mesh( shape1 );
  	var fence4 = new THREE.Mesh( shape1 );
  	var fence5 = new THREE.Mesh( shape1 );
  	var fence6 = new THREE.Mesh( shape1 );
  	var fence7 = new THREE.Mesh( shape1 );
  fence1.position.x = 1400;     // default position is current position - going to then move it 
  fence1.position.y =200;
  fence1.position.z = 0;
  threeworld.scene.add(fence1); paintThis (fence1,7);
  count++;
  updateStatusAfter();
  fence2.position.x = 1200;     // default position is current position - going to then move it 
  fence2.position.y =200;
  fence2.position.z = 0;
  threeworld.scene.add(fence2); paintThis (fence2,7);
  count++;
  updateStatusAfter();
    fence3.position.x = 1000;     // default position is current position - going to then move it 
  fence3.position.y =200;
  fence3.position.z = 0;
  threeworld.scene.add(fence3); paintThis (fence3,7);
  count++;
  updateStatusAfter();
    fence4.position.x = 800;     // default position is current position - going to then move it 
  fence4.position.y =200;
  fence4.position.z = 0;
  threeworld.scene.add(fence4); paintThis (fence4,7);
  count++;
  updateStatusAfter();
    fence5.position.x = 600;     // default position is current position - going to then move it 
  fence5.position.y =200;
  fence5.position.z = 0;
  threeworld.scene.add(fence5); paintThis (fence5,7);
  count++;
  updateStatusAfter();
    fence6.position.x = 400;     // default position is current position - going to then move it 
  fence6.position.y =200;
  fence6.position.z = 0;
  threeworld.scene.add(fence6); paintThis (fence6,7);
  count++;
  updateStatusAfter();
    fence7.position.x = 200;     // default position is current position - going to then move it 
  fence7.position.y =200;
  fence7.position.z = 0;
  threeworld.scene.add(fence7); paintThis (fence7,7);
  count++;
  updateStatusAfter();
  
}

function starterFence2(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var fence1 = new THREE.Mesh( shape1 );
  	var fence2 = new THREE.Mesh( shape1 );
  	var fence3 = new THREE.Mesh( shape1 );
  	var fence4 = new THREE.Mesh( shape1 );
  	var fence5 = new THREE.Mesh( shape1 );
  	var fence6 = new THREE.Mesh( shape1 );
  	var fence7 = new THREE.Mesh( shape1 );
  fence1.position.x = 1400;     // default position is current position - going to then move it 
  fence1.position.y =200;
  fence1.position.z = 1200;
  threeworld.scene.add(fence1); paintThis (fence1,7);
  count++;
  updateStatusAfter();
  fence2.position.x = 1200;     // default position is current position - going to then move it 
  fence2.position.y =200;
  fence2.position.z = 1200;
  threeworld.scene.add(fence2); paintThis (fence2,7);
  count++;
  updateStatusAfter();
    fence3.position.x = 1000;     // default position is current position - going to then move it 
  fence3.position.y =200;
  fence3.position.z = 1200;
  threeworld.scene.add(fence3); paintThis (fence3,7);
  count++;
  updateStatusAfter();
    fence4.position.x = 800;     // default position is current position - going to then move it 
  fence4.position.y =200;
  fence4.position.z = 1200;
  threeworld.scene.add(fence4); paintThis (fence4,7);
  count++;
  updateStatusAfter();
    fence5.position.x = 600;     // default position is current position - going to then move it 
  fence5.position.y =200;
  fence5.position.z = 1200;
  threeworld.scene.add(fence5); paintThis (fence5,7);
  count++;
  updateStatusAfter();
    fence6.position.x = 400;     // default position is current position - going to then move it 
  fence6.position.y =200;
  fence6.position.z = 1200;
  threeworld.scene.add(fence6); paintThis (fence6,7);
  count++;
  updateStatusAfter();
    fence7.position.x = 200;     // default position is current position - going to then move it 
  fence7.position.y =200;
  fence7.position.z = 1200;
  threeworld.scene.add(fence7); paintThis (fence7,7);
  count++;
  updateStatusAfter();
  
}

function starterFence3(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var fence1 = new THREE.Mesh( shape1 );
  	var fence2 = new THREE.Mesh( shape1 );
  	var fence3 = new THREE.Mesh( shape1 );
  	var fence4 = new THREE.Mesh( shape1 );
  	var fence5 = new THREE.Mesh( shape1 );
  	var fence6 = new THREE.Mesh( shape1 );
  	var fence7 = new THREE.Mesh( shape1 );
  fence1.position.x = 1400;     // default position is current position - going to then move it 
  fence1.position.y =200;
  fence1.position.z = 1200;
  threeworld.scene.add(fence1); paintThis (fence1,7);
  count++;
  updateStatusAfter();
  fence2.position.x = 1400;     // default position is current position - going to then move it 
  fence2.position.y =200;
  fence2.position.z = 1000;
  threeworld.scene.add(fence2); paintThis (fence2,7);
  count++;
  updateStatusAfter();
    fence3.position.x = 1400;     // default position is current position - going to then move it 
  fence3.position.y =200;
  fence3.position.z = 800;
  threeworld.scene.add(fence3); paintThis (fence3,7);
  count++;
  updateStatusAfter();
    fence4.position.x = 1400;     // default position is current position - going to then move it 
  fence4.position.y =200;
  fence4.position.z = 600;
  threeworld.scene.add(fence4); paintThis (fence4,7);
  count++;
  updateStatusAfter();
    fence5.position.x = 1400;     // default position is current position - going to then move it 
  fence5.position.y =200;
  fence5.position.z = 400;
  threeworld.scene.add(fence5); paintThis (fence5,7);
  count++;
  updateStatusAfter();
    fence6.position.x = 1400;     // default position is current position - going to then move it 
  fence6.position.y =200;
  fence6.position.z = 200;
  threeworld.scene.add(fence6); paintThis (fence6,7);
  count++;
  updateStatusAfter();
    fence7.position.x = 1400;     // default position is current position - going to then move it 
  fence7.position.y =200;
  fence7.position.z = 1200;
  threeworld.scene.add(fence7); paintThis (fence7,7);
  count++;
  updateStatusAfter();
  
}


function starterFence4(){
    var shape1 = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var fence1 = new THREE.Mesh( shape1 );
  	var fence2 = new THREE.Mesh( shape1 );
  	var fence3 = new THREE.Mesh( shape1 );
  	var fence4 = new THREE.Mesh( shape1 );
  	var fence5 = new THREE.Mesh( shape1 );
  	var fence6 = new THREE.Mesh( shape1 );
  	var fence7 = new THREE.Mesh( shape1 );
  fence1.position.x = 200;     // default position is current position - going to then move it 
  fence1.position.y =200;
  fence1.position.z = 1200;
  threeworld.scene.add(fence1); paintThis (fence1,7);
  count++;
  updateStatusAfter();
  fence2.position.x = 200;     // default position is current position - going to then move it 
  fence2.position.y =200;
  fence2.position.z = 1000;
  threeworld.scene.add(fence2); paintThis (fence2,7);
  count++;
  updateStatusAfter();
    fence3.position.x = 200;     // default position is current position - going to then move it 
  fence3.position.y =200;
  fence3.position.z = 800;
  threeworld.scene.add(fence3); paintThis (fence3,7);
  count++;
  updateStatusAfter();
    fence4.position.x = 200;     // default position is current position - going to then move it 
  fence4.position.y =200;
  fence4.position.z = 600;
  threeworld.scene.add(fence4); paintThis (fence4,7);
  count++;
  updateStatusAfter();
    fence5.position.x = 200;     // default position is current position - going to then move it 
  fence5.position.y =200;
  fence5.position.z = 400;
  threeworld.scene.add(fence5); paintThis (fence5,7);
  count++;
  updateStatusAfter();
    fence6.position.x = 200;     // default position is current position - going to then move it 
  fence6.position.y =200;
  fence6.position.z = 200;
  threeworld.scene.add(fence6); paintThis (fence6,7);
  count++;
  updateStatusAfter();
    fence7.position.x = 200;     // default position is current position - going to then move it 
  fence7.position.y =200;
  fence7.position.z = 1200;
  threeworld.scene.add(fence7); paintThis (fence7,7);
  count++;
  updateStatusAfter();
  
}



var r = 0;
//this function handles user inputs
  function handleKeyDown (event)
  {
        var tmp = 0;
   	    var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
  	var theobject  = new THREE.Mesh( shape );
    
  theobject.position.x = x;     // default position is current position - going to then move it 
  theobject.position.y = y;
  theobject.position.z = z;
 var tree  = theobject;
       var tree1  = new THREE.Mesh( shape );
       var tree2  = new THREE.Mesh( shape );
       
  var code = event.keyCode;
  if (code == 37) { theobject.position.x = x - objectsize;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg'); audio1.play();}// left
  if (code == 39) { theobject.position.x = x + objectsize ;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg');audio1.play(); }  // right
 
  if (code == 38) {theobject.position.z = z - objectsize ;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg'); audio1.play();}  // forward
  if (code == 40) {theobject.position.z = z + objectsize ;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg'); audio1.play();}  // back 
  
  if (code == 34){ theobject.position.y = y - objectsize ;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg'); audio1.play();} 
  if (code == 33) {theobject.position.y = y + objectsize ;var audio1 = new Audio('/uploads/2tczkf6z/grass1.ogg'); audio1.play();}
  if (code == 49)  {theobject.position.x = x  ; threeworld.scene.add(theobject); paintThis (theobject,r);} // left
  if (code == 80) {drawPig();var audio1 = new Audio('/uploads/2tczkf6z/pigsquealanimals024.wav'); audio1.play(); }///if enter p create a pig
  if (code == 83) {drawSheep();var audio1 = new Audio('/uploads/2tczkf6z/sheep-eweanimals112.wav'); audio1.play();} //if enter s create a sheep
  if (code == 67) {drawCow();   var audio1 = new Audio('/uploads/2tczkf6z/cowanimals055.wav'); audio1.play();} //if enter c draw a cow
  if (code === 70) drawFence();
  if (code === 71) drawGrass();
  if (code == 87) {drawStone();var audio1 = new Audio('/uploads/2tczkf6z/stone3.ogg'); audio1.play(); }///if enter w create stone
    if (code == 84){//creates a tree if t
    
             
          tree.position.y = y + (200)  ; threeworld.scene.add(tree); paintThis (tree,2);
          count++;
          sleep(1000);
          well();
          function well(){
        
        
        tree1.position.y = y + (400)  ;tree1.position.x = x  ;tree1.position.z = z  ;  threeworld.scene.add(tree1); paintThis (tree1,2); 
        count++;
        tree2.position.y = y + (600)  ;tree2.position.x = x  ;tree2.position.z = z  ;  threeworld.scene.add(tree2); paintThis (tree2,2);
        count++; updateStatusAfter();
          }
theobject.posistion.y = y -1500;
    }

  x = theobject.position.x;     // current position is now this 
  y = theobject.position.y;
  z = theobject.position.z;
 if (code == 55 ){threeworld.scene.add(theobject);  paintRemove (theobject,0xFFFFFF);}//delete an element
 if (code == 32 && count >= 100){
     drawCastle();
          
           
 }

 
      
   
  
 
 //threeworld.lookat.copy ( theobject.position );	
        

      
      // sound effect credit:
      // http://soundbible.com/1399-Chambering-A-Round.html
        var audio = new Audio('/uploads/starter/chamber.mp3');
       // audio.play();
       
        if(count >= 100){
     updateNewObject();
 }
     
       
 }
  



function paintThis(object,x )        // paint objects with random textures 
{
      //  var t = randomintAtoB ( 0, textureArray.length - 1 );     // random texture 
    
        object.material =  new THREE.MeshBasicMaterial ( { map: textureArray[x] } );   
}

function paintRemove(object, x){
    object.material = new THREE.MeshBasicMaterial (  x);
}
	

function updateStatusAfter(){

	    var status = "&nbsp;score" + count;
	    $("#user_span5").html(status);
	    
	    
	}
	
function updateNewObject(){
     var status = "&nbsp;You have unlocked a new item....press space to recieve!(look at the centre of your map!)";
	    $("#user_span5").html(status);
    if (count === 100){
	   
	    var audio = new Audio('/uploads/2tczkf6z/john_wesley_coleman_-_07_-_tequila_10_seconds.mp3');
        audio.play();
        
    }
    
	}



	this.endCondition;	



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

  threeworld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  ); 

 var s = "<center> <h2> User controlled. Use arrow keys and PgUp, PgDn to move. Use 7 to delete boxes! Use t,1,p,w,s,g,c,f to draw different objects. Score increases when draw animals or trees(+3). When score >= 100 press SPACE to recieve new unlock! </h2> </center>";
 	$("#user_span2").html( s );
 	         
//these functions are called as I want them to appear at the beggining of the game
 	  init();
 	  
 	  starterTree();
 	 starterCow();
    starterGrass();
    starterFence1();
    starterFence2();
    starterFence3();
    starterFence4();
   starterPig();
   starterSheep();
   
   
 
 document.addEventListener( 'keydown', handleKeyDown   );

 
updateStatusAfter();
};



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


this.nextStep = function()		 
{
 var a = 4;


    
};


this.endRun = function()
{
   updateStatusAfter();
};


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

}