<commit_before>/* global game, Phaser, shmup */
var Enemy = require('./enemy');

var getBullet = function() {
    var shot = shmup.enemyBullets.getFirstDead();
    if (!shot) {
        shot = game.make.sprite(0, 0, 'pix');
        shot.checkWorldBounds = true;
        shot.outOfBoundsKill = true;
        game.physics.arcade.enable(shot);
        shmup.enemyBullets.add(shot);
    }
    return shot;
};

var Boss = function(difficulty) {
    Phaser.Sprite.call(this, game, 400, 0, game.rnd.pick(Enemy.prototype.IMAGE_KEYS));
    shmup.enemies.add(this);
    this.anchor.set(0.5);
    game.physics.arcade.enable(this);
    this.body.setSize(this.body.width * .7, this.body.height * .7);
    this.moveTimer = 0;
    this.moveState = this.INIT;
    this.moveTween = null;
    this.shotTimer = 0;
    this.scale.set(1.5);
    this.health = difficulty * 100; // shot-in-the-dark for balance
};
Boss.prototype = Object.create(Phaser.Sprite.prototype);
Boss.prototype.constructor = Boss;
Boss.prototype.INIT = 0;
Boss.prototype.PAN = 1;
Boss.prototype.RANDOM = 2;
Boss.prototype.update = function() {
    // handle movement based on move state / health
    switch (this.moveState) {
        case this.INIT:
            this.y += 30 * game.time.physicsElapsed;
            if (this.y >= 150) this.moveState = this.PAN;
            break;
        case this.PAN:

            break;
        case this.RANDOM:
            break;
    }
    // shoot based on boss pattern
    this.shotTimer += game.time.physicsElapsed;
    if (this.shotTimer > 0.5) {
        // add shots
        this.shotTimer = 0;
        var shot = getBullet();
        shot.tint = 0xff80ff;
        shot.x = this.x;
        shot.y = this.y;
        shot.height = shot.width = 20;
        shot.body.reset(shot.x, shot.y);
        shot.revive();
        game.physics.arcade.moveToObject(shot, shmup.player, 300);
    }<commit_msg>Add multiple movement stages to boss.<commit_after>/* global game, Phaser, shmup */
var Enemy = require('./enemy');

var getBullet = function() {
    var shot = shmup.enemyBullets.getFirstDead();
    if (!shot) {
        shot = game.make.sprite(0, 0, 'pix');
        shot.checkWorldBounds = true;
        shot.outOfBoundsKill = true;
        game.physics.arcade.enable(shot);
        shmup.enemyBullets.add(shot);
    }
    return shot;
};

var createRandomLocationTween = function(target, tween) {
    tween.to({
        x: game.rnd.between(100, 700),
        y: game.rnd.between(20, 300)
    }, 1000, null, true);
};

var Boss = function(difficulty) {
    Phaser.Sprite.call(this, game, 400, 0, game.rnd.pick(Enemy.prototype.IMAGE_KEYS));
    shmup.enemies.add(this);
    this.anchor.set(0.5);
    game.physics.arcade.enable(this);
    this.body.setSize(this.body.width * .7, this.body.height * .7);
    this.moveTimer = 0;
    this.moveState = this.INIT;
    this.moveTween = null;
    this.shotTimer = 0;
    this.scale.set(1.5);
    this.maxHealth = this.health = difficulty * 100; // shot-in-the-dark for balance
};
Boss.prototype = Object.create(Phaser.Sprite.prototype);
Boss.prototype.constructor = Boss;
Boss.prototype.INIT = 0;
Boss.prototype.PAN = 1;
Boss.prototype.RANDOM = 2;
Boss.prototype.update = function() {
    if (!this.alive) return; // seems like this should be the default behavior in Phaser...
    // handle movement based on move state / health
    switch (this.moveState) {
        case this.INIT:
            if (this.y < 150) this.y += 30 * game.time.physicsElapsed;
            if (this.health < this.maxHealth * .7) this.moveState = this.PAN;
            break;
        case this.PAN:
            if (!this.moveTween) {
                this.moveTween = game.tweens.create(this);
                this.moveTween.to({
                    x: 650
                }, 3000, null, false, 0, -1, true);
                game.add.tween(this).to({
                    x: 150
                }, 1500, null, true).chain(this.moveTween);
            }
            if (this.health < this.maxHealth * .35) {
                this.moveTween.stop();
                this.moveTween = null;
                this.moveState = this.RANDOM;
            }
            break;
        case this.RANDOM:
            if (!this.moveTween) {
                this.moveTween = game.add.tween(this);
                this.moveTween.onComplete.add(createRandomLocationTween);
                createRandomLocationTween(null, this.moveTween);
            }
            break;
    }
    // shoot based on boss pattern
    this.shotTimer += game.time.physicsElapsed;
    if (this.shotTimer > 0.5) {
        // add shots
        this.shotTimer = 0;
        var shot = getBullet();
        shot.tint = 0xff80ff;
        shot.x = this.x;
        shot.y = this.y;
        shot.height = shot.width = 20;
        shot.body.reset(shot.x, shot.y);
        shot.revive();
        game.physics.arcade.moveToObject(shot, shmup.player, 300);
    }
{'fraction_non_alphanumeric': 0.1366042345276873, 'fraction_numerical': 0.021579804560260585, 'mean_word_length': 2.053449347420758, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '764032', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1631, 'n_words': 328}