Sorry if what I write seems a bit odd, I’m trying to answer you from a phone. Anyways, what I Tend to do is have an Arraylist for the Bullets and another one for the ships.
So first things first we create them:
public ArrayList<YourShipClass> shipList;
Public ArrayList<YourBulletClass> bulletList;
Then make sure to instantiate your ArrayLists or you will get a Null Pointer Exception.
shipList = new ArrayList<>();
bulletList = new ArrayList<>();
You can add objects to an ArrayList like so (for when you press space for your bullets):
bulletList.add(new Bullet());
Doing the same with the ships, you can then check for collision between the bullets and the ships by constantly looping through both the lists.
for(Iterator<YourShipClass> shipIter = shipList.iterator; shipIter.hasNext();){
YourShipClass ship = shipIter.next();
for(Iterator<YourBulletClass> bulletIter = bulletList.iterator; bulletIter.hasNext();){
YourBulletClass bullet = bulletIter.next();
If (bullet intersects with ship){
bulletIter.remove(); // Removes the bullet that collided
ship.blowTheFuckUp();
}
}
}
Again, sorry for any unreadable sections or bad syntax, its quite hard to type on the phone.
Oh, and don’t use what I say permanently I’m a noob as well and am only showing you what has worked for me so far. If there’s anything I’ve learned from programming is that there’s almost always room for improvement.