diff --git a/mario/main.cpp b/mario/main.cpp index 2662f45..ac1785c 100644 --- a/mario/main.cpp +++ b/mario/main.cpp @@ -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 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 ) {