コード例 #1
0
  /** Move this ball according to its position and speed and redraw. */
  public void move() {
    // remove from canvas at the current position
    erase();

    // compute new position
    ySpeed += GRAVITY;
    yPosition += ySpeed;
    xPosition += 2;

    // check if it has hit the ground
    if (yPosition >= (groundPosition - diameter) && ySpeed > 0) {
      yPosition = (int) (groundPosition - diameter);
      ySpeed = -ySpeed + ballDegradation;
    }

    // draw again at new position
    draw();
  }