import objectdraw.*;

import java.awt.*;

/*
 * One falling leaf, represented as an ActiveObject that
 * will gradually move a leaf image down the screen.
 */
public class FallingLeaf extends ActiveObject {

  private static final int DELAY_TIME = 33; // delay between leaf motions

  // lowest point in window
  private int screenHeight; 

  // speed of fall
  private double yspeed; 

  // the leaf
  private VisibleImage leaf; 

  // construct leaf and put at top of screen at x from left
  public FallingLeaf(DrawingCanvas canvas, Image leafpic, double x,
                     double speed, int aScreenHeight) {

    leaf = new VisibleImage(leafpic, 0, 0, canvas);
    leaf.move(x, -leaf.getHeight());

    yspeed = speed;
    screenHeight = aScreenHeight;

    this.start();
  }

  // Leaf falls to ground
  public void run() {

    while (leaf.getY() < screenHeight) {
      pause(DELAY_TIME);
      leaf.move(0, yspeed);
    }

    leaf.removeFromCanvas();
  }
}
