1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| I already have the collisions done, for when the player is falling. It looks like this: [code]
public double checkBrickTop(double worldX, double worldY, double step) { if (isInsideBrick(worldX, worldY)) { double shouldBeY = worldY/10 +1 ; double diff = shouldBeY - worldY; return step - diff; } else { return step; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| if (player.getYVelocity() <= 0) { if (player.getYVelocity() <= -1) { player.setYVelocity(-1); } else { player.setYVelocity(player.getYVelocity() - 0.1); } newY = player.getWorldY() + player.getYVelocity(); if (level.isInsideBrick(player.getWorldX(), newY - (player.getHeight() + 2))) { double yTrans = level.checkBrickTop(player.getWorldX(), player.getWorldY() - player.getHeight(), player.getYVelocity()); player.setWorldY(player.getWorldY() + yTrans); System.out.println(yTrans + " " + player.getYVelocity()); player.setJumping(false); } else { player.setWorldY(newY); } } |
However, I've hit a brick wall now. I need to do roughly the same thing, but for when I hit a brick, when jumping.
Current code looks like this, but it doesn't work correctly - player gets teleported high above when brick is hit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public double checkBrickBottom(double worldX, double worldY, double step) { if (isInsideBrick(worldX, worldY)) { double shouldBeY = worldY/10 +1 ; double diff = shouldBeY - worldY; return step - diff; } else { return step; } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| if (player.getYVelocity() > 0) { player.setYVelocity(player.getYVelocity() - 0.1); } double newY = player.getWorldY() + player.getYVelocity(); if (level.isInsideBrick(player.getWorldX(), newY + 1)) { double yTrans = level.checkBrickTop(player.getWorldX(), player.getWorldY(), player.getYVelocity()); player.setWorldY(player.getWorldY() + yTrans); } else { player.setWorldY(newY); } |
It's probably something small, I just don't see it.[/code]