Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public boolean push(Direction dir) throws IllegalMoveException{
  2.  
  3. Position pos = owner.getPosition(this);
  4.  
  5. if(dir == Direction.EAST){
  6.  
  7. // Get the object in the tile to the right
  8. Position rightPos = pos.moveDirection(Direction.EAST);
  9. IBDObject rightObj = owner.get(rightPos);
  10.  
  11. // Move one step to the right if tile is empty
  12. if (rightObj instanceof BDEmpty && !(rightObj instanceof BDSand)) {
  13. prepareMoveTo(Direction.EAST);
  14.  
  15. audio = new Audio("rockPush");
  16. audio.playSound(); // plays sound
  17. super.step();
  18. return true;
  19. }
  20. }
  21.  
  22. if(dir == Direction.WEST){
  23.  
  24. // Get the object in the tile to the left
  25. Position leftPos = pos.moveDirection(Direction.WEST);
  26. IBDObject leftObj = owner.get(leftPos);
  27.  
  28. // Move one step to the left if tile is empty
  29. if (leftObj instanceof BDEmpty && !(leftObj instanceof BDSand)) {
  30. prepareMoveTo(Direction.WEST);
  31. audio = new Audio("rockPush");
  32. audio.playSound(); // plays sound
  33. super.step();
  34. return true;
  35. }
  36.  
  37. }
  38. return false;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement