Advertisement
staxx6

Untitled

May 22nd, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1.        public void moveLeft(){
  2.             x -= speed;
  3.                 if(isCollision(player)) {
  4.                     x += speed + 1;
  5.                 }
  6.                 /*
  7.                 for (Rectangle v : myArr) {
  8.                         if (player.getX()>v.getX()+v.getWidth()) {
  9.                                         x -= speed;
  10.                         }
  11.                 }
  12.                 */
  13.         }
  14.        
  15.        
  16.         public void moveRight(){
  17.             x += speed;
  18.                 if(isCollision(player)) {
  19.                     x -= speed + 1;
  20.                 }
  21.                 /*
  22.                 for (Rectangle v : myArr) {
  23.                         if (player.getX()+player.getWidth()<v.getX()) {
  24.                                         x += speed;
  25.                         }
  26.                 }
  27.                 */
  28.         }
  29.        
  30.         private boolean isCollision(Rectangle object) {
  31.             boolean collision = false;
  32.            
  33.             for(Rectangle rectangle : myArr) {
  34.                 if(object.intersects(rectangle)) {
  35.                     collision = true;
  36.                     break;
  37.                 }
  38.             }
  39.            
  40.             return collision;
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement