Mario: loop through all moving objects in doInput

This commit is contained in:
zvon 2021-08-07 21:38:00 +02:00
parent 6238022ed2
commit 7cb3f95e44

View File

@ -135,17 +135,18 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
FPSmanager gFPS;
SDL_initFramerate( &gFPS );
SDL_setFramerate( &gFPS, 200 );
while ( true ) {
while ( !quit ) {
SDL_framerateDelay( &gFPS );
pollEvents( *scene );
std::lock_guard< std::mutex > lock( render_mutex );
scene->updateScene();
auto prev_coin_count = coin_count;
// TODO visit all moving objects
auto visitor =
getVisitor( *mario, *scene, quit, coin_count, moving_objects );
scene->visitCollisions( *mario, *visitor );
mario->handleVisitor( *visitor );
for(size_t i = 0; i < moving_objects.size(); i++) {
auto visitor =
getVisitor( *moving_objects[i], *scene, quit, coin_count, moving_objects );
scene->visitCollisions( *moving_objects[i], *visitor );
moving_objects[i]->handleVisitor( *visitor );
}
if ( coin_count != prev_coin_count ) {
coins->changeText( std::to_string( coin_count ) + " COINS" );
@ -247,9 +248,9 @@ int main() {
auto base = SDL_GetTicks();
int frames = 0;
std::thread inputThread( doInput, scene );
inputThread.detach();
scene->moveEverything( -mario->getDoubleRect().first.getX() + 0.2, 0 );
update = true;
moving_objects.push_back(mario);
while ( !quit ) {
SDL_PumpEvents();
SDL_framerateDelay( &gFPS );
@ -272,6 +273,7 @@ int main() {
base = SDL_GetTicks();
}
}
inputThread.join();
return 0;
}