Slow collision detection using bounding box
<p>I have small library i want to use for creating games. First, i tried to implement pixel perfect collision detection, but that did not went well, so i decided to use simple bounding box collision detection. It works fine, but after amount of objects exceeds around 20, it starts slowing down. Here is my code:
(Runs in loop, 25 times per second)</p>

<pre><code>for (int i=0;i&lt;sc.collGr.size();i++){
    CollisionGroup gr=sc.collGr.get(i);
    Collidable[] cc=gr.getCollidables();
    for (int l=0;l&lt;cc.length;l++){
        for (int w=l+1;w&lt;cc.length;w++){
            if (BorderBox.areColliding(cc[l].getBorderBox(), cc[w].getBorderBox()){
                addEventToHandler(sc.collGr.get(i),cc[l],cc[w]);
            }
        }
   }
}
</code></pre>

<p>part of BorderBox class:</p>

<pre><code>public class BorderBox {
int top;
int down;
int left;
int right;

/**
 * Creates new BorderBox object
 * Arguments: (top, down, left, right);
 * */
public BorderBox(int topy,int downy, int leftx,int rightx){
    top=topy;
    down=downy;
    left=leftx;
    right=rightx;
}

/**
 * Checks if two provided BorderBoxes are colliding.
 * */
public static boolean areColliding(BorderBox a,BorderBox b){
    if (b.left&lt;=a.right &amp;&amp; b.right&gt;=a.left &amp;&amp; b.down&gt;=a.top &amp;&amp; b.top&lt;=a.down){
        return true;
    }
    return false;
}
</code></pre>
