TETRIS: Code cleanup

This commit is contained in:
2020-09-13 14:14:39 +02:00
parent 896b5d131f
commit 96c54454f7
6 changed files with 66 additions and 45 deletions
+10 -2
View File
@@ -89,21 +89,29 @@ int main() {
SDL_framerateDelay( &gFPS );
if ( !g_cur_object && g_checked_line ) {
std::lock_guard< std::mutex > guard( g_movement_mutex );
g_cur_object = g_next_object;
g_cur_object->setPos( 0.5, TOP_BORDER - BLOCK_SIZE );
g_cur_shadow = g_cur_object->copySelf();
g_cur_shadow->turnIntoShadow();
for(auto &piece : g_cur_shadow->getObjects()) {
// make it so shadow gets covered by g_cur_object
g_main_scene->moveZ(piece, -4);
}
updateShadow(*g_main_scene);
auto rand_index = std::rand() / ( ( RAND_MAX + 1u ) / 7 );
int retries = 0;
while ( g_bag[rand_index] < 4 ) {
rand_index = ( rand_index + 1 ) % 7;
retries++;
if ( retries == 7 )
quitGame();
// bag is empty
if ( retries == 7 ) {
g_game_over_scene->updateSizeAndPosition();
g_active_scenes.push_back( g_game_over_scene );
g_input_functions.push_back(gameOverSceneInput);
break;
}
}
g_next_object.reset();
g_next_object = g_tetrisFunctions[rand_index]( renderer, g_main_scene );