import objectdraw.*;
import java.applet.AudioClip;

// class to animate the bouncing of a ball
public class Dribbler extends ActiveObject {

    // number of times to move the ball before it changes direction
    private static final int DRIBBLE_STEPS = 6;

    private static final double SPEED = 8.6; // how far to move each time
    private static final int DELAY = 35; // delay between moves

    private BBall ball;
    
    // a flag to indicate whether the dribbler is still dribbling.
    private boolean moving;
    
    public Dribbler(BBall theBall) {
        ball = theBall;
        moving = true;
        this.start();
    }
    
    // return whether the ball is still dribbling or not.
    public boolean isDribbling() {
        return moving;
    }

    // move the ball up and down, playing an audio clip
    // when the ball reaches the bottom of its cycle.
    public void run() {
        int count = 0;
        
        while (count < DRIBBLE_STEPS) {
            int dribbleSteps = 0;
            while (dribbleSteps < DRIBBLE_STEPS) {
                ball.move(0, -SPEED);
                pause(DELAY);
                dribbleSteps++;
            }
            dribbleSteps = 0;
            while (dribbleSteps < DRIBBLE_STEPS) {
                ball.move(0, SPEED);
                pause(DELAY);
                dribbleSteps++;
            }
          
            count++;
        }
        moving = false;
    }
}
