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