import objectdraw.ActiveObject;
import objectdraw.Drawable2DInterface;

// FallingObject class to encapsulate the behavior of ActiveObjects that
// fall until they reach a certain y-position then disappear
public class FallingObject extends ActiveObject {

        protected static final int DELAY_TIME = 33;

        protected int fallToPos;

        protected double ySpeed;

        protected Drawable2DInterface object;

        // Parameters: thePos - how far down the object should fall
        //             theSpeed - how far to fall each time around
        public FallingObject(int thePos, double theSpeed) {
                ySpeed = theSpeed;
                fallToPos = thePos;
        }

        public void run() {
                while (object.getY() < fallToPos) {
                        pause(DELAY_TIME);
                        object.move(0, ySpeed);
                }
                this.hitBottom();
        }

        // default "hit bottom" behavior - may be overridden
        protected void hitBottom() {
                object.removeFromCanvas();
        }
}
