So I made this game where you need to click on the ball that the eyes are following. and I when you click on the right ball i want more balls to appear. However, when i change numBalls to a higher number i get an error. When i change it to a smaller number there are no problems. No idea how to go about this.
float bx = random (500);
float by = random (500);
float ballSpeedX = random (2.0,4.0);
float ballSpeedY = random (2.0,4.0);
int numBalls = 3;
Ball[] balls = new Ball[numBalls];
void setup ()
{
size (500,500);
for (int i = 0; i < numBalls; i++) {
balls[i] = new Ball(random(width), random(height), 20, i, balls, random (2.0,4.0), random (2.0,4.0));
}
}
void draw ()
{
smooth ();
background (0);
face ();
for (int i = 0; i<numBalls; i++) {
balls[i].move();
balls[i].display();
println (i);
}
ball ();
levels ();
}
void ball ()
{
bx += ballSpeedX;
by += ballSpeedY;
if (bx>width || bx<0) {ballSpeedX = ballSpeedX * -1;}
if (by>height || by<0) {ballSpeedY = ballSpeedY * -1;}