Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean push(Direction dir) throws IllegalMoveException{
- Position pos = owner.getPosition(this);
- if(dir == Direction.EAST){
- // Get the object in the tile to the right
- Position rightPos = pos.moveDirection(Direction.EAST);
- IBDObject rightObj = owner.get(rightPos);
- // Move one step to the right if tile is empty
- if (rightObj instanceof BDEmpty && !(rightObj instanceof BDSand)) {
- prepareMoveTo(Direction.EAST);
- audio = new Audio("rockPush");
- audio.playSound(); // plays sound
- super.step();
- return true;
- }
- }
- if(dir == Direction.WEST){
- // Get the object in the tile to the left
- Position leftPos = pos.moveDirection(Direction.WEST);
- IBDObject leftObj = owner.get(leftPos);
- // Move one step to the left if tile is empty
- if (leftObj instanceof BDEmpty && !(leftObj instanceof BDSand)) {
- prepareMoveTo(Direction.WEST);
- audio = new Audio("rockPush");
- audio.playSound(); // plays sound
- super.step();
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement