<commit_before>/* globals __DEV__ */
import Phaser from 'phaser';
import Ship from '../sprites/Ship';

// This is where all the game play code goes.
class Play extends Phaser.State {
    init() {
        // set game config variable data from game cache
        this.Config = this.game.cache.getJSON('config');

        this.Config.gameProperties.screenWidth = this.game.world.width;
        this.Config.gameProperties.screenHeight = this.game.world.height;
        this.Config.shipProperties.startX = this.Config.gameProperties.screenWidth * 0.5;
        this.Config.shipProperties.startY = this.Config.gameProperties.screenHeight * 0.5;
        this.Config.asteroidProperties.asteroidLarge.nextSize = this.Config.graphicAssets.asteroidMedium.name;
        this.Config.asteroidProperties.asteroidMedium.nextSize = this.Config.graphicAssets.asteroidSmall.name;

        this.bulletInterval = 0;
        this.score = 0;
        this.asteroidsCount = this.Config.asteroidProperties.startingAsteroids;

        // start physics system
        this.game.physics.startSystem(Phaser.Physics.ARCADE);
    }
    preload() {}

    create() {
        this.initGraphics();
        this.initSounds();
        this.initPhysics();
        this.initKeyboard();
        this.resetAsteroids();
    }

    initGraphics() {
        this.backgroundSprite = this.game.add.sprite(0, 0, this.Config.graphicAssets.background.name);
        this.backgroundSprite.width = this.Config.gameProperties.screenWidth;
        this.backgroundSprite.height = this.Config.gameProperties.screenHeight;

        this.ship = new Ship({
            game: this.game,
            x: this.game.world.centerX,
            y: this.game.world.centerY,
            asset: this.Config.graphicAssets.shipsheet.name
        });
        this.game.add.existing(this.ship);

        this.bulletGroup = this.game.add.group();
        this.asteroidGroup = this.game.add.group();

        this.tf_lives = this.game.add.text(20, 10, this.ship.lives, this.Config.fontAssets.playFontStyle);

        this.tf_score = this.game.add.text(this.Config.gameProperties.screenWidth - 50, 10, "0", this.Config.fontAssets.playFontStyle);
        this.tf_score.align = 'right';
        this.tf_score.anchor.set(1, 0);

        this.explosionLargeGroup = this.game.add.group();
        this.explosionLargeGroup.createMultiple(20, this.Config.graphicAssets.explosionLarge.name, 0);
        this.explosionLargeGroup.setAll('anchor.x', 0.5);
        this.explosionLargeGroup.setAll('anchor.y', 0.5);
        this.explosionLargeGroup.callAll('animations.add', 'animations', 'explode', null, 30);

        this.explosionMediumGroup = this.game.add.group();
        this.explosionMediumGroup.createMultiple(20, this.Config.graphicAssets.explosionMedium.name, 0);
        this.explosionMediumGroup.setAll('anchor.x', 0.5);
        this.explosionMediumGroup.setAll('anchor.y', 0.5);
        this.explosionMediumGroup.callAll('animations.add', 'animations', 'explode', null, 30);

        this.explosionSmallGroup = this.game.add.group();
        this.explosionSmallGroup.createMultiple(20, this.Config.graphicAssets.explosionSmall.name, 0);
        this.explosionSmallGroup.setAll('anchor.x', 0.5);
        this.explosionSmallGroup.setAll('anchor.y', 0.5);
        this.explosionSmallGroup.callAll('animations.add', 'animations', 'explode', null, 30);
    }

    initSounds() {
        this.sndDestroyed = this.game.add.audio(this.Config.soundAssets.destroyed.name);
        this.sndFire = this.game.add.audio(this.ship.sound.fire);
    }

    initPhysics() {
        this.bulletGroup.enableBody = true;
        this.bulletGroup.physicsBodyType = Phaser.Physics.ARCADE;
        this.bulletGroup.createMultiple(this.Config.bulletProperties.maxCount, this.Config.graphicAssets.bullet.name);
        this.bulletGroup.setAll('anchor.x', 0.5);
        this.bulletGroup.setAll('anchor.y', 0.5);
        this.bulletGroup.setAll('lifespan', this.Config.bulletProperties.lifespan);

        this.asteroidGroup.enableBody = true;
        this.asteroidGroup.physicsBodyType = Phaser.Physics.ARCADE;
    }

    initKeyboard() {
        this.key_left = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
        this.key_right = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
        this.key_thrust = this.game.input.keyboard.addKey(Phaser.Keyboard.UP);
        this.key_fire = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
    }

    checkPlayerInput() {
        if (this.key_left.isDown) {
            this.ship.moveShip('left');
        } else if (this.key_right.isDown) {
            this.ship.moveShip('right');
        } else {
            this.ship.moveShip('stop');
        }

        if (this.key_thrust.isDown) {
          this.ship.thrustShip('on');
        } else {
          this.ship.thrustShip('off');
        }

        if (this.key_fire.isDown) {<commit_msg>consolidated explosion group creation into function<commit_after>/* globals __DEV__ */
import Phaser from 'phaser';
import Ship from '../sprites/Ship';

// This is where all the game play code goes.
class Play extends Phaser.State {
    init() {
        // set game config variable data from game cache
        this.Config = this.game.cache.getJSON('config');

        this.Config.gameProperties.screenWidth = this.game.world.width;
        this.Config.gameProperties.screenHeight = this.game.world.height;
        this.Config.shipProperties.startX = this.Config.gameProperties.screenWidth * 0.5;
        this.Config.shipProperties.startY = this.Config.gameProperties.screenHeight * 0.5;
        this.Config.asteroidProperties.asteroidLarge.nextSize = this.Config.graphicAssets.asteroidMedium.name;
        this.Config.asteroidProperties.asteroidMedium.nextSize = this.Config.graphicAssets.asteroidSmall.name;

        this.bulletInterval = 0;
        this.score = 0;
        this.asteroidsCount = this.Config.asteroidProperties.startingAsteroids;

        // start physics system
        this.game.physics.startSystem(Phaser.Physics.ARCADE);
    }
    preload() {}

    create() {
        this.initGraphics();
        this.initSounds();
        this.initPhysics();
        this.initKeyboard();
        this.resetAsteroids();
    }

    initGraphics() {
        this.backgroundSprite = this.game.add.sprite(0, 0, this.Config.graphicAssets.background.name);
        this.backgroundSprite.width = this.Config.gameProperties.screenWidth;
        this.backgroundSprite.height = this.Config.gameProperties.screenHeight;

        this.ship = new Ship({
            game: this.game,
            x: this.game.world.centerX,
            y: this.game.world.centerY,
            asset: this.Config.graphicAssets.shipsheet.name
        });
        this.game.add.existing(this.ship);

        this.bulletGroup = this.game.add.group();
        this.asteroidGroup = this.game.add.group();

        this.tf_lives = this.game.add.text(20, 10, this.ship.lives, this.Config.fontAssets.playFontStyle);

        this.tf_score = this.game.add.text(this.Config.gameProperties.screenWidth - 50, 10, "0", this.Config.fontAssets.playFontStyle);
        this.tf_score.align = 'right';
        this.tf_score.anchor.set(1, 0);

        this.explosionLargeGroup = this.makeExplosionGroup(this.game, 'large');
        this.explosionMediumGroup = this.makeExplosionGroup(this.game, 'medium');
        this.explosionSmallGroup = this.makeExplosionGroup(this.game, 'small');
    }

    initSounds() {
        this.sndDestroyed = this.game.add.audio(this.Config.soundAssets.destroyed.name);
        this.sndFire = this.game.add.audio(this.ship.sound.fire);
    }

    initPhysics() {
        this.bulletGroup.enableBody = true;
        this.bulletGroup.physicsBodyType = Phaser.Physics.ARCADE;
        this.bulletGroup.createMultiple(this.Config.bulletProperties.maxCount, this.Config.graphicAssets.bullet.name);
        this.bulletGroup.setAll('anchor.x', 0.5);
        this.bulletGroup.setAll('anchor.y', 0.5);
        this.bulletGroup.setAll('lifespan', this.Config.bulletProperties.lifespan);

        this.asteroidGroup.enableBody = true;
        this.asteroidGroup.physicsBodyType = Phaser.Physics.ARCADE;
    }

    initKeyboard() {
        this.key_left = this.game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
        this.key_right = this.game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);
        this.key_thrust = this.game.input.keyboard.addKey(Phaser.Keyboard.UP);
        this.key_fire = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
    }

    makeExplosionGroup(game, size) {
      let group = game.add.group();
      let explosionName = "";

      if(size === 'large') {
        explosionName = this.Config.graphicAssets.explosionLarge.name;
      } else if(size === 'medium') {
        explosionName = this.Config.graphicAssets.explosionMedium.name;
      } else {
        explosionName = this.Config.graphicAssets.explosionSmall.name;
      }

      group.createMultiple(20, explosionName, 0);
      group.setAll('anchor.x', 0.5);
      group.setAll('anchor.y', 0.5);
      group.callAll('animations.add', 'animations', 'explode', null, 30);

      return group;
    }

    checkPlayerInput() {
        if (this.key_left.isDown) {
            this.ship.moveShip('left');
        } else if (this.key_right.isDown) {
            this.ship.moveShip('right');
        } else {
            this.ship.moveShip('stop');
        }

        if (this.key_thrust.isDown) {
          this.ship.thrustShip('on');
        } else {
          this.ship.thrustShip('off');
        }

        if (this.key_fire.isDown) {
{'fraction_non_alphanumeric': 0.13007284079084286, 'fraction_numerical': 0.008532778355879293, 'mean_word_length': 2.7675421403371225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7204868', 'n_tokens_mistral': 3092, 'n_tokens_neox': 2973, 'n_words': 397}