diff --git a/source/global_events.cpp b/source/global_events.cpp index c228ec6..5a7c571 100644 --- a/source/global_events.cpp +++ b/source/global_events.cpp @@ -41,7 +41,7 @@ void handleInputEvents(const SDL_Event &event) { } // Comprueba los eventos que se pueden producir en cualquier sección del juego -void check(const SDL_Event &event) { +void handle(const SDL_Event &event) { switch (event.type) { case SDL_EVENT_QUIT: // Evento de salida de la aplicación Section::name = Section::Name::QUIT; diff --git a/source/global_events.h b/source/global_events.h index cff34ca..2072210 100644 --- a/source/global_events.h +++ b/source/global_events.h @@ -4,5 +4,5 @@ namespace GlobalEvents { // Comprueba los eventos que se pueden producir en cualquier sección del juego -void check(const SDL_Event &event); +void handle(const SDL_Event &event); } // namespace GlobalEvents \ No newline at end of file diff --git a/source/player.cpp b/source/player.cpp index e2c27c4..6a334c9 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -603,10 +603,10 @@ void Player::update() { } // Incrementa la puntuación del jugador -void Player::addScore(int score, int last_hi_score_entry) { +void Player::addScore(int score, int lowest_hi_score_entry) { if (isPlaying()) { score_ += score; - qualifies_for_high_score_ = score_ > last_hi_score_entry; + qualifies_for_high_score_ = score_ > lowest_hi_score_entry; } } diff --git a/source/player.h b/source/player.h index 01e3e5e..be50ad6 100644 --- a/source/player.h +++ b/source/player.h @@ -114,7 +114,7 @@ class Player { void updateCooldown(); // Actualiza el cooldown de disparo // --- Puntuación y marcador --- - void addScore(int score, int last_hi_score_entry); // Añade puntos + void addScore(int score, int lowest_hi_score_entry); // Añade puntos void incScoreMultiplier(); // Incrementa el multiplicador void decScoreMultiplier(); // Decrementa el multiplicador diff --git a/source/sections/credits.cpp b/source/sections/credits.cpp index bb48bbb..ccb0f5f 100644 --- a/source/sections/credits.cpp +++ b/source/sections/credits.cpp @@ -124,7 +124,7 @@ void Credits::render() { void Credits::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { - GlobalEvents::check(event); + GlobalEvents::handle(event); } } diff --git a/source/sections/game.cpp b/source/sections/game.cpp index e47fe0b..8ff0e80 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -626,13 +626,12 @@ void Game::handleItemDrop(std::shared_ptr balloon, std::shared_ptr balloon, std::shared_ptr player) { - evaluateAndSetMenace(); - if (player->isPlaying()) { auto const SCORE = balloon_manager_->popBalloon(balloon) * player->getScoreMultiplier() * difficulty_score_multiplier_; player->addScore(SCORE, Options::settings.hi_score_table.back().score); player->incScoreMultiplier(); } + setMenace(); updateHiScore(); } @@ -1022,7 +1021,7 @@ void Game::run() { checkInput(); #endif update(); - checkEvents(); // Tiene que ir antes del render + handleEvents(); // Tiene que ir antes del render render(); } } @@ -1083,7 +1082,7 @@ void Game::initPaths() { // Actualiza las variables de ayuda void Game::updateHelper() { // Solo ofrece ayuda cuando la amenaza es elevada - if (menace_current_ > 15) { + if (menace_ > 15) { helper_.need_coffee = true; helper_.need_coffee_machine = true; for (const auto &player : players_) { @@ -1128,7 +1127,7 @@ auto Game::allPlayersAreNotPlaying() -> bool { } // Comprueba los eventos que hay en cola -void Game::checkEvents() { +void Game::handleEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { @@ -1145,9 +1144,9 @@ void Game::checkEvents() { } #ifdef _DEBUG - checkDebugEvents(event); + handleDebugEvents(event); #endif - GlobalEvents::check(event); + GlobalEvents::handle(event); } } @@ -1705,7 +1704,7 @@ void Game::updateGameStateFadeIn() { if (fade_in_->hasEnded()) { setState(State::ENTERING_PLAYER); balloon_manager_->createTwoBigBalloons(); - evaluateAndSetMenace(); + setMenace(); } } @@ -1791,15 +1790,16 @@ void Game::updateMenace() { // Aumenta el nivel de amenaza en función del progreso de la fase menace_threshold_ = stage.getMinMenace() + (difference * fraction); - if (menace_current_ < menace_threshold_) { + if (menace_ < menace_threshold_) { balloon_manager_->deployRandomFormation(stage_manager_->getCurrentStageIndex()); - evaluateAndSetMenace(); + setMenace(); } + std::cout << "MT: " << menace_threshold_ << " | MC: " << menace_ << std::endl; } // Calcula y establece el valor de amenaza en funcion de los globos activos -void Game::evaluateAndSetMenace() { - menace_current_ = balloon_manager_->getMenace(); +void Game::setMenace() { + menace_ = balloon_manager_->getMenace(); } // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase @@ -1808,8 +1808,7 @@ void Game::checkAndUpdateBalloonSpeed() { return; } - // const float PERCENT = static_cast(Stage::power) / Stage::get(Stage::number).power_to_complete; - const float PERCENT = stage_manager_->getCurrentStageProgressPercentage(); + const float PERCENT = stage_manager_->getCurrentStageProgressFraction(); constexpr std::array THRESHOLDS = {0.2F, 0.4F, 0.6F, 0.8F}; for (size_t i = 0; i < std::size(THRESHOLDS); ++i) { @@ -1883,13 +1882,13 @@ void Game::onPauseStateChanged(bool is_paused) { #ifdef _DEBUG // Comprueba los eventos en el modo DEBUG -void Game::checkDebugEvents(const SDL_Event &event) { +void Game::handleDebugEvents(const SDL_Event &event) { static int formation_id_ = 0; if (event.type == SDL_EVENT_KEY_DOWN && static_cast(event.key.repeat) == 0) { switch (event.key.key) { case SDLK_1: // Crea una powerball { - // balloon_manager_->createPowerBall(); + balloon_manager_->createPowerBall(); // throwCoffee(players_.at(0)->getPosX() + (players_.at(0)->getWidth() / 2), players_.at(0)->getPosY() + (players_.at(0)->getHeight() / 2)); break; } diff --git a/source/sections/game.h b/source/sections/game.h index 2b523db..23b7e43 100644 --- a/source/sections/game.h +++ b/source/sections/game.h @@ -13,8 +13,8 @@ #include "path_sprite.h" // Para PathSprite, Path #include "player.h" // Para Player #include "smart_sprite.h" // Para SmartSprite -#include "utils.h" // Para Demo #include "stage.h" // Para StageManager +#include "utils.h" // Para Demo class Background; class Balloon; @@ -102,25 +102,25 @@ class Game { Scoreboard *scoreboard_; // Objeto para dibujar el marcador SDL_Texture *canvas_; // Textura para dibujar la zona de juego - + std::vector> players_; // Vector con los jugadores std::vector> bullets_; // Vector con las balas std::vector> items_; // Vector con los items std::vector> smart_sprites_; // Vector con los smartsprites std::vector> path_sprites_; // Vector con los pathsprites - + std::vector> item_textures_; // Vector con las texturas de los items std::vector>> player_textures_; // Vector con todas las texturas de los jugadores - + std::vector> game_text_textures_; // Vector con las texturas para los sprites con textos - + std::vector> item_animations_; // Vector con las animaciones de los items std::vector> player_animations_; // Vector con las animaciones del jugador - + std::unique_ptr pause_manager_; // Objeto para gestionar la pausa std::unique_ptr stage_manager_; // Objeto para gestionar las fases std::unique_ptr balloon_manager_; // Objeto para gestionar los globos - std::unique_ptr background_; // Objeto para dibujar el fondo del juego + std::unique_ptr background_; // Objeto para dibujar el fondo del juego std::unique_ptr fade_in_; // Objeto para renderizar fades std::unique_ptr fade_out_; // Objeto para renderizar fades std::unique_ptr tabe_; // Objeto para gestionar el Tabe Volaor @@ -142,7 +142,7 @@ class Game { int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más globos int game_over_counter_ = GAME_OVER_COUNTER; // Contador para el estado de fin de partida int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido - int menace_current_ = 0; // Nivel de amenaza actual + int menace_ = 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 State state_ = State::FADE_IN; // Estado std::vector> players_to_put_at_back_; @@ -156,7 +156,7 @@ class Game { // --- Ciclo principal del juego --- void update(); // Actualiza la lógica principal del juego void render(); // Renderiza todos los elementos del juego - void checkEvents(); // Procesa los eventos del sistema en cola + void handleEvents(); // Procesa los eventos del sistema en cola void checkState(); // Verifica y actualiza el estado actual del juego void setState(State state); // Cambia el estado del juego void cleanVectors(); // Limpia vectores de elementos deshabilitados @@ -263,8 +263,8 @@ class Game { void initDifficultyVars(); // Inicializa variables de dificultad // --- Sistema de amenaza --- - void updateMenace(); // Gestiona el nivel de amenaza del juego - void evaluateAndSetMenace(); // Calcula y establece amenaza según globos activos + void updateMenace(); // Gestiona el nivel de amenaza del juego + void setMenace(); // Calcula y establece amenaza según globos activos // --- Puntuación y marcador --- void updateHiScore(); // Actualiza el récord máximo si es necesario @@ -300,6 +300,6 @@ class Game { // --- Depuración (solo en modo DEBUG) --- #ifdef _DEBUG - void checkDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG + void handleDebugEvents(const SDL_Event &event); // Comprueba los eventos en el modo DEBUG #endif }; \ No newline at end of file diff --git a/source/sections/hiscore_table.cpp b/source/sections/hiscore_table.cpp index b8225e0..b94728f 100644 --- a/source/sections/hiscore_table.cpp +++ b/source/sections/hiscore_table.cpp @@ -108,7 +108,7 @@ void HiScoreTable::fillTexture() { void HiScoreTable::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { - GlobalEvents::check(event); + GlobalEvents::handle(event); } } diff --git a/source/sections/instructions.cpp b/source/sections/instructions.cpp index 74c783d..acc6c65 100644 --- a/source/sections/instructions.cpp +++ b/source/sections/instructions.cpp @@ -245,7 +245,7 @@ void Instructions::render() { void Instructions::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { - GlobalEvents::check(event); + GlobalEvents::handle(event); } } diff --git a/source/sections/intro.cpp b/source/sections/intro.cpp index fc9d9c4..b6143e4 100644 --- a/source/sections/intro.cpp +++ b/source/sections/intro.cpp @@ -47,7 +47,7 @@ Intro::Intro() void Intro::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { - GlobalEvents::check(event); + GlobalEvents::handle(event); } } diff --git a/source/sections/logo.cpp b/source/sections/logo.cpp index c09fa96..be896ad 100644 --- a/source/sections/logo.cpp +++ b/source/sections/logo.cpp @@ -68,7 +68,7 @@ Logo::~Logo() { void Logo::checkEvents() { SDL_Event event; while (SDL_PollEvent(&event)) { - GlobalEvents::check(event); + GlobalEvents::handle(event); } } diff --git a/source/sections/title.cpp b/source/sections/title.cpp index 1ded865..1f2eb9f 100644 --- a/source/sections/title.cpp +++ b/source/sections/title.cpp @@ -117,7 +117,7 @@ void Title::checkEvents() { handleKeyDownEvent(event); } - GlobalEvents::check(event); + GlobalEvents::handle(event); } }