Advertisement
dermetfan

collision for vavere

Jun 12th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public void update() {
  2.     // your other update stuff
  3.  
  4.     float oldX = x;
  5.     float oldY = y;
  6.  
  7.     // everything that changes the position
  8.  
  9.     if(collides(x, y) || collides(x + playerWidth, y)) // check the feet
  10.         x = oldX;
  11.     if(collides(x, y) || collides(x, y + playerHeight)) // check the sides
  12.         y = oldY;
  13. }
  14.  
  15. /**
  16.  * @return if this {@link Player} collides with the TiledMap environment at the given position
  17.  * @param x the x position
  18.  * @param y the y position
  19.  */
  20. public boolean collides(float x, float y) {
  21.     return !layer.getCell((int) x, (int) y).getTile().getProperties().get("passable", Boolean.class);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement