Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void update() {
- // your other update stuff
- float oldX = x;
- float oldY = y;
- // everything that changes the position
- if(collides(x, y) || collides(x + playerWidth, y)) // check the feet
- x = oldX;
- if(collides(x, y) || collides(x, y + playerHeight)) // check the sides
- y = oldY;
- }
- /**
- * @return if this {@link Player} collides with the TiledMap environment at the given position
- * @param x the x position
- * @param y the y position
- */
- public boolean collides(float x, float y) {
- return !layer.getCell((int) x, (int) y).getTile().getProperties().get("passable", Boolean.class);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement