Hi guys,
I just a few days ago started to program my own top-down shooter game. However, while programming the destroying of enemies and bullets on collision with each other I have run into some errors:
Debug assertion failed!
...
Expression: ("this->_Has_container()", 0)
...
I believe this is to do with the code:
for(std::vector<Player>::iterator i = enemies.begin(); i != enemies.end(); i++) {
for(std::vector<Particle>::iterator j = bullets.begin(); j < bullets.end(); j++) {
if((*i).ALIVE() && (*j).ALPHA() > 0.0f) {
if((*j).X() > (*i).X() -(*i).W()/2 && (*j).X() < (*i).X() + (*i).W()/2
&& (*j).Y() > (*i).Y() - (*i).H()/2 && (*j).Y() < (*i).Y() + (*i).H()/2) {
if(enemies.size() > 1) {
std::swap(*i, *(enemies.rbegin()));
}
enemies.pop_back();
if(bullets.size() > 1) {
std::swap(*j, *(bullets.rbegin()));
}
bullets.pop_back();
}
}
}
}
Please please help!!!
Note: I add new elements to the vectors (enemies) and (bullets) at the beginning, not the end.
The idea of that code was to loop through checking for collisions of enemies with bullets, and if they collide, move them to the end of the vector and erase them.
The error occurs whenever my bullets hit the enemies.