Skip to content

Commit

Permalink
Merge pull request #592 from pawurb/smoothier_collisions
Browse files Browse the repository at this point in the history
Gravity collision detected only on top.
  • Loading branch information
starwed committed Nov 13, 2013
2 parents cbf5c0d + 90e153d commit afabe59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ Crafty.c("Gravity", {
*/
gravity: function (comp) {
if (comp) this._anti = comp;
if(isNaN(this._jumpSpeed)) this._jumpSpeed = 0; //set to 0 if Twoway component is not present

this.bind("EnterFrame", this._enterFrame);

Expand Down Expand Up @@ -1108,8 +1109,10 @@ Crafty.c("Gravity", {
}
}

if (hit) { //stop falling if found
if (this._falling) this.stopFalling(hit);
if (hit) { //stop falling if found and player is moving down
if (this._falling && ((this._gy > this._jumpSpeed) || !this._up)){
this.stopFalling(hit);
}
} else {
this._falling = true; //keep falling otherwise
}
Expand Down
8 changes: 6 additions & 2 deletions src/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,16 @@ Crafty.c("Twoway", {
});

if (speed) this._speed = speed;
if (arguments.length < 2) jump = this._speed * 2;
if (arguments.length < 2){
this._jumpSpeed = this._speed * 2;
} else{
this._jumpSpeed = jump;
}

this.bind("EnterFrame", function () {
if (this.disableControls) return;
if (this._up) {
this.y -= jump;
this.y -= this._jumpSpeed;
this._falling = true;
}
}).bind("KeyDown", function (e) {
Expand Down

0 comments on commit afabe59

Please sign in to comment.