for (int i = 0; i < shots.size(); i++) // This "something" is the number of objects in the "shots" arraylist.
{
Shot shot = (Shot) shots.get(i);
shot.display();
shot.move();
// This will be another for-loop nested inside of the above for-loop.
// This new for-loop will test and resolve collisions between the
// asteroids and the bullets.
for (int j = 0; j < 12; j++) // This "something" is the number of asteroids that exist in your asteroids array.
{
// if the shot collides with the asteroid...
if(shot.shape.isInside(asteroid[i].shape))
{
shots.remove(j);
asteroid[j].reset();
score+=5;
}
}
}
}
here is the shot class:
class Shot
{
Shape shape;
Shot(Loc center, float direction, AudioSample player) {
Loc shotCenter = new Loc(center.x, center.y);
Loc[] points = new Loc[3];
points[0]= new Loc(center.x, center.y-1);
points[1]= new Loc(center.x+1, center.y-1);
points[2]=new Loc(center.x-1, center.y+1);
shape = new Shape(shotCenter, points, direction);
shape.restart=false;