1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public void act() { time = time + 1 ; if (time <= 150 ){ move( 0 ); } else { setLocation (Greenfoot.getRandomNumber(),getY()+dy); if (getY() >= getWorld().getHeight() - 1 ){ dy = - 5 ; Greenfoot.playSound( "button-14.wav" ); } if (getX() >= getWorld().getWidth() - 1 ){ Greenfoot.setWorld ( new space()); } if (getY() <= 20 ){ dy = 5 ; Greenfoot.playSound( "button-14.wav" ); } if (getX() <= 20 ){ Greenfoot.setWorld ( new space()); } if (isTouching(P1. class )){ dx = -dx; dy = dy- 1 ; Greenfoot.playSound( "button-3.wav" ); } if (isTouching(P2. class )){ dx = -dx; dy = dy- 1 ; Greenfoot.playSound( "button-9.wav" ); } } } } |
