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


/**
 * Create an array of basketballs and bounce them,
 * but only create balls when you click.
 */
public class BBallArray extends WindowController {
    
    private int MAX_BALLS = 10;
    private int BALL_X = 20;
    private int BALL_Y = 200;
    private int BALL_STEP = 30;
    private int BALL_SIZE = 20;
    
    private double ballLeft = BALL_X;

    
    private BallCollection balls;
    
    public void begin() {
        balls = new BallCollection();
    }
    
    /*
     * If there is space left in the array, add a new ball. 
     */
    public void onMouseMove(Location pt) {
        if (ballLeft < canvas.getWidth()) {
            BBall ball = new BBall(ballLeft,
                                           BALL_Y,
                                           BALL_SIZE,
                                           canvas);
            balls.add(ball);
            
            ballLeft = ballLeft + BALL_STEP; // adjust where next ball goes
        }
    }
    

    public void onMouseClick(Location point) {
        BBall ball = balls.selectedBall(point);
        if (ball != null) {
            new Bouncer(ball);
        } else {
            new Bouncer(balls.pickRandomly());
        }
    }

}
