<commit_before>var RigidBody = function (attachedTo, mass) {
    this.attachedTo = attachedTo;
    this.mass = mass;
    this.speedX = 0.0;
    this.speedY = 0.0;
    this.forceX = 0.0;
    this.forceY = 0.0;
    this.isGrounded = false;
};

RigidBody.prototype.applyForce = function () {
    var gAcc = -0.00001;    // Kinda low? Maybe?
    var vAcc = this.forceY / this.mass;
    var hAcc = this.forceX / this.mass;

    this.speedY += (gAcc + vAcc) * scene.elapsed;
    this.speedX += hAcc * scene.elapsed;

    var bodyPosition = this.attachedTo.getPosition();
    this.attachedTo.setPosition(bodyPosition.x + this.speedX * scene.elapsed, bodyPosition.y + this.speedY * scene.elapsed);
};

RigidBody.prototype.onGround = function () {
    this.isGrounded = true;
    this.speedY = 0.0;
};

var Collider = function (attachedTo, width, height) {
    this.attachedTo = attachedTo;
    this.w = width;
    this.h = height;
};

Collider.prototype.checkForCollision = function (other) {
    var actorPos = this.attachedTo.getPosition();
    var otherPos = other.attachedTo.getPosition();

    if (actorPos.x - this.w / 2 < otherPos.x + other.w / 2 &&
        actorPos.x + this.w / 2 > otherPos.x - other.w / 2 &&
        actorPos.y - this.h / 2 < otherPos.y + other.h / 2 &&
        actorPos.y + this.h / 2 > otherPos.y - other.h / 2) {

        var deltaX = actorPos.x - otherPos.x;
        var deltaY = actorPos.y - otherPos.y;

        if (deltaY > deltaX) {
            if (deltaY > 0) {
                this.attachedTo.rigidBody.onGround();
                this.attachedTo.setPosition(actorPos.x, otherPos.y + (other.h + this.h) / 2);
            } else {
                this.attachedTo.setPosition(actorPos.x, otherPos.y - (other.h + this.h) / 2);
            }
        } else {
            if (deltaX > 0) {
                this.attachedTo.setPosition(otherPos.x + (other.w + this.w) / 2, actorPos.y);
            } else {
                this.attachedTo.setPosition(otherPos.x - (other.w + this.w) / 2, actorPos.y);
            }
        }
    }
};<commit_msg>Fixed collision detection on all sides Bug: when hitting an object from down, player sticks slightly (feature?)<commit_after>var RigidBody = function (attachedTo, mass) {
    this.attachedTo = attachedTo;
    this.mass = mass;
    this.speedX = 0.0;
    this.speedY = 0.0;
    this.forceX = 0.0;
    this.forceY = 0.0;
    this.isGrounded = false;
};

RigidBody.prototype.applyForce = function () {
    var gAcc = -0.00001;    // Kinda low? Maybe?
    var vAcc = this.forceY / this.mass;
    var hAcc = this.forceX / this.mass;

    this.speedY += (gAcc + vAcc) * scene.elapsed;
    this.speedX += hAcc * scene.elapsed;

    var bodyPosition = this.attachedTo.getPosition();
    this.attachedTo.setPosition(bodyPosition.x + this.speedX * scene.elapsed, bodyPosition.y + this.speedY * scene.elapsed);
};

RigidBody.prototype.onGround = function () {
    this.isGrounded = true;
    this.speedY = 0.0;
};

var Collider = function (attachedTo, width, height) {
    this.attachedTo = attachedTo;
    this.w = width;
    this.h = height;
};

Collider.prototype.checkForCollision = function (other) {
    var actorPos = this.attachedTo.getPosition();
    var otherPos = other.attachedTo.getPosition();

    if (actorPos.x - this.w / 2 < otherPos.x + other.w / 2 &&
        actorPos.x + this.w / 2 > otherPos.x - other.w / 2 &&
        actorPos.y - this.h / 2 < otherPos.y + other.h / 2 &&
        actorPos.y + this.h / 2 > otherPos.y - other.h / 2) {

        var deltaX = actorPos.x - otherPos.x;
        var deltaY = actorPos.y - otherPos.y;

        if (Math.abs(deltaY) > Math.abs(deltaX)) {
            if (deltaY > 0) {
                this.attachedTo.rigidBody.onGround();
                this.attachedTo.setPosition(actorPos.x, otherPos.y + (other.h + this.h) / 2);
            } else {
                this.attachedTo.setPosition(actorPos.x, otherPos.y - (other.h + this.h) / 2);
            }
        } else {
            if (deltaX > 0) {
                this.attachedTo.setPosition(otherPos.x + (other.w + this.w) / 2, actorPos.y);
            } else {
                this.attachedTo.setPosition(otherPos.x - (other.w + this.w) / 2, actorPos.y);
            }
        }
    }
};
{'fraction_non_alphanumeric': 0.14040451552210725, 'fraction_numerical': 0.014111006585136407, 'mean_word_length': 2.066330209084355, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3046141', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1479, 'n_words': 304}