<commit_before>'use strict';

Darwinator.GameState = function() {

    // Input
    this.cursors               = null;
    this.cheatKey              = null;
    this.pauseKey              = null;

    // Groups
    this.bullets               = null;
    this.gui                   = null;

    // Displayables
    this.fps                   = null;
    this.stats                 = null;
    this.health                = null;
    this.secondsRemaining      = null;
    this.enemiesRemaining      = null;
    this.pauseText             = null;
    this.roundSecondsRemaining = null;
    this.endRoundTimer         = null;
    this.displayTimeLeftTimer  = null;
    this.crosshair             = null;

};

Darwinator.GameState.prototype = {

    init: function (reset) {
        if (!reset) {
            // Input
            this.cursors        = this.game.input.keyboard.createCursorKeys();
            this.cheatKey       = this.game.input.keyboard.addKey(Phaser.Keyboard.E);
            this.pauseKey       = this.game.input.keyboard.addKey(Phaser.Keyboard.P);
            this.fullScreenKey  = this.game.input.keyboard.addKey(Phaser.Keyboard.F);

            // Map
            this.level = new Darwinator.Level(this.game);
            this.level.addTopLayer();

            // Containers
            this.bullets = this.game.add.group();
            this.gui     = this.initGUI();

            // Misc
            this.game.time.advancedTiming = true;
            this.gui.fixedToCamera        = true;
        }

        this.game.add.existing(this.gui);
        this.game.add.existing(this.bullets);

        this.cheatKey.onDown.add(this.endRound, this);
        this.pauseKey.onDown.add(this.togglePause, this);
        this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
        this.fullScreenKey.onDown.add(this.goFullScreen, this);

        // Since states lack a callback for the resume event
        this.game.onResume.add(this.resumed, this);
    },

    beforeSwitch: function () {
        this.game.world.remove(this.game.player);
        this.game.world.remove(this.game.enemies);
        this.game.world.remove(this.gui);
        this.game.world.remove(this.bullets);

        this.cheatKey.onDown.remove(this.endRound, this);
        this.pauseKey.onDown.remove(this.togglePause, this);
        this.game.onResume.remove(this.resumed, this);

        this.stopTimers();
        this.game.time.events.remove(this.game.player.dodgeTimer);
        this.game.player.alpha = 1;
        this.game.player.dodging = false;
    },

    create: function () {

        this.spawnPlayer(160, 620);
        this.game.enemies = this.level.spawnEnemies();

        // TODO Find the right way to do this
        this.game.enemies.setAll('alive', true);

        this.game.world.bringToTop(this.level.toplayer);

        for (var i = 0; i < this.game.enemies.length; i++) {
            var enemy = this.game.enemies.getAt(i);
            var weapon = new Darwinator.Cannon(this.game, enemy, this.bullets);
            enemy.arm(weapon);<commit_msg>kill bullets when round ends<commit_after>'use strict';

Darwinator.GameState = function() {

    // Input
    this.cursors               = null;
    this.cheatKey              = null;
    this.pauseKey              = null;

    // Groups
    this.bullets               = null;
    this.gui                   = null;

    // Displayables
    this.fps                   = null;
    this.stats                 = null;
    this.health                = null;
    this.secondsRemaining      = null;
    this.enemiesRemaining      = null;
    this.pauseText             = null;
    this.roundSecondsRemaining = null;
    this.endRoundTimer         = null;
    this.displayTimeLeftTimer  = null;
    this.crosshair             = null;

};

Darwinator.GameState.prototype = {

    init: function (reset) {
        if (!reset) {
            // Input
            this.cursors        = this.game.input.keyboard.createCursorKeys();
            this.cheatKey       = this.game.input.keyboard.addKey(Phaser.Keyboard.E);
            this.pauseKey       = this.game.input.keyboard.addKey(Phaser.Keyboard.P);
            this.fullScreenKey  = this.game.input.keyboard.addKey(Phaser.Keyboard.F);

            // Map
            this.level = new Darwinator.Level(this.game);
            this.level.addTopLayer();

            // Containers
            this.bullets = this.game.add.group();
            this.gui     = this.initGUI();

            // Misc
            this.game.time.advancedTiming = true;
            this.gui.fixedToCamera        = true;
        }

        this.game.add.existing(this.gui);
        this.game.add.existing(this.bullets);

        this.cheatKey.onDown.add(this.endRound, this);
        this.pauseKey.onDown.add(this.togglePause, this);
        this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
        this.fullScreenKey.onDown.add(this.goFullScreen, this);

        // Since states lack a callback for the resume event
        this.game.onResume.add(this.resumed, this);
    },

    beforeSwitch: function () {
        this.game.world.remove(this.game.player);
        this.game.world.remove(this.game.enemies);
        this.game.world.remove(this.gui);
        this.game.world.remove(this.bullets);

        this.cheatKey.onDown.remove(this.endRound, this);
        this.pauseKey.onDown.remove(this.togglePause, this);
        this.game.onResume.remove(this.resumed, this);

        this.stopTimers();

        this.game.time.events.remove(this.game.player.dodgeTimer);
        this.game.player.alpha = 1;
        this.game.player.dodging = false;

        for(var i = 0; i < this.bullets.length; i++){
            var bulletGroup = this.bullets.getAt(i);
            bulletGroup.forEachAlive(function(bullet){bullet.kill();}, this);
        }
    },

    create: function () {

        this.spawnPlayer(160, 620);
        this.game.enemies = this.level.spawnEnemies();

        // TODO Find the right way to do this
        this.game.enemies.setAll('alive', true);

        this.game.world.bringToTop(this.level.toplayer);

        for (var i = 0; i < this.game.enemies.length; i++) {
            var enemy = this.game.enemies.getAt(i);
            var weapon = new Darwinator.Cannon(this.game, enemy, this.bullets);
            enemy.arm(weapon);
{'fraction_non_alphanumeric': 0.12177063642091998, 'fraction_numerical': 0.0026780088216761186, 'mean_word_length': 1.8068081343943412, 'pattern_counts': {'":': 0, '<': 6, '<?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': '77228', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1899, 'n_words': 294}