Hello dear JGO forumers,
I've spent the last 2 days working on slope/hills for my 2D plateformer game. I got the slope working and you can move up and down on it, but when the player starts jumping onto the slope he goes through it. I'm just wondering if this http://jnrdev.72dpiarmy.com/en/jnrdev2/ is the only way to implement slope that doesn't cause the jump bug or is it possible for the method I came up with.
This is my check slope method and it’s only called when player is moving left/right or jumping
/** Check if there's a slope and shift Y according to it */
private void checkSlope(float x, float y) {
/** If there is a slope in the next x direction do slope movement */
if(map.onSlope(x + sizeW / 2 , y + sizeH)) {
if(jumpDistance > 0 && jumping) {
py = (int)y + 1;
}
onSlope = true;
jumping = false;
/** Moving to right slope */
if(map.slopeTyle(x + sizeW / 2 , y + sizeH) == Map.SLOPE_R) {
if(left) {
moveY(-moveSpeed);
} else {
moveY(moveSpeed);
}
/** Moving to left slope */
} else {
if(right) {
moveY(-moveSpeed);
} else {
moveY(moveSpeed);
}
}
/** moving from a plateform down to the slope */
} else if(map.onSlope(x + sizeW / 2, y + 1) && !jumping) {
onSlope = true;
moveY(moveSpeed);
} else {
onSlope = false;
}
}
