/*
 * Game state
 * ============================================================================
 *
 * This is where the real action takes place!
 */


import RotatingLogo from '../objects/RotatingLogo';


class Game extends Phaser.State {

  init (level) {
    // You can pass as many arguments as needed to a state prior to its
    // initialization. This is good if you have to transport information
    // between states that will affect the overall game behaviour...

    // In this example, we are taking the level of the game we'll initialize.

    // Remember that Phaser's StateManager API requires you to pass two more
    // optional arguments.

    // `this.state.start(stateName, true, false, ...)`
    this.level = level;
  }

  create () {
    // Below follows a little ES6 snippet, to show you not just classes and
    // modules are supported. Object destructured assignment: here, we're
    // taking out two properties of `this.world`, and aliasing them to two new
    // variables, `x` and `y`.

    // Besides it being a feature you shouldn't be abusing too much, this one
    // can become quite handy sometimes, specially when destructuring objects
    // in function parameters.
    var { centerX: x, centerY: y } = this.world;

    // The rotating logo.
    this.rotatingLogo = this.add.existing(this.makeRotatingLogo(x, y));

    // Place the rotating logo wherever the user clicks/touches the game
    // canvas.
    this.input.onUp.add(this.placeLogo, this);
  }

  update () {
    // See, this is just a demonstration game, so we have nothing much to do
    // here. Now, it's your time to create an awesome game!
  }

  makeRotatingLogo (x, y, speed = 4000) {
    return new RotatingLogo(this.game, x, y, speed);
  }

  placeLogo ({ x, y }) {
    // This method uses object destructuring right in the parameters, so we can
    // take only the object properties we are interested in.
    this.rotatingLogo.reset(x, y);
  }

}


export default Game;

@@ -1484,467 +1484,1475 @@
 s);%0A
-  %7D%0A%0A  update () %7B%0A    // See, this is just a demonstration game, so we have nothing much to do%0A    // here. Now, it's your time to create an awesome game!%0A  %7D%0A%0A  makeRotatingLogo (x, y, speed = 4000) %7B%0A    return new RotatingLogo(this.game, x, y, speed);%0A  %7D%0A%0A  placeLogo (%7B x, y %7D) %7B%0A    // This method uses object destructuring right in the parameters, so we can%0A    // take only the object properties we are interested in.%0A    this.rotatingLogo.reset(x, y
+%0A    this.add.existing(this.makeBackButton(48, 48));%0A%0A    // For demonstration purposes, every 3s a new level will be unlocked.%0A    this.time.events.add(3000, this.unlockNextLevel, this);%0A  %7D%0A%0A  update () %7B%0A    // See, this is just a demonstration game, so we have nothing much to do%0A    // here. Now, it's your time to create an awesome game!%0A  %7D%0A%0A  // --------------------------------------------------------------------------%0A%0A  makeButton (x, y, face, callback = null) %7B%0A    let button = this.make.button(%0A      x, y, 'buttons', callback, this, face, face);%0A%0A    button.anchor.set(0.5);%0A    button.input.useHandCursor = true;%0A%0A    return button;%0A  %7D%0A%0A  makeBackButton (x, y) %7B%0A    return this.makeButton(x, y, 'button-back', this.showLevelSelection);%0A  %7D%0A%0A  makeRotatingLogo (x, y, speed = 4000) %7B%0A    return new RotatingLogo(this.game, x, y, speed);%0A  %7D%0A%0A  placeLogo (%7B x, y %7D) %7B%0A    // This method uses object destructuring right in the parameters, so we can%0A    // take only the object properties we are interested in.%0A    this.rotatingLogo.reset(x, y);%0A  %7D%0A%0A  showLevelSelection () %7B%0A    this.state.start('Levels');%0A  %7D%0A%0A  unlockNextLevel () %7B%0A    if (this.level %3C 5) %7B%0A      this.game.settings.lastLevel = this.level + 1;%0A%0A      this.game.storage.setItem(%0A        'settings', this.game.settings.data, this.nextLevelUnlocked, this);%0A    %7D%0A  %7D%0A%0A  nextLevelUnlocked (err, data) %7B%0A    if (!err)%0A      console.log('Unlocking game level number #%25d', data.lastLevel
 );%0A 

Make Game state unlock levels.