ArrayList Problems / get() & remove()

It’s going to be easy to remove the bullets that hit from your ArrayList because an ArrayList is specifically designed to allow you to remove elements from it.

Removing a single Alien from an Array of Aliens is not going to be as easy.

So… why are you using an Array of Aliens, instead of an ArrayList of them? You don’t actually need space for 1000 aliens at a time. Just a few that are on the screen.

Anyway, I’m getting ahead of myself. You want to do collisions. You need to check - for each alien - if any bullet is hitting it.

Thus you will first need to loop over every alien.

for ( each alien ){

Then you will need to loop ove each bullet.

  for( each bullet ) {

Then you need to see if those collide.

if( alien.collides( bullet ) ){

If so, you remove that alien and that bullet.


When is a round bullet colliding with a round alien? Basically, when are two circles intersecting? What can you say about the distance between their centers in relationship to the sum of their radii?


You might see this thread I posted recently: