I have an android game which involves a ship shooting enemies. I am trying to make it so that if the enemies are within a certain distance of the ammos, then the enemys remove themselves from the screen. I have attempted to do it and the code compiles, but i am unsure why the enemys arent being removed from the screen once been hit. Can anyone see anything wrong with the code below? Thankyou
for (TopEnemy i : newTopEnemy)
{
for (int q = 0; q < ammo.length; q++)
{
float xsubs = i.enemyX - ammo[q].positionX;
float ysubs = i.enemyY - ammo[q].positionY;
float squared = (xsubs * xsubs) + (ysubs * ysubs);
float distance = (float)Math.sqrt(squared);
if (distance < 10.0)
{
newTopEnemy.remove(q);
}
}
}