Lesson 5: The Challenge

Now that you're familiar with feature flags, we have a take-home challenge for you: make Toggle Runner feel more like a space game.

You've learned that the following code starts the game:

// js/app.js
  const runner = new Runner('.interstitial-wrapper', config);

After the game starts, runner objects provide a method to change the game configuration dynamically while it runs. You do not need to paste this into your code, but here is an example runner object:

// Example: This method call will change the gravity of the game after it has started
runner.updateConfigSetting('GRAVITY', 0.3)

You can add a function to call which adds more "space-like" features:

// js/app.js
// Paste this after the closing `}` of the `drawGame` function
function setSpaceMode(runner, isSpaceMode) {
  console.log('Space mode enabled:', isSpaceMode);
  if (isSpaceMode) {
    runner.updateConfigSetting('GRAVITY', 0.3)
    runner.updateConfigSetting('INVERT_DISTANCE', 0)
    runner.updateConfigSetting('INVERT_FADE_DURATION', 1000)
    runner.updateConfigSetting('MAX_CLOUDS', 1)
    runner.updateConfigSetting('MAX_OBSTACLE_LENGTH', 6)
    runner.updateConfigSetting('GAP_COEFFICIENT', 5)
  } else {
    runner.updateConfigSetting('GRAVITY', config.GRAVITY)
    runner.updateConfigSetting('INVERT_DISTANCE', config.INVERT_DISTANCE)
    runner.updateConfigSetting(
      'INVERT_FADE_DURATION',
      config.INVERT_FADE_DURATION
    )
    runner.updateConfigSetting('MAX_CLOUDS', config.MAX_CLOUDS)
    runner.updateConfigSetting('MAX_OBSTACLE_LENGTH', config.MAX_OBSTACLE_LENGTH)
    runner.updateConfigSetting('GAP_COEFFICIENT', config.GAP_COEFFICIENT)
  }
}

Your challenge is to figure out how call this function when the space-mode flag is turned on. Good luck!