

class AboutPanel extends Phaser.Scene {
  constructor() {
    super({ key: 'AboutPanel', active: false });
  }

  create() {
    this.background = this.add.tileSprite(0, 0, config.width, config.height, "background");
    this.background.setOrigin(0, 0);

    let aboutText = `
Scoring:

Destroy Meteor
1 point

Complete Answer
5 points

Meteor off the bottom
-1 point

BONUSES:

Dual Laser
+1 point

EXCELLENT
(No meteors off the bottom)
+10 points

FLAWLESS
(No missed words)
+25 points

STAR (multiplier)
Double Points`;


    let aboutBitmap = this.add.bitmapText(config.width/2,config.height/2,'kenvector_thin', aboutText, 25).setOrigin(0.5).setTint(0xffff00, 0xffff00,0x6666ff, 0x6666ff);

    aboutBitmap.setInteractive();
    aboutBitmap.on("pointerup", function() {
      this.scene.stop('AboutPanel');
    }, this);


  }

  update(time, delta) {
    this.background.tilePositionY -= 1.5;
  }
}


class Scene1 extends Phaser.Scene {
  constructor() {
    super("bootGame");
  }

  preload() {
    this.load.image("background", "assets/Backgrounds/darkPurple.png");
    this.load.image("meteorBrown_big1", "assets/PNG/Meteors/meteorBrown_big1.png");
    this.load.image("meteorBrown_big2", "assets/PNG/Meteors/meteorBrown_big2.png");
    this.load.image("meteorBrown_big3", "assets/PNG/Meteors/meteorBrown_big3.png");
    this.load.image("meteorBrown_big4", "assets/PNG/Meteors/meteorBrown_big4.png");
    this.load.image("meteorBrown_med1", "assets/PNG/Meteors/meteorBrown_med1.png");
    this.load.image("meteorGrey_big1", "assets/PNG/Meteors/meteorGrey_big1.png");
    this.load.image("meteorGrey_big2", "assets/PNG/Meteors/meteorGrey_big2.png");
    this.load.image("meteorGrey_big3", "assets/PNG/Meteors/meteorGrey_big3.png");
    this.load.image("meteorGrey_big4", "assets/PNG/Meteors/meteorGrey_big4.png");
    this.load.image("meteorGrey_med1", "assets/PNG/Meteors/meteorGrey_med1.png");
    this.load.image("spark_red", "assets/PNG/Effects/red.png");
    this.load.image("spark_blue", "assets/PNG/Effects/blue.png");
    this.load.image("spark_orange", "assets/PNG/Meteors/spark_orange.png");
    this.load.image("powerupBlue_bolt", "assets/PNG/Power-ups/powerupBlue_bolt.png");
    this.load.image("powerupGreen_bolt", "assets/PNG/Power-ups/powerupGreen_bolt.png");
    this.load.image("powerupBlue_star", "assets/PNG/Power-ups/powerupBlue_star.png");
    this.load.image("powerupBlue_star", "assets/PNG/Power-ups/powerupGreen_star.png");
    this.load.image("star_silver", "assets/PNG/Power-ups/star_silver.png");

    this.load.image("enemyRed1", "assets/PNG/Enemies/enemyRed1.png");

    //this.load.image("spark_red", "assets/PNG/Meteors/spark_red.png");
    this.load.image("spark_green", "assets/PNG/Meteors/spark_green.png");
    this.load.image("spark_yellow", "assets/PNG/Meteors/spark_yellow.png");
    this.load.image("laserBlue01", "assets/PNG/Lasers/laserBlue01.png");
    this.load.image("playerShip1_blue", "assets/PNG/playerShip1_blue.png");
    this.load.spritesheet("explosionSmoke", "assets/PNG/Effects/explosionSmokeSprite.png", {
      frameWidth: 64,
      frameHeight: 64
    });

    this.load.bitmapFont('atari', 'assets/fonts/atari-smooth.png', 'assets/fonts/atari-smooth.xml');
    this.load.bitmapFont('kenvector_thin', 'assets/fonts/kenvector_thin_0.png', 'assets/fonts/kenvector_thin.fnt');
    this.load.bitmapFont('kenvector', 'assets/fonts/kenvector_0.png', 'assets/fonts/kenvector.fnt');
  }

  addMenuItem(text, offset, num) {
    let menuItem = this.add.bitmapText(config.width / 2, config.height / 2 + offset, 'kenvector', text + this.formatHighScore(num), 28);
    menuItem.setOrigin(0.5);
    menuItem.setInteractive();
    menuItem.on("pointerup", function() {
      if (num != 0) {
        // remove any previously saved state.
        localStorage.removeItem('saveRecord');
      }
      config.questionSet = num;
      this.scene.start("playGame");
    }, this);

    return menuItem;
  }

  formatHighScore(questionSet) {
    if (questionSet < 1 || questionSet > 7) {
      return '';
    }
    var highScore = parseInt(localStorage.getItem('high_score_' + questionSet + '_' + 0)) || 0;
    var highScoreName = localStorage.getItem('high_score_name_' + questionSet + '_' + 0) || 'AAA';

    return '(' + highScoreName + ' ' + highScore + ')';
  }

  create() {
    this.background = this.add.tileSprite(0, 0, config.width, config.height, "background");
    this.background.setOrigin(0, 0);

    this.add.bitmapText(config.width-40,config.height - 20,'kenvector_thin', "Version: 0.014", 18).setOrigin(1,1);

    this.add.bitmapText(config.width / 2, config.height * 0.25, 'kenvector', 'Catechism Game!', 64).setOrigin(0.5).setTint(0xffff00, 0xffff00,0x6666ff, 0x6666ff);

    // if there is a saved game in local storage then show the menu item for resuming it.
    if (localStorage.getItem('saveRecord') != null) {
      this.addMenuItem('Resume Unfinished Game', -80, 0).setTint(0xff00ff);
    }

    this.addMenuItem('Part 1: God, man, and sin ', 0, 1);
    this.addMenuItem('Part 2: Salvation ', 50, 2);
    this.addMenuItem('Part 3: Ten Commandments ', 100, 3);
    this.addMenuItem('Part 4: Prayer ', 150, 4);
    this.addMenuItem('Part 5: The Church ', 200, 5);
    this.addMenuItem('Part 6: Last Things ', 250, 6);
    this.addMenuItem('Test ', 300, 7).setTint(0xffff00);

    this.modeText = this.add.bitmapText(config.width - 200, config.height*0.35, 'kenvector', 'Joshy Mode OFF', 20).setTint(0xffff00);
    this.modeText.setOrigin(0.5);
    this.modeText.setInteractive();
    this.modeText.on("pointerup", function() {
      if (config.mode != MODE.JOSHY) {
      config.mode = MODE.JOSHY;
      this.modeText.setText('Joshy Mode ON');
    } else {
      config.mode = MODE.EASY;
      this.modeText.setText('Joshy Mode OFF');
    }

    }, this);

    /*
    this.fullscrText = this.add.bitmapText(config.width - 200, config.height*0.40, 'kenvector', 'FULLSCREEN OFF', 20).setTint(0xffff00);
    this.fullscrText.setOrigin(0.5);
    this.fullscrText.setInteractive();
    this.fullscrText.on("pointerup", function() {
      if (this.scale.isFullscreen) {
        this.scale.stopFullscreen();
        this.fullscrText.setText('FULLSCREEN OFF');
        // On stop fulll screen
      } else {
          this.scale.startFullscreen();
          this.fullscrText.setText('FULLSCREEN ON');
          // On start fulll screen
      }
    }, this);
    */

    this.aboutText = this.add.bitmapText(config.width - 200, config.height*0.40, 'kenvector', 'RULES & STUFF', 20).setTint(0x00ffcc);
    this.aboutText.setOrigin(0.5);
    this.aboutText.setInteractive();
    this.aboutText.on("pointerup", function() {
      this.scene.launch('AboutPanel');
    }, this);


  }

  update(time, delta) {
    this.background.tilePositionY -= 1.5;
  }


}
