title: Collision Detection with MANY objects
body: <p>I mainly focused on the Graphics aspects to create a little 2DGame. I've watched/looked at several tutorials but none of them were that pleasing. I already have a player(a square) moving and colliding with other squares on the screen. Gravity etc. Are also done.</p>
  
  <p>If there are only that much objects as seen on the screen (30*20), everything works perfectly fine. But if I increase it to let's say 300*300 the program starts to run very slow since it has to check for so many objects.</p>
  
  <p>I really don't get how games like Minecraft can work with ALL THOSE blocks and my program already gives up on 300*300 blocks.</p>
  
  <p>I already tried to ONLY check for collisions when the objects are visible, but that leads to the program checking every single object for it's visibility leading to the same problem.
  What am I doing wrong? Help appreciated.</p>
  
  <p>I'll post some code on how I handle the collisions.</p>
  
  <pre><code>player.collision(player, wall);
  
  public void collision(Tile object1, Tile[] object2){
      collisionCheckUp(object1, object2);
      collisionCheckDown(object1, object2);
      collisionCheckLeft(object1, object2);
      collisionCheckRight(object1, object2);  
  }
  
  public void collisionCheckDown(Tile object1, Tile[] object2){
  
      for (int i = 0; i &lt; Map.tileAmount; i++){
          if(object2[i] != null &amp;&amp; object2[i].visible)
          {
              if(object1.isCollidingDown(object2[i])){
                  object1.collisionDown = true;
                  return;
              }
  
          }
      }       
      object1.collisionDown = false;
  }
  
  public void compileHullDown(){
  
       collisionHull = new Rectangle((int)x+3, (int)y+3, width-6, height);
  }
  
  int wallCount = 0;
      for (int x=0;x&lt;Map.WIDTH;x++) {
          for (int y=0;y&lt;Map.HEIGHT;y++) {
  
              if (Map.data[x][y] == Map.BLOCKED) {
                  wall[wallCount] = new Tile(x * Map.TILE_SIZE, y *  Map.TILE_SIZE);
                  wallCount++;
              }
          }
      }
  </code></pre>