I am attempting to check collision between two objects. First is the shape passed to my function, second is the map containing one of the many sprites I've loaded into them. The problem I am having is the function only ever checks against the first element. I need to function to check if the ball has collided with a valid item of the map, which one it has collided with, report true then move onto direction change. Here is the function so far:
bool bounceCheck(const sf::CircleShape& object1, map<int, sf::Sprite>& sprite){
// returns true if a ball collides with an element of the map
for (map<int, sf::Sprite>::iterator it = sprite.begin(); it != sprite.end(); it++){
search.push_back(it->second.getGlobalBounds());
if (object1.getGlobalBounds().intersects(search[it->first])){
cout << "Collided with " << it->first << endl;
return true;
}
}
return false;
}
I am assinging integers to the sprites I have loaded into my map for easy referal. Search is a vector I created to add each sprites bounds. Im guessing my logic isnt quite right somehow. Any help?