title: Processing - Array index out of bounds error
body: <p>I'm trying to use an array of objects to have barrels fall from the top of the screen to the bottom. (Like that old donkey kong game.) However, I can't seem to find a way to create more instances of the object than whatever the initial length of the array was. Anyone know a way to do this?</p>
  <p>Here's the code:</p>
  <pre><code>Man Man;
  Man background;
  Man ladders;
  PFont font1;
  int time;
  boolean run;
  boolean newBarrel;
  int barrelTotal;
  Barrel[] barrel = new Barrel[100];
  void setup() {
    newBarrel = false;
    run = true;
    barrelTotal = 1;
    time = millis();
    size(800, 800);
    Man = new Man();
    background = new Man();
    ladders = new Man();
    for (int i = 0; i &lt; barrel.length; i++) {
      barrel[i] = new Barrel();
    }
  }
  void draw() {
    if (run == true) {
      for (int i = 0; i &lt; barrel.length; i++) {
        if ((Man.bottom-10 &gt;= barrel[i].top)&amp;&amp;(Man.bottom-10 &lt;= barrel[i].bottom)&amp;&amp;(Man.Ladder == barrel[i].randomLadder)) {
          print(&quot;GAME OVER!&quot;);
          run = false;
        }
        if ((Man.top &gt;= barrel[i].top)&amp;&amp;(Man.top &lt;= barrel[i].bottom)&amp;&amp;(Man.Ladder == barrel[i].randomLadder)) {
          print(&quot;GAME OVER!&quot;);
          run = false;
        }
      }
    }
    if (run == true) {
      background.createBackground();
      Man.ladders();
      Man.movement();
      Man.createMan();
      //spawns a barrel every second
      if (millis()&gt; time + 10) {
        newBarrel = false;
        print(&quot;     &quot; + barrelTotal + &quot;        &quot;);
        time = time + 10;
        barrelTotal = barrelTotal+1;
        newBarrel = true;
      }
      for (int i = 0; i &lt; barrelTotal; i++) {
        if (newBarrel == true) {
        }
        barrel[i].gravity();
        barrel[i].createBarrel();
      }
      //if(barrelTotal == 100){
      //for (int i = 0; i &lt; 50; i++){
      // barrel[i] = &quot;???&quot;;
      //}
      //}
    }
  }
  </code></pre>