Code viewer for World: Run (clone by Lorcan Dunne)
function World() 
{ 
    
    
    //config
    var pointsToWin = 11;
    
    //
    var cam;
    var meshFloor;
    var food_list = [];
    var keyboard = {};
    var distance;
    var updatedPosX;
    var updatedPosZ;
    var egg = [];
    var hasEgg = false;
    var play;
    var player_base;
    var ai_base;
    var AiFoodCount = 0;
    var playerFoodCount=0;
    var pspan;
    var pspan2;
    var Aspan;
    var Aspan1;
    var birdsView = false;
    var disFood;
    var botEgg = false;
    var eggSpawned = false;
    var playerEgg = false;
    var eggTimer = 10000;
    var aiCaptures = 1;
    var playerCaptures = 1;
    //Ai vars
    //camera
    //player

    var botSpeed = 0.3;
    var update_speed = 0.2;//
    var player = { height:2, speed:0.3, turnSpeed:0.09}; //to get player position get cam position

    
    var scene = new THREE.Scene(); //CREATE SCENE
    var sky_texture = new THREE.TextureLoader().load( 'uploads/tuitef2/skyyy.png' );
    scene.background = sky_texture;
    
    var renderer = new THREE.WebGLRenderer();
    function render(){
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
    }
    
    function camera(){
        cam = new THREE.PerspectiveCamera(90, window.innerWidth/window.innerHeight, 0.1, 1000);
        cam.position.set(0, 3.5, -160); //position.x,position.y,position.z
        cam.lookAt(scene.position);
    }
    
    function create_player(){

        var geometry = new THREE.BoxGeometry( 1, 1, 1 );
        var material = new THREE.MeshBasicMaterial( {color: "#c91092"} );
        play = new THREE.Mesh( geometry, material );
        play.scale.multiplyScalar(2);
        play.position.set(0,player.height,-160);
        scene.add(play);
    }
    var ai;
     function createMind(){
        var geometry = new THREE.BoxGeometry( 1, 1, 1 );
        var material = new THREE.MeshBasicMaterial( {color: "blue"} );
        ai = new THREE.Mesh( geometry, material );
        ai.position.set(0,2,160);
        ai.scale.multiplyScalar(2);
        scene.add( ai );
     }
     
    ////// CAMERA STUFFS 
        function hud(event){
        pspan = document.getElementById("user_span1");
        pspan2 = document.getElementById("user_span2");
        pspan.innerHTML = "<br>Player food count: ";
        
        pspan.style.fontSize = '20px';
        pspan2.style.fontSize = '20px';
        
        Aspan1 = document.getElementById("user_span3");
        Aspan = document.getElementById("user_span4");
        Aspan1.innerHTML = "  AI food count: ";
        
        Aspan1.style.padding = '5px';
        Aspan1.style.fontSize = '20px';
        Aspan.style.fontSize = '20px';
        
        eggPlayer = document.getElementById("user_span5");
        eggPlayer.innerHTML = "<br><br>Player Egg Count:";
        eggPlayer1 = document.getElementById("user_span6");
        
        eggAi = document.getElementById("user_span7");
        eggAi.innerHTML = "AI Egg Count:";
        eggAi1 = document.getElementById("user_span8");
        
        eggPlayer.style.fontSize = 20;
        eggAi.style.fontSize = 20;
        
        let span = document.getElementById('api_span1');
        let span1 = document.getElementById('api_span2');
        var button = document.createElement("button");
        var button2 = document.createElement("button");
        let run = document.getElementById('w2m_runcontrols');
        run.innerHTML = "";
        
        span.innerHTML = 'Change view: ';

        button.style.background= '#ed8c0e';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.cursor = 'pointer';
        button.style.borderRadius = '3px';
        button.style.fontSize = '18';
        button.style.padding = '5px';
        
        
        button2.style.background = '#4CAF50';
        button2.style.color = 'white';
        button2.style.fontSize = '18';
        button2.style.border = 'none';
        button2.style.cursor = 'pointer';
        button2.style.borderRadius = '3px';
        button2.style.padding = '5px';
        
        
        button.innerHTML = "Third Person";
        button2.innerHTML = "Birds Eye";
        
        span.appendChild(button);
        span1.appendChild(button2);
        
        button.addEventListener("click", camView1);
        button2.addEventListener("click", camView2);
    }
    
    function camView1(){
        birdsView = false;
        cam.position.x = play.position.x ;
        cam.position.z = play.position.z -5;
        cam.position.y = 3.5;
        cam.rotation.y = 0;
        cam.rotation.z = -3.141592653589793;
        cam.rotation.x = -3.1197211417647925;
        play.rotation.x= 0;
        play.rotation.y= 0;
        play.rotation.z = 0;
    }
    function camView2(){
        birdsView = true;
        cam.position.x = play.position.x;
        cam.position.z = play.position.z + 20;
        cam.position.y = 60;
        cam.rotation.y = 0;
        cam.rotation.z = -3.141592653589793;
        cam.rotation.x = 29.5;
        play.rotation.x= 0;
        play.rotation.y= 0;
        play.rotation.z = 0;
        
    }
    
    function ground(){
        var texture = new THREE.TextureLoader().load( 'uploads/tuitef2/ground_texture1.png' );
        
        texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
        texture.offset.set( 0, 0 );
        texture.repeat.set( 2, 2 );
        
        // immediately use the texture for material creation
        meshFloor = new THREE.Mesh(
        new THREE.PlaneGeometry(400,400),
        new THREE.MeshBasicMaterial({map:texture}));
        
        meshFloor.rotation.x -= Math.PI / 2; // Rotate the plane 90 degrees as if you don't do this it'll be like a tv screen.
        scene.add(meshFloor);
    }
    
    function beginGame(){
        AB.removeSplash();
        movement();
        food_color();
    }
    
    this.newRun = function()
	{   
	    splash();
		render();
		create_player();
        camera();
        hud();
        ground();
        base();
        createMind();
        food();
        eat_food();
        place_structure();
        hide_egg();
        eat_foodAI();
        //eat_eggAi();
        //eat_egg(); 
        place_trees();
        
        for(i=-180;i<180;i++){
            if(i%22===0){
                tree_border(i);
            }
        }
        AB.showRunHeader(); 
        endRun();
    };
    function endRun(){
        if (playerCaptures === pointsToWin){
            winner();
        }
        else if(aiCaptures === pointsToWin){
            loser();
        }
    }
    
}