import objectdraw.*;
import java.awt.*;

/*
 * 
 * Example FallingSnow: the snowflakes that fall
 *
 * Jim Teresco, Siena College, CSIS 120, Fall 2011
 * Based on example from CSCI 134, Williams College
 *
 * $Id: FallingSnow.java 1576 2011-03-24 04:32:40Z terescoj $
 */

public class FallingSnow extends ActiveObject {

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

    private DrawingCanvas canvas;

    // speed of fall
    private double ySpeed;

    // the snowflake
    private VisibleImage snow;

    // initialize the instance variables and start the active object
    public FallingSnow(DrawingCanvas aCanvas, Image aSnowPic,
                       double x, double aSpeed) {
        canvas = aCanvas;
        ySpeed = aSpeed;

        snow = new VisibleImage(aSnowPic, 0, 0, canvas);
        snow.move(x, - snow.getHeight());

        start();
    }

    public void run() {

        // as long as the snow is still on the screen
        // move it and pause
        while (snow.getY() < canvas.getHeight()) {
            pause(DELAY_TIME);
            snow.move(0,ySpeed);
        }

        snow.removeFromCanvas();
    }

}