Exemplo n.º 1
0
  protected void moveBall() {
    // System.out.println("I'm in the moveBall() function!");
    int width = getWidth();
    int height = getHeight();
    int min, max, randomX, randomY;
    min = 0;
    max = 200;
    randomX = min + (int) (Math.random() * ((max - min) + 1));
    randomY = min + (int) (Math.random() * ((max - min) + 1));
    // System.out.println(randomX + ", " + randomY);

    Rectangle ballBounds = ball.getBounds();
    //      //System.out.println(ballBounds.x + ", " + ballBounds.y);
    //      if (ballBounds.x + randomX < 0) {
    //          randomX = 200;
    //      } else if (ballBounds.x + ballBounds.width + randomX > width) {
    //          randomX = -200;
    //      }
    //      if (ballBounds.y + randomY < 0) {
    //          randomY = 200;
    //      } else if (ballBounds.y + ballBounds.height + randomY > height) {
    //          randomY = -200;
    //      }

    ballBounds.x = randomX;
    ballBounds.y = randomY;
    _ballXpos = ballBounds.x;
    _ballYpos = ballBounds.y;
    ball.setFrame(ballBounds);
    thePlacebo.repaint();
  }