<commit_before>//
//  enemy.js
//
//  Created by <NAME> on 2014-12-06.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

(function () {
    "use strict";

    var Enemy = function (difficulty) {
	this._setup(difficulty);
    };

    Enemy.prototype = new window.LivingObject();

    Enemy.prototype._setup = function (difficulty) {
	window.GameObject.prototype._setup.call(this);

	this._node.className = "enemy";

	var extraScale = Math.random() * difficulty;
	var extraSpeed = Math.max(0, 0.5 * Math.random() * difficulty + 0.5 - 0.5 * extraScale);
	var extraHealth = Math.random() * difficulty;

	this._scale = 1 + extraScale;
	this._size = {width: Math.round(20 * this._scale), height: Math.round(20 * this._scale)};
	this._maxSpeed = 3 + 3 * extraSpeed;
	this._health = 10 + 30 * extraHealth;

	var red = Math.floor(255 * Math.min(0.9, (0.25 + 0.25 * extraHealth)));
	var green = Math.floor(255 * Math.min(0.9, (0.5 + 0.25 * extraScale)));
	var blue = Math.floor(255 * Math.min(0.9, (0.25 + 0.25 * extraSpeed)));

	this._color = "rgb(" + red + ", " + green + ", " + blue + ")";
	this._bodyNode.style.backgroundColor = this._color;
	this._bodyNode.style.left = "" + (-this._size.width / 2) + "px";
	this._bodyNode.style.top = "" + (-this._size.height / 2) + "px";
	this._bodyNode.style.width = "" + this._size.width + "px";
	this._bodyNode.style.height = "" + this._size.height + "px";
	this._bodyNode.style.borderRadius = "" + (this._size.width / 2) + "px";
    };

    Enemy.prototype.update = function (tick, playerPosition) {
	this._updateVelocityTowardsPosition(playerPosition);
	this._updatePosition();
	this._updateHurtCounter();
    };

    Enemy.prototype._updateVelocityTowardsPosition = function (position) {
	var speed = Math.sqrt(this._velocity.x * this._velocity.x + this._velocity.y * this._velocity.y);
	var dimmingFactor = 0.8;
	var distance = {
	    x: position.x - this.position().x,
	    y: position.y - this.position().y
	}
	var linearDistance = Math.sqrt(distance.x * distance.x + distance.y * distance.y);
	var change = {
	    x: distance.x / linearDistance / 20 + (Math.random() - 0.5) / 2,
	    y: distance.y / linearDistance / 20 + (Math.random() - 0.5) / 2
	};

	this._velocity.x += change.x;
	this._velocity.y += change.y;

	if (change.x === 0) {
	    this._velocity.x *= dimmingFactor;
	}
	if (change.y === 0) {
	    this._velocity.y *= dimmingFactor;
	}

	if (speed > this._maxSpeed) {
	    this._velocity.x *= this._maxSpeed / speed;
	    this._velocity.y *= this._maxSpeed / speed;
	}
    };

    Enemy.prototype.drawDeadBodyOntoCanvas = function (canvas) {
	var context = canvas.getContext("2d");
	var position = this.position();
	var radius = this._size.width / 2;
	var color = this._color;

	context.save();
	context.fillStyle = color;
	context.globalAlpha = 0.5;

	context.beginPath();
	context.arc(position.x, position.y, radius, 0, 2 * Math.PI, true);
	context.closePath();
	context.fill();

	context.restore();
    };

    window.Enemy = Enemy;
}());
<commit_msg>Tweaked enemy colors a bit.<commit_after>//
//  enemy.js
//
//  Created by <NAME> on 2014-12-06.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

(function () {
    "use strict";

    var Enemy = function (difficulty) {
	this._setup(difficulty);
    };

    Enemy.prototype = new window.LivingObject();

    Enemy.prototype._setup = function (difficulty) {
	window.GameObject.prototype._setup.call(this);

	this._node.className = "enemy";

	var extraScale = Math.random() * difficulty;
	var extraSpeed = Math.max(0, 0.5 * Math.random() * difficulty + 0.5 - 0.5 * extraScale);
	var extraHealth = Math.random() * difficulty;

	this._scale = 1 + extraScale;
	this._size = {width: Math.round(20 * this._scale), height: Math.round(20 * this._scale)};
	this._maxSpeed = 3 + 3 * extraSpeed;
	this._health = 10 + 30 * extraHealth;

	var red = Math.floor(255 * Math.min(0.9, (0.1 + 0.2 * extraHealth)));
	var green = Math.floor(255 * Math.min(0.9, (0.3 + 0.4 * extraScale)));
	var blue = Math.floor(255 * Math.min(0.9, (0.3 + 0.4 * extraSpeed)));

	this._color = "rgb(" + red + ", " + green + ", " + blue + ")";
	this._bodyNode.style.backgroundColor = this._color;
	this._bodyNode.style.left = "" + (-this._size.width / 2) + "px";
	this._bodyNode.style.top = "" + (-this._size.height / 2) + "px";
	this._bodyNode.style.width = "" + this._size.width + "px";
	this._bodyNode.style.height = "" + this._size.height + "px";
	this._bodyNode.style.borderRadius = "" + (this._size.width / 2) + "px";
    };

    Enemy.prototype.update = function (tick, playerPosition) {
	this._updateVelocityTowardsPosition(playerPosition);
	this._updatePosition();
	this._updateHurtCounter();
    };

    Enemy.prototype._updateVelocityTowardsPosition = function (position) {
	var speed = Math.sqrt(this._velocity.x * this._velocity.x + this._velocity.y * this._velocity.y);
	var dimmingFactor = 0.8;
	var distance = {
	    x: position.x - this.position().x,
	    y: position.y - this.position().y
	}
	var linearDistance = Math.sqrt(distance.x * distance.x + distance.y * distance.y);
	var change = {
	    x: distance.x / linearDistance / 20 + (Math.random() - 0.5) / 2,
	    y: distance.y / linearDistance / 20 + (Math.random() - 0.5) / 2
	};

	this._velocity.x += change.x;
	this._velocity.y += change.y;

	if (change.x === 0) {
	    this._velocity.x *= dimmingFactor;
	}
	if (change.y === 0) {
	    this._velocity.y *= dimmingFactor;
	}

	if (speed > this._maxSpeed) {
	    this._velocity.x *= this._maxSpeed / speed;
	    this._velocity.y *= this._maxSpeed / speed;
	}
    };

    Enemy.prototype.drawDeadBodyOntoCanvas = function (canvas) {
	var context = canvas.getContext("2d");
	var position = this.position();
	var radius = this._size.width / 2;
	var color = this._color;

	context.save();
	context.fillStyle = color;
	context.globalAlpha = 0.5;

	context.beginPath();
	context.arc(position.x, position.y, radius, 0, 2 * Math.PI, true);
	context.closePath();
	context.fill();

	context.restore();
    };

    window.Enemy = Enemy;
}());

{'fraction_non_alphanumeric': 0.1755345599204376, 'fraction_numerical': 0.02734957732471407, 'mean_word_length': 3.2314165497896212, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3324709', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2104, 'n_words': 440}