<commit_before>/* jshint unused:true, undef:true, browser:true */
/* global Phaser:false */

// Look for TODO items in the code.



var ConfettiEmitter = function() {
    Phaser.Particles.Arcade.Emitter.call(this, this.game, 0, 0, 100);
    this.makeParticles(this.game.cache.getBitmapData("confetti"));
    this.gravity = 200;
};
ConfettiEmitter.prototype = Object.create(Phaser.Particles.Arcade.Emitter.prototype);
ConfettiEmitter.prototype.boom = function(x, y) {
    // Position emitter to distribute particles.
    this.x = x;
    this.y = y;
    // The first parameter sets the effect to "explode" which means all particles are emitted at once
    // The second gives each particle a 2000ms lifespan
    // The third is ignored when using burst/explode mode
    // The final parameter (10) is how many particles will be emitted in this single burst
    this.start(true, 2000, null, 10);
};
// Provide a set color or a random color.
ConfettiEmitter.prototype.colorize = function(color) {
    this.forEach(function(p) {
        // Give each piece of confetti a random tint.
        p.tint = color || Phaser.Color.getRandomColor();
    });
};
// Set during init, reference to game.
ConfettiEmitter.prototype.game = null;
// This pattern is okay, I'm sticking with it because I tried it out earlier.
ConfettiEmitter.init = function(game) {
    var confetti = game.add.bitmapData(10, 10, "confetti", true);
    confetti.fill(255, 255, 255, 1);

    this.prototype.game = game;
};



var Flaktulence = function(x, y) {
    // Trying out cache.
    Phaser.Sprite.call(this, this.game, x || 0, y || 0, this.game.cache.getBitmapData("flak"));

    // Center flak over pointer.
    this.anchor.setTo(0.5, 0.5);
    this.game.physics.arcade.enable(this);
    this.game.add.existing(this);
    // Start off dead, expect to be added to a group.
    this.kill();
};
Flaktulence.prototype = Object.create(Phaser.Sprite.prototype);
// What's our max lifespan?
Flaktulence.prototype.maxLifespan = 2000;
Flaktulence.prototype.halflife = Flaktulence.prototype.maxLifespan / 2;
Flaktulence.prototype.lifespan = Flaktulence.prototype.maxLifespan;
// How many pixels big before we implode.
Flaktulence.prototype.maxSize = 60;
Flaktulence.prototype.launch = function(x, y) {
    this.lifespan = this.maxLifespan;
    this.reset(x, y);
};
Flaktulence.prototype.update = function() {
    // TODO: Make the collision box at most the radius of the circle.
    // TODO: Try tweens instead of the math below.

    // Increase the size of the sprite.
    var sizeRatio;
    // Whether we are imploding or exploding.
    if (this.lifespan > this.halflife) {
        // Exploding.
        sizeRatio = 1 - ((this.lifespan - this.halflife) / this.halflife);
    } else {
        // Imploding.
        sizeRatio = this.lifespan / this.halflife;
    }
    this.width = sizeRatio * this.maxSize;
    this.height = sizeRatio * this.maxSize;
};
// Reference to game instance using Flaktulence. Initialized during init.
Flaktulence.prototype.game = null;
// Call before using flak instances.
Flaktulence.init = function(game) {
    // width, height, key
    var spriteImage = game.add.bitmapData(14, 14);
    spriteImage.circle(7, 7, 7, "#ff0000");

    // try out cache for bit map data.
    game.cache.addBitmapData("flak", spriteImage);

    this.prototype.game = game;
};



var Pig = function(position) {
    position = position || {};
    Phaser.Sprite.call(this, this.game, position.x || 0, position.y || 0, 'pig');
    this.anchor.setTo(0.5, 0.5);
    // For collisions.
    this.game.physics.arcade.enable(this);<commit_msg>Spending a few train rides to/from work commenting and cleaning up code (mainly commenting), since I want this to serve as yet-another-rubber-duck example.<commit_after>/* jshint unused:true, undef:true, browser:true */
/* global Phaser:false */

// Look for TODO items in the code.



// Used for exploding dinos and exploding pigs.
// Extenders Phaser.Emitter.
var ConfettiEmitter = function() {
    // game, initialX, initialY, maxParticles
    Phaser.Particles.Arcade.Emitter.call(this, this.game, 0, 0, 100);
    this.makeParticles(this.game.cache.getBitmapData("confetti"));
    this.gravity = 200;
};
ConfettiEmitter.prototype = Object.create(Phaser.Particles.Arcade.Emitter.prototype);
// Explode paricles at a point.
// {Number} x, {Number} y -> Point in world to emit particles.
ConfettiEmitter.prototype.boom = function(x, y) {
    // Position emitter to distribute particles.
    this.x = x;
    this.y = y;
    // The first parameter sets the effect to "explode" which means all particles are emitted at once
    // The second gives each particle a 2000ms lifespan
    // The third is ignored when using burst/explode mode
    // The final parameter (10) is how many particles will be emitted in this single burst
    this.start(true, 2000, null, 10);
};
// {Color} -> A phaser supported color expression. Turns all phaser particles
// this color, otherwise randomizes the color for each particle emitted.
ConfettiEmitter.prototype.colorize = function(color) {
    this.forEach(function(p) {
        // Give each piece of confetti a random tint.
        p.tint = color || Phaser.Color.getRandomColor();
    });
};
// Refence to game, set during init.
ConfettiEmitter.prototype.game = null;
// This is a pattern I tried out here as an experiment. Since Phaser has
// a lot of hierarchical relationships, the main enforced being references
// to the game that the objects are a part of, I require initialization of
// the datatype object before it is ready. Next time, I think I'll keep
// the game as a global object and just assume it's there.
// This comment won't be repeated throughout the document and is here for
// historical reference.
ConfettiEmitter.init = function(game) {
    // width, height, name, true means add to cache (later retrieval by name).
    var confetti = game.add.bitmapData(10, 10, "confetti", true);
    // r, g, b, a
    confetti.fill(255, 255, 255, 1);

    this.prototype.game = game;
};



// As this game is a bit crude, this is the "flak" let off by the gaseous
// purple dinosaur.
var Flaktulence = function(x, y) {
    
    Phaser.Sprite.call(this, this.game, x || 0, y || 0, this.game.cache.getBitmapData("flaktulence"));

    // Center drawing of flak over x, y of sprite.
    this.anchor.setTo(0.5, 0.5);
    this.game.physics.arcade.enable(this);
    this.game.add.existing(this);

    // Start off dead, expect to be added to a group.
    this.kill();
};
Flaktulence.prototype = Object.create(Phaser.Sprite.prototype);
// What's our max lifespan?
Flaktulence.prototype.maxLifespan = 2000;
Flaktulence.prototype.halflife = Flaktulence.prototype.maxLifespan / 2;
Flaktulence.prototype.lifespan = Flaktulence.prototype.maxLifespan;
// How many pixels big before we implode.
Flaktulence.prototype.maxSize = 60;
Flaktulence.prototype.launch = function(x, y) {
    this.lifespan = this.maxLifespan;
    this.reset(x, y);
};
Flaktulence.prototype.update = function() {
    // TODO: Make the collision box at most the radius of the circle.
    // TODO: Try tweens instead of the math below.

    // Increase the size of the sprite.
    var sizeRatio;
    // Whether we are imploding or exploding.
    if (this.lifespan > this.halflife) {
        // Exploding.
        sizeRatio = 1 - ((this.lifespan - this.halflife) / this.halflife);
    } else {
        // Imploding.
        sizeRatio = this.lifespan / this.halflife;
    }
    this.width = sizeRatio * this.maxSize;
    this.height = sizeRatio * this.maxSize;
};
// Refence to game, set during init.
Flaktulence.prototype.game = null;
// Call before using flak instances.
Flaktulence.init = function(game) {
    // width, height, name, add to cache.
    var spriteImage = game.add.bitmapData(14, 14, "flaktulence", true);
    spriteImage.circle(7, 7, 7, "#ff0000");

    this.prototype.game = game;
};



var Pig = function(position) {
    position = position || {};
    Phaser.Sprite.call(this, this.game, position.x || 0, position.y || 0, 'pig');
    this.anchor.setTo(0.5, 0.5);
    // For collisions.
    this.game.physics.arcade.enable(this);
{'fraction_non_alphanumeric': 0.12079548244537196, 'fraction_numerical': 0.015958752762091823, 'mean_word_length': 3.188688946015424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7403526', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2522, 'n_words': 798}