Mario: destroy moving objects once they leave left side of screen, remove destroyed objects from moving_objects
This commit is contained in:
parent
e283b36229
commit
a194bfb86e
@ -147,6 +147,22 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
|||||||
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
|
||||||
scene->visitCollisions( *moving_objects[i], *visitor );
|
scene->visitCollisions( *moving_objects[i], *visitor );
|
||||||
moving_objects[i]->handleVisitor( *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 ) {
|
if ( coin_count != prev_coin_count ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user