diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 1890cbd..f55f91a 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -212,7 +212,7 @@ void Game::updatePlayers() // Comprueba la colisión entre el jugador y los globos if (checkPlayerBalloonCollision(player)) { - killPlayer(player); + handlePlayerCollision(player); if (demo_.enabled && allPlayersAreNotPlaying()) { @@ -225,6 +225,9 @@ void Game::updatePlayers() checkPlayerItemCollision(player); } } + + // Organiza la lista de jugadores + movePlayersToFront(); } // Dibuja a los jugadores @@ -899,8 +902,8 @@ void Game::renderPathSprites() } } -// Acciones a realizar cuando el jugador muere -void Game::killPlayer(std::shared_ptr &player) +// Acciones a realizar cuando el jugador colisiona con un globo +void Game::handlePlayerCollision(std::shared_ptr &player) { if (!player->isPlaying() || player->isInvulnerable()) { @@ -925,6 +928,7 @@ void Game::killPlayer(std::shared_ptr &player) screen_->shake(); playSound("voice_no.wav"); player->setPlayingState(PlayerState::DYING); + players_to_reorder.push_back(player); if (allPlayersAreNotPlaying()) { // No se puede subir poder de fase si no hay nadie jugando @@ -2026,6 +2030,26 @@ void Game::playSound(const std::string &name) audio->playSound(name); } +// Organiza los jugadores para que los vivos se pinten sobre los muertos +void Game::movePlayersToFront() +{ + if (players_to_reorder.empty()) + return; + + for (auto& player : players_to_reorder) + { + auto it = std::find(players_.begin(), players_.end(), player); + if (it != players_.end() && it != players_.begin()) + { + std::shared_ptr dyingPlayer = *it; + players_.erase(it); + players_.insert(players_.begin(), dyingPlayer); + } + } + players_to_reorder.clear(); +} + + #ifdef DEBUG // Comprueba los eventos en el modo DEBUG void Game::checkDebugEvents(const SDL_Event &event) diff --git a/source/sections/game.h b/source/sections/game.h index cf2fb46..1884ed3 100644 --- a/source/sections/game.h +++ b/source/sections/game.h @@ -153,6 +153,7 @@ private: int menace_current_ = 0; // Nivel de amenaza actual int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos GameState state_ = GameState::FADE_IN; // Estado + std::vector> players_to_reorder; #ifdef DEBUG bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados @@ -162,7 +163,6 @@ private: #endif // --- Métodos internos --- - void update(); // Actualiza el juego void render(); // Dibuja el juego void checkEvents(); // Comprueba los eventos que hay en cola @@ -194,7 +194,7 @@ private: void renderSmartSprites(); // Pinta los SpriteSmarts activos void updatePathSprites(); // Actualiza los PathSprites void renderPathSprites(); // Pinta los PathSprites activos - void killPlayer(std::shared_ptr &player); // Acciones a realizar cuando el jugador muere + void handlePlayerCollision(std::shared_ptr &player); // Acciones a realizar cuando el jugador colisiona con un globo void updateTimeStopped(); // Actualiza y comprueba el valor de la variable void updateBackground(); // Actualiza el fondo void initPaths(); // Inicializa las variables que contienen puntos de ruta para mover objetos @@ -243,6 +243,7 @@ private: void evaluateAndSetMenace(); // Calcula y establece el valor de amenaza en funcion de los globos activos void checkAndUpdateBalloonSpeed(); // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase void setState(GameState state); // Cambia el estado del juego + void movePlayersToFront(); // Organiza los jugadores para que los vivos se pinten sobre los muertos #ifdef RECORDING void updateRecording(); // Actualiza las variables durante el modo de grabación #endif