import objectdraw.*;

import java.awt.Color;


/**
 * A class to make a Basketball bounce up and down a
 * bunch of times.
 */
public class Bouncer extends ActiveObject {
    // how many balls to bounce
    private static final int BOUNCES = 5;

    // speed and acceleration of ball motion
    private static final double INITSPEED = -3;
    private static final double GRAVITY = .125;

    // length of pauses between moving a ball
    private static final int STEPDELAY = 30;

    // length of pause between picking balls to bounce
    private static final int BOUNCEDELAY = 250;

    // the ball to bounce
    private BBall ball;

    public Bouncer(BBall theBall) {
        ball = theBall;
        this.start();
    }

    // animate the bounce.  The ball starts going up and slows down
    // on each iteration of the loop.  When it reaches the negative of
    // its original velocity, it will be back to where it started.
    public void run() {
        
        for (int count = 0; count < BOUNCES; count++) {
            
            for (double velocity = INITSPEED; 
                 velocity <= -INITSPEED;
                 velocity = velocity + GRAVITY) {
                     
                ball.move(0, velocity);
                pause(STEPDELAY);
                
            }
        }
    }
}
