js/render.js
// Initialize everything needed to start displaying the WebGL scene in-browser
Initialize everything needed to start displaying the WebGL scene in-browser
Initialize everything needed to start displaying the WebGL scene in - browser
function initRenderer() {
  renderer = new THREE.WebGLRenderer({canvas: $('#gameCanvas')[0], antialias: true});
  let clearColor = 0xd0e0e0 
  renderer.setClearColor(clearColor);
  renderer.setPixelRatio(window.devicePixelRatio);
  let width = window.innerWidth;
  let height = window.innerHeight;
  renderer.setSize(width, height);
  camera2d = new THREE.OrthographicCamera(width/-2, width/2, height/2, height/-2, NEAR, FAR);
  camera3d = new THREE.PerspectiveCamera(35, width/height, NEAR, FAR);
  controls = new THREE.OrbitControls(camera3d, renderer.domElement);
  if (flat) {
    camera = camera2d;
    controls.enabled = false;
  }
  else {
    camera = camera3d;
    controls.enabled = true;
  }
  let listener = new THREE.AudioListener();
  camera2d.add(listener);
  sound = new THREE.Audio(listener);
  let audioLoader = new THREE.AudioLoader();
  audioLoader.load( 'sounds/onmyway.mp3', function( buffer ) {
  	sound.setBuffer( buffer );
  	sound.setLoop( true );
  	sound.setVolume( 0.5 );
  });
  let listenerHit = new THREE.AudioListener();
  camera2d.add(listenerHit);
  soundHit = new THREE.Audio(listenerHit);
  let audioLoaderHit = new THREE.AudioLoader();
  audioLoaderHit.load( 'sounds/blaster.wav', function( buffer ) {
    soundHit.setBuffer( buffer );
    soundHit.setLoop( false );
    soundHit.setVolume( 0.8 );
  });
  controls.minDistance = 1000;
  controls.maxDistance = 1000;
  controls.maxAzimuthAngle = Math.PI / 8;
  controls.minAzimuthAngle = -Math.PI / 8;
  controls.maxPolarAngle = 5 * Math.PI / 8;
  controls.minPolarAngle = 3 * Math.PI / 8;
  controls.enabled = false;
  controls.screenSpacePanning = true;
  controls.saveState();
  scene = new THREE.Scene();
  floor = {};
  let inf = 100000;
  floor.geometry = new THREE.PlaneGeometry(inf, inf);
  floor.material = new THREE.MeshPhongMaterial(0x443344);
  let texture = new THREE.TextureLoader().load( "textures/granite.jpg" );
  texture.wrapS = THREE.RepeatWrapping;
  texture.wrapT = THREE.RepeatWrapping;
  let imgSize = 500;
  let n = inf / imgSize;
  texture.repeat.set( n,n );
  floor.material.map = texture;
  floor.mesh     = new THREE.Mesh(floor.geometry, floor.material);
  floor.mesh.position.set(0,0,-2000);
  scene.add(ambientWhite);
  activeLights[ambientWhite.uuid] = ambientWhite;
  initEntities();
  initParticles();
  initWalls();
  initObjectives();
  let geometry1 = new THREE.PlaneGeometry(300, 300, 1, 1);
  let material1 = new THREE.MeshPhongMaterial({color: 0x447777});
  let mesh1 = new THREE.Mesh(geometry1, material1);
  mesh1.position.set(0,0,-1100);
  updateColors();
  requestAnimationFrame(render);
}
function initRenderer ( ) { renderer = new THREE . WebGLRenderer ( { canvas : $ ( '#gameCanvas' ) [ 0 ] , antialias : true } ) ; let clearColor = 0xd0e0e0 renderer . setClearColor ( clearColor ) ; renderer . setPixelRatio ( window . devicePixelRatio ) ; let width = window . innerWidth ; let height = window . innerHeight ; renderer . setSize ( width , height ) ; camera2d = new THREE . OrthographicCamera ( width / - 2 , width / 2 , height / 2 , height / - 2 , NEAR , FAR ) ; camera3d = new THREE . PerspectiveCamera ( 35 , width / height , NEAR , FAR ) ; controls = new THREE . OrbitControls ( camera3d , renderer . domElement ) ; if ( flat ) { camera = camera2d ; controls . enabled = false ; } else { camera = camera3d ; controls . enabled = true ; } let listener = new THREE . AudioListener ( ) ; camera2d . add ( listener ) ; sound = new THREE . Audio ( listener ) ; let audioLoader = new THREE . AudioLoader ( ) ; audioLoader . load ( 'sounds/onmyway.mp3' , function ( buffer ) { sound . setBuffer ( buffer ) ; sound . setLoop ( true ) ; sound . setVolume ( 0.5 ) ; } ) ; let listenerHit = new THREE . AudioListener ( ) ; camera2d . add ( listenerHit ) ; soundHit = new THREE . Audio ( listenerHit ) ; let audioLoaderHit = new THREE . AudioLoader ( ) ; audioLoaderHit . load ( 'sounds/blaster.wav' , function ( buffer ) { soundHit . setBuffer ( buffer ) ; soundHit . setLoop ( false ) ; soundHit . setVolume ( 0.8 ) ; } ) ; controls . minDistance = 1000 ; controls . maxDistance = 1000 ; controls . maxAzimuthAngle = Math . PI / 8 ; controls . minAzimuthAngle = - Math . PI / 8 ; controls . maxPolarAngle = 5 * Math . PI / 8 ; controls . minPolarAngle = 3 * Math . PI / 8 ; controls . enabled = false ; controls . screenSpacePanning = true ; controls . saveState ( ) ; scene = new THREE . Scene ( ) ; floor = { } ; let inf = 100000 ; floor . geometry = new THREE . PlaneGeometry ( inf , inf ) ; floor . material = new THREE . MeshPhongMaterial ( 0x443344 ) ; let texture = new THREE . TextureLoader ( ) . load ( "textures/granite.jpg" ) ; texture . wrapS = THREE . RepeatWrapping ; texture . wrapT = THREE . RepeatWrapping ; let imgSize = 500 ; let n = inf / imgSize ; texture . repeat . set ( n , n ) ; floor . material . map = texture ; floor . mesh = new THREE . Mesh ( floor . geometry , floor . material ) ; floor . mesh . position . set ( 0 , 0 , - 2000 ) ; scene . add ( ambientWhite ) ; activeLights [ ambientWhite . uuid ] = ambientWhite ; initEntities ( ) ; initParticles ( ) ; initWalls ( ) ; initObjectives ( ) ; let geometry1 = new THREE . PlaneGeometry ( 300 , 300 , 1 , 1 ) ; let material1 = new THREE . MeshPhongMaterial ( { color : 0x447777 } ) ; let mesh1 = new THREE . Mesh ( geometry1 , material1 ) ; mesh1 . position . set ( 0 , 0 , - 1100 ) ; updateColors ( ) ; requestAnimationFrame ( render ) ; }
Initialize everything needed to start displaying the WebGL scene in-browser
Initialize everything needed to start displaying the WebGL scene in - browser
// Initialize the WebGL renderer // 0xa5b6b6; // Initialize the cameras // sound.play(); // sound.play(); //fog = new THREE.Fog(0xFFFFFF, 200, 2000); //scene.fog = fog; // BUild an "infinite" floor // scene.add(floor.mesh); // Add lights (playing with these leads to super cool effects) // ==================== SET UP THE SCENE =========================== // Add the player, enemies, particles, walls, objectives... // The testing "floor" square in the center -- does nothing so far // scene.add(mesh1); // ================================================================== // Disable colors that aren't yet unlocked