Mario: destroy moving objects once they leave left side of screen, remove destroyed objects from moving_objects

This commit is contained in:
zvon 2021-08-07 22:10:09 +02:00
parent e283b36229
commit a194bfb86e

View File

@ -147,6 +147,22 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
scene->visitCollisions( *moving_objects[i], *visitor );
moving_objects[i]->handleVisitor( *visitor );
auto rightmost_pos = moving_objects[i]->getAbsolutePos().getX() +
moving_objects[i]->getDoubleRect().second.getX();
if(rightmost_pos < 0) {
moving_objects[i]->destroy();
std::cout << "DESTRUCTION!!!!" << std::endl;
}
}
std::vector<uint64_t> killed_indices{};
for(size_t i = 0; i < moving_objects.size(); i++) {
if(moving_objects[i]->getKilled()) {
killed_indices.push_back(i);
}
}
std::reverse( killed_indices.begin(), killed_indices.end() );
for(auto &index : killed_indices) {
moving_objects.erase(moving_objects.begin() + index);
}
if ( coin_count != prev_coin_count ) {