Let's say that I have code like this:
private void actuallyDrawGraphics(Canvas canvas) {
canvas.drawColor(Color.WHITE);
for(Ball ball : balls){
canvas.drawBitmap(ballBitmap,
-16 + (ball.x / 100f) * canvas.getWidth(),
-16 + (ball.y / 100f) * canvas.getHeight(),
paint
);
}
}
Every ball is registered in an array. I need to make a collision (when one collides with the second) and everything goes well, until I have more balls, for example 10. It's not efficient to make a check like:
ball 1 with 2, 3, 4...
ball 2 with 1, 3, 4...
Is there any way that this can be done?