I created an Enemy vector and used push_back
twice to add two identical enemies. Inside a for loop, I created a collision system to prevent my player from going inside the enemies. However,for some reason it only works with the last enemy added.
I would like to know what should I do in order to make it work with every single enemy in that vector.
EnemyCounter = 0;
for (iter = EnemyArray.begin(); iter != EnemyArray.end(); iter++)
{
EnemyArray[EnemyCounter].update(Seconds);
window.draw(EnemyArray[EnemyCounter].CharacterSprite);
if (player.RectShape.getGlobalBounds().intersects(EnemyArray[EnemyCounter].RectShape.getGlobalBounds()))
{
if (player.LastDirection == 0) player.canMoveDown = false;
else if (player.LastDirection == 1) player.canMoveLeft = false;
else if (player.LastDirection == 2) player.canMoveRight = false;
else if (player.LastDirection == 3) player.canMoveUp = false;
}
if (!player.RectShape.getGlobalBounds().intersects(EnemyArray[EnemyCounter].RectShape.getGlobalBounds())) player.ResetCanMove();
EnemyCounter++;
}