The vector of enemies always has enemyArray.size() enemies. For example:
{ e0, e1, e2, e3, e4, e5, e6 } : seven enemies
But your original question was how to only look at the first 5 enemies:
{
e0, e1, e2, e3, e4, e5, e6 }
The enemies beyond the first five are still there. So if you delete one of the first five:
{ e0, e2, e3, e4, e5, e6 }
One of the other enemies will now be in position as one of the first five:
{
e0, e2, e3, e4, e5, e6 }
Maybe I misunderstood your original question. Do you want to make sure that there are never more than five enemies total?
Do that by only spawning new enemies when there is room.
1 2 3 4 5
|
if (enemyArray.size() < 5)
{
enemy new_enemy = ...;
enemyArray.push_back(new_enemy);
}
|
Then you don't need the code to limit a loop to N elements:
1 2 3 4 5
|
for (auto& enemy : enemyArray)
{
enemy.update();
...
}
|
Hope this helps.