<commit_before>TowerDefense.Bullet = function () {

    TowerDefense.Element.call( this );

    this.type = 'BULLET';

    this.stats = {
        damage: 1,
        speed: .01 // Movement in units.
    }

    this.targetIndex = -1;
    this.material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
    this.geometry = new THREE.BoxGeometry( .5, .5, .5 );
}

TowerDefense.Bullet.prototype = Object.create( TowerDefense.Element.prototype );

TowerDefense.Bullet.prototype.constructor = TowerDefense.Bullet;

TowerDefense.Bullet.prototype.remove = function () {

    if (TowerDefense.objects[this.targetIndex] != null) {
        TowerDefense.objects[this.targetIndex].removeHealth(this.stats.damage);
    }
    TowerDefense.__removeObject(this);

}

TowerDefense.Bullet.prototype.update = function() {

    // Move closer to targetIndex position or delete when it hits or is already destroyed
    if (TowerDefense.objects[this.targetIndex] == null) {
        this.remove();
        return;
    }
    var target = TowerDefense.objects[this.targetIndex];

    if (TowerDefense.inRange(target.object.position, this.object.position,1)) {
        this.remove();
        return;
    }

    // Distance of each
    var moveXOrg = this.object.position.x - target.object.position.x;
    var moveYOrg = this.object.position.y - target.object.position.y;
    var moveZOrg = this.object.position.z - target.object.position.z;

    // Positive number of distance
    var moveX = Math.abs(moveXOrg);
    var moveY = Math.abs(moveYOrg);
    var moveZ = Math.abs(moveZOrg);

    // Total (100%)
    var total = moveX + moveY + moveZ;
    var one = 100 / total;

    var moveXPercent = one * moveX;
    var moveYPercent = one * moveY;
    var moveZPercent = one * moveZ;

    moveX = moveXPercent * this.stats.speed;
    moveY = moveYPercent * this.stats.speed;
    moveZ = moveZPercent * this.stats.speed;

    if (moveXOrg < 0) {
        moveX = moveX-moveX-moveX;
    }
    if (moveYOrg < 0) {
        moveY = moveY-moveY-moveY;
    }
    if (moveZOrg < 0) {
        moveZ = moveZ-moveZ-moveZ;
    }

    this.object.position.x -= moveX;
    this.object.position.y -= moveY;
    this.object.position.z -= moveZ;

//
//    var hundredPercent = moveX + moveY + moveZ;
//    var onePercent = hundredPercent / 100;
//    var moveXPercent = onePercent * moveX;
//    moveX = hundredPercent / moveXPercent * this.stats.speed;
////    moveX = this.stats.speed + (this.object.position.x - target.object.position.x);
//    moveY = this.stats.speed + (this.object.position.y - target.object.position.y);
//    moveZ = this.stats.speed + (this.object.position.z - target.object.position.z);
//    console.log(moveX);
//    this.object.position.x -= moveX;
//    this.object.position.y -= moveY;
//    this.object.position.z -= moveZ;
//    this.object.position.x = (one * moveX) + this.stats.speed;// * this.stats.speed;
//    this.object.position.y = (one * moveY) + this.stats.speed;; //* this.stats.speed;
//    this.object.position.z = (one * moveZ) + this.stats.speed;;// * this.stats.speed;

}<commit_msg>Despawn bullet after losing target after deadtimer.<commit_after>TowerDefense.Bullet = function () {

    TowerDefense.Element.call( this );

    this.type = 'BULLET';

    this.stats = {
        damage: 1,
        speed: .01 // Movement in units.
    }

    this.lastMovement = {};
    this.deadTimer = 180;

    this.targetIndex = -1;
    this.material = new THREE.MeshBasicMaterial( { color: 0xff9900 } );
    this.geometry = new THREE.BoxGeometry( .5, .5, .5 );
}

TowerDefense.Bullet.prototype = Object.create( TowerDefense.Element.prototype );

TowerDefense.Bullet.prototype.constructor = TowerDefense.Bullet;

TowerDefense.Bullet.prototype.remove = function () {

    TowerDefense.__removeObject(this);

}

TowerDefense.Bullet.prototype.update = function() {

    // Move closer to targetIndex position or delete when it hits or is already destroyed
    if (TowerDefense.objects[this.targetIndex] == null) {

        this.object.position.x -= this.lastMovement.x;
        this.object.position.y -= this.lastMovement.y;
        this.object.position.z -= this.lastMovement.z;
        this.deadTimer--;
        if (this.deadTimer <= 0) {
            this.remove();
        }
        return;
    }
    var target = TowerDefense.objects[this.targetIndex];

    if (TowerDefense.inRange(target.object.position, this.object.position,1)) {
        TowerDefense.objects[this.targetIndex].removeHealth(this.stats.damage);
        this.remove();
        return;
    }

    // Distance of each
    var moveXOrg = this.object.position.x - target.object.position.x;
    var moveYOrg = this.object.position.y - target.object.position.y;
    var moveZOrg = this.object.position.z - target.object.position.z;

    // Positive number of distance
    var moveX = Math.abs(moveXOrg);
    var moveY = Math.abs(moveYOrg);
    var moveZ = Math.abs(moveZOrg);

    // Total (100%)
    var total = moveX + moveY + moveZ;
    var one = 100 / total;

    var moveXPercent = one * moveX;
    var moveYPercent = one * moveY;
    var moveZPercent = one * moveZ;

    moveX = moveXPercent * this.stats.speed;
    moveY = moveYPercent * this.stats.speed;
    moveZ = moveZPercent * this.stats.speed;

    if (moveXOrg < 0) {
        moveX = moveX-moveX-moveX;
    }
    if (moveYOrg < 0) {
        moveY = moveY-moveY-moveY;
    }
    if (moveZOrg < 0) {
        moveZ = moveZ-moveZ-moveZ;
    }

    this.lastMovement = { x: moveX, y: moveY, z: moveZ };

    this.object.position.x -= moveX;
    this.object.position.y -= moveY;
    this.object.position.z -= moveZ;

}
{'fraction_non_alphanumeric': 0.13545180188176814, 'fraction_numerical': 0.009053790165098526, 'mean_word_length': 2.579415501905972, 'pattern_counts': {'":': 0, '<': 10, '<?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': '6978467', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1871, 'n_words': 372}