js/render.js
// Handle when keys are pushed and released
Handle when keys are pushed and released
Handle when keys are pushed and released
function handleKeypress(event) {
  let key = event.key;
  let action = KEY_BINDINGS[key];
  if (!action || !INSTANT_ACTIONS.includes(action.type)) return;
  if (action.type == SHIFT) {
    shiftCamera();
  }
  else if (action.type == ADD_LIGHT) {
    let uuid = action.light.uuid;
    if (activeLights[uuid]) return;
    scene.add(action.light);
    activeLights[uuid] = action.light;
    normalizeLights();
  }
  else if (action.type == REM_LIGHT) {
    let uuid = action.light.uuid;
    if (!activeLights[uuid]) return;
    scene.remove(action.light);
    delete activeLights[uuid];
    normalizeLights();
  }
  else if (action.type == UNLOCK_ALL) {
    unlockAllObjectives();
  }
  else if (action.type == GODMODE) {
    player.canDie = false;
    player.canMove = true;
  }
  else if (action.type == LOCK_ALL) {
    for (let x in objectives) {
      objectives[x]=false;
    }
  }
  else if (action.type == UNLOCK_NEXT) {
    player.healFor(100);
    for (let x in objectives) {
      if (!objectives[x]) {
        objectives[x] = true;
        if (x == "sounds") {
          sound.play();
        }
        if (x == "galaxy") {
          addGalaxyFloor();
        }
        else if (x == "perspective") {
          shiftCamera();
        }
        else if (x == "flatLight") {
          scene.add(pointWhite);
          ambientWhite.intensity = 0.8;
        }
        else if (x == "playerLight") {
          player.addLight();
          showInvisibleWalls();
        }
        else if (x == "coolParticles") {
          options.lifetime = 4;
        }
        return;
      }
    }
  }
  else if(action.type == SCREENSHOT ){
    takeScreenshot();
  }
}
function handleKeypress ( event ) { let key = event . key ; let action = KEY_BINDINGS [ key ] ; if ( ! action || ! INSTANT_ACTIONS . includes ( action . type ) ) return ; if ( action . type == SHIFT ) { shiftCamera ( ) ; } else if ( action . type == ADD_LIGHT ) { let uuid = action . light . uuid ; if ( activeLights [ uuid ] ) return ; scene . add ( action . light ) ; activeLights [ uuid ] = action . light ; normalizeLights ( ) ; } else if ( action . type == REM_LIGHT ) { let uuid = action . light . uuid ; if ( ! activeLights [ uuid ] ) return ; scene . remove ( action . light ) ; delete activeLights [ uuid ] ; normalizeLights ( ) ; } else if ( action . type == UNLOCK_ALL ) { unlockAllObjectives ( ) ; } else if ( action . type == GODMODE ) { player . canDie = false ; player . canMove = true ; } else if ( action . type == LOCK_ALL ) { for ( let x in objectives ) { objectives [ x ] = false ; } } else if ( action . type == UNLOCK_NEXT ) { player . healFor ( 100 ) ; for ( let x in objectives ) { if ( ! objectives [ x ] ) { objectives [ x ] = true ; if ( x == "sounds" ) { sound . play ( ) ; } if ( x == "galaxy" ) { addGalaxyFloor ( ) ; } else if ( x == "perspective" ) { shiftCamera ( ) ; } else if ( x == "flatLight" ) { scene . add ( pointWhite ) ; ambientWhite . intensity = 0.8 ; } else if ( x == "playerLight" ) { player . addLight ( ) ; showInvisibleWalls ( ) ; } else if ( x == "coolParticles" ) { options . lifetime = 4 ; } return ; } } } else if ( action . type == SCREENSHOT ) { takeScreenshot ( ) ; } }
Handle when keys are pushed and released
Handle when keys are pushed and released
// Only consider keys that have movement actions bound to them. // Change the camera perspective // Do nothing if light already in scene // Normalize lights to have intensity 1 // Do nothing if light not already in scene // Normalize lights to have intensity 1 // for demoing