-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Fix problem with ladder
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,6 +487,14 @@ | |
* @name me.ObjectEntity#onladder | ||
*/ | ||
this.onladder = false; | ||
/** | ||
* equal true if the entity can go down on a ladder<br> | ||
* (!) READ ONLY property | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* @public | ||
* @type Boolean | ||
* @name me.ObjectEntity#disableTopLadderCollision | ||
*/ | ||
this.disableTopLadderCollision = false; | ||
|
||
// to enable collision detection | ||
this.collidable = settings.collidable || false; | ||
|
@@ -659,6 +667,7 @@ | |
if (this.onladder) { | ||
this.vel.y = (up) ? -this.accel.x * me.timer.tick | ||
: this.accel.x * me.timer.tick; | ||
this.disableTopLadderCollision = !up; | ||
return true; | ||
} | ||
return false; | ||
|
@@ -847,85 +856,86 @@ | |
updateMovement : function() { | ||
|
||
this.computeVelocity(this.vel); | ||
|
||
// Adjust position only on collidable object | ||
if (this.collidable) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// check for collision | ||
var collision = this.collisionMap.checkCollision(this.collisionBox, this.vel); | ||
|
||
// check for collision | ||
var collision = this.collisionMap.checkCollision(this.collisionBox, this.vel); | ||
|
||
// update some flags | ||
this.onslope = collision.yprop.isSlope || collision.xprop.isSlope; | ||
// clear the ladder flag | ||
this.onladder = false; | ||
|
||
// update some flags | ||
this.onslope = collision.yprop.isSlope || collision.xprop.isSlope; | ||
// clear the ladder flag | ||
this.onladder = false; | ||
|
||
|
||
// y collision | ||
if (collision.y) { | ||
|
||
// going down, collision with the floor | ||
this.onladder = collision.yprop.isLadder; | ||
// y collision | ||
if (collision.y) { | ||
// going down, collision with the floor | ||
this.onladder = collision.yprop.isLadder || collision.yprop.isTopLadder; | ||
|
||
if (collision.y > 0) { | ||
if (collision.yprop.isSolid || (collision.yprop.isPlatform && (this.collisionBox.bottom - 1 <= collision.ytile.pos.y))) { | ||
// adjust position to the corresponding tile | ||
this.pos.y = ~~this.pos.y; | ||
this.vel.y = (this.falling) ?collision.ytile.pos.y - this.collisionBox.bottom: 0 ; | ||
this.falling = false; | ||
} | ||
else if (collision.yprop.isSlope && !this.jumping) { | ||
// we stop falling | ||
this.checkSlope(collision.ytile, collision.yprop.isLeftSlope); | ||
this.falling = false; | ||
} | ||
else if (collision.yprop.isBreakable) { | ||
if (this.canBreakTile) { | ||
// remove the tile | ||
me.game.currentLevel.clearTile(collision.ytile.col, collision.ytile.row); | ||
if (this.onTileBreak) | ||
this.onTileBreak(); | ||
} | ||
else { | ||
if (collision.y > 0) { | ||
if (collision.yprop.isSolid || (collision.yprop.isPlatform && (this.collisionBox.bottom - 1 <= collision.ytile.pos.y)) || (collision.yprop.isTopLadder && !this.disableTopLadderCollision)) { | ||
This comment has been minimized.
Sorry, something went wrong.
parasyte
|
||
// adjust position to the corresponding tile | ||
this.pos.y = ~~this.pos.y; | ||
this.vel.y = (this.falling) ?collision.ytile.pos.y - this.collisionBox.bottom: 0; | ||
this.vel.y = (this.falling) ?collision.ytile.pos.y - this.collisionBox.bottom: 0 ; | ||
this.falling = false; | ||
} | ||
else if (collision.yprop.isSlope && !this.jumping) { | ||
// we stop falling | ||
this.checkSlope(collision.ytile, collision.yprop.isLeftSlope); | ||
this.falling = false; | ||
} | ||
else if (collision.yprop.isBreakable) { | ||
if (this.canBreakTile) { | ||
// remove the tile | ||
me.game.currentLevel.clearTile(collision.ytile.col, collision.ytile.row); | ||
if (this.onTileBreak) | ||
this.onTileBreak(); | ||
} | ||
else { | ||
// adjust position to the corresponding tile | ||
this.pos.y = ~~this.pos.y; | ||
this.vel.y = (this.falling) ?collision.ytile.pos.y - this.collisionBox.bottom: 0; | ||
this.falling = false; | ||
} | ||
} | ||
} | ||
} | ||
// going up, collision with ceiling | ||
else if (collision.y < 0) { | ||
if (!collision.yprop.isPlatform && !collision.yprop.isLadder) { | ||
this.falling = true; | ||
// cancel the y velocity | ||
this.vel.y = 0; | ||
// going up, collision with ceiling | ||
else if (collision.y < 0) { | ||
if (!collision.yprop.isPlatform && !collision.yprop.isLadder && !collision.yprop.isTopLadder) { | ||
this.falling = true; | ||
// cancel the y velocity | ||
this.vel.y = 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// x collision | ||
if (collision.x) { | ||
// x collision | ||
if (collision.x) { | ||
|
||
this.onladder = collision.xprop.isLadder ; | ||
this.onladder = collision.xprop.isLadder || collision.yprop.isTopLadder; | ||
|
||
if (collision.xprop.isSlope && !this.jumping) { | ||
this.checkSlope(collision.xtile, collision.xprop.isLeftSlope); | ||
this.falling = false; | ||
} else { | ||
// can walk through the platform & ladder | ||
if (!collision.xprop.isPlatform && !collision.xprop.isLadder) { | ||
if (collision.xprop.isBreakable && this.canBreakTile) { | ||
// remove the tile | ||
me.game.currentLevel.clearTile(collision.xtile.col, collision.xtile.row); | ||
if (this.onTileBreak) { | ||
this.onTileBreak(); | ||
if (collision.xprop.isSlope && !this.jumping) { | ||
this.checkSlope(collision.xtile, collision.xprop.isLeftSlope); | ||
this.falling = false; | ||
} else { | ||
// can walk through the platform & ladder | ||
if (!collision.xprop.isPlatform && !collision.xprop.isLadder && !collision.xprop.isTopLadder) { | ||
if (collision.xprop.isBreakable && this.canBreakTile) { | ||
// remove the tile | ||
me.game.currentLevel.clearTile(collision.xtile.col, collision.xtile.row); | ||
if (this.onTileBreak) { | ||
this.onTileBreak(); | ||
} | ||
} else { | ||
this.vel.x = 0; | ||
} | ||
} else { | ||
this.vel.x = 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
// update player position | ||
this.pos.add(this.vel); | ||
|
||
|
4 comments
on commit ec15bf7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very very much, and using "?w=1", the commit is much more clear :)
Just one last question, why did you remove the test on '(pv.y != 0)' in TMXLayer ?
If y === 0, the following code will be executed for nothing ?
I can't wait now to see xrick2 running in my browser :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parasyte (+1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a deep analysis on the and other issue that I would like to work on, it seems to be related to my game and the collision detection system.
It solved my problem (I'm in the case of melonjs#50) with my tile but as suggested in issue melonjs#169, melonjs#103, melonjs#50 & melonjs#16, the collision detection system should be rewritten to take care as you suggest the collision rectangle box instead of only some point.
In conclusion just leave the two lines from TMXLayer that I deleted until someone (maybe me, who knows) will rewrite the collision process.
If you have any suggestion between the four issues I listed to do the fix, I'd like to read it and I will try to implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I have to catch a fight right now, but quickly and for tile based collision, what I had in mind was either rewriting it using chipmunk (not to name it) as each square can anyway be "converted" , OR used a better SAT approach, as nicely explained in the following article :
But ultimately I guess a combination of the two would probably be the best with chipmunk being optional through a plugin (still under discussion)
Please use
@readonly
here. That will mark the property as read-only in the JSDoc output. :D