This is my first time experimenting on collision algorithm. I tried checking the rect size of an object with the boundary. Now, in this application, I made running bullets and check if the collision in a no time-delay while loop. The problem is, as I spawn around 30-40 bullets, the fps gets so low. I would be glad if someone could teach me a robust way to write collision detection.
By the way, I used a java Vector collection (Maybe the iteration is not fast enough? or my code is being too messy)
public void checkBoundary(int width, int height) //width and height of the applet
{
for(int i = 0; i < vec.size(); i++)
{
if(vec.get(i).x + vec.get(i).width <= 0 ||
vec.get(i).y + vec.get(i).height <= 0 ||
vec.get(i).x >= width ||
vec.get(i).y >= height)
vec.remove(i);
}
}
This Vector store an object of Bullet with (x,y) as bottom-left corner, and (width,height).