Hi. I created multiple enemies with an array like this:
for (int i = 0; i<7; i++)
{
enemies[i]->update();
//1.example
if (enemies[i]->rect.getGlobalBounds().intersects(sprite.getGlobalBounds())) {
//COLLISION
}
//2.example
if (enemies[1]->rect.getGlobalBounds().intersects(enemies[2]->rect.getGlobalBounds()) ) {
//COLLISION
}
}
if i want to detect collision between sprite and enemies collision works like example 1. and i can do that for different enemies at second example. Should i write this codes again for all different enemies like
(1)→intersects(2)
(1)→intersects(3) ….. 4,5,6..
or is there any simple way to detection all enemies collision for each others? I need easier way to do that because sometimes i have to create enemies more than 10 - 20
I tried a code like this but it doesnt work :/
if (enemies[i]->rect.getGlobalBounds().intersects(enemies[i]->rect.getGlobalBounds()) ) {
}
Thanks for every help and advice.