This commit is contained in:
2025-10-19 22:01:31 +02:00
parent 16306f2325
commit 2b4523d644
101 changed files with 2058 additions and 1564 deletions

View File

@@ -1,14 +1,16 @@
#include "game.hpp"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_EventType, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_Event, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_KP_MINUS, SDLK_KP_PLUS, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_Point, SDL_TextureAccess, Uint64
#include <algorithm> // Para find, clamp, find_if, min, std::shuffle, std::iota
#include <algorithm> // Para find, clamp, find_if, min, shuffle
#include <array> // Para array
#include <cstdlib> // Para rand, size_t
#include <functional> // Para function
#include <iterator> // Para size
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
#include <random> // std::random_device, std::default_random_engine
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, make_unique, allocator, operator==
#include <numeric> // Para iota
#include <optional> // Para optional
#include <random> // Para random_device, default_random_engine
#include <utility> // Para move
#include "asset.hpp" // Para Asset
@@ -16,12 +18,12 @@
#include "background.hpp" // Para Background
#include "balloon.hpp" // Para Balloon
#include "balloon_manager.hpp" // Para BalloonManager
#include "bullet.hpp" // Para Bullet, Bullet::Type, BulletMoveStatus
#include "bullet.hpp" // Para Bullet
#include "bullet_manager.hpp" // Para BulletManager
#include "color.hpp" // Para Color, Colors::FLASH
#include "color.hpp" // Para Color, FLASH, NO_COLOR_MOD
#include "difficulty.hpp" // Para Code
#include "fade.hpp" // Para Fade, FadeType, FadeMode
#include "global_events.hpp" // Para check
#include "fade.hpp" // Para Fade
#include "global_events.hpp" // Para handle
#include "global_inputs.hpp" // Para check
#include "hit.hpp" // Para Hit
#include "input.hpp" // Para Input
@@ -30,7 +32,7 @@
#include "lang.hpp" // Para getText
#include "manage_hiscore_table.hpp" // Para HiScoreEntry, ManageHiScoreTable
#include "param.hpp" // Para Param, param, ParamGame, ParamScoreboard, ParamFade, ParamBalloon
#include "path_sprite.hpp" // Para Path, PathSprite, createPath, PathType
#include "path_sprite.hpp" // Para Path, PathSprite, PathType
#include "pause_manager.hpp" // Para PauseManager
#include "player.hpp" // Para Player
#include "resource.hpp" // Para Resource
@@ -38,13 +40,14 @@
#include "screen.hpp" // Para Screen
#include "section.hpp" // Para Name, name, AttractMode, Options, attract_mode, options
#include "smart_sprite.hpp" // Para SmartSprite
#include "stage.hpp" // Para number, Stage, get, total_power, power, init, power_can_be_added, stages
#include "stage.hpp" // Para StageManager, StageData
#include "tabe.hpp" // Para Tabe
#include "text.hpp" // Para Text
#include "texture.hpp" // Para Texture
#include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.hpp" // Para Zone, checkCollision, easeInQuint, easeOutQuint, boolToString
#ifdef _DEBUG
#include <iostream> // Para std::cout
#include <iostream> // Para basic_ostream, basic_ostream::operator<<, operator<<, cout
#include "ui/notifier.hpp" // Para Notifier
#endif
@@ -240,9 +243,9 @@ void Game::updateHiScore() {
}
// Actualiza las variables del jugador
void Game::updatePlayers(float deltaTime) {
void Game::updatePlayers(float delta_time) {
for (auto& player : players_) {
player->update(deltaTime);
player->update(delta_time);
if (player->isPlaying()) {
// Comprueba la colisión entre el jugador y los globos
@@ -341,29 +344,29 @@ void Game::updateStage() {
}
// Actualiza las variables y sistemas durante el estado de fin de partida
void Game::updateGameStateGameOver(float deltaTime) {
void Game::updateGameStateGameOver(float delta_time) {
fade_out_->update();
updatePlayers(deltaTime);
updateScoreboard(deltaTime);
updateBackground(deltaTime);
balloon_manager_->update(deltaTime);
tabe_->update(deltaTime);
bullet_manager_->update(deltaTime);
updateItems(deltaTime);
updateSmartSprites(deltaTime);
updatePathSprites(deltaTime);
updateTimeStopped(deltaTime);
updatePlayers(delta_time);
updateScoreboard(delta_time);
updateBackground(delta_time);
balloon_manager_->update(delta_time);
tabe_->update(delta_time);
bullet_manager_->update(delta_time);
updateItems(delta_time);
updateSmartSprites(delta_time);
updatePathSprites(delta_time);
updateTimeStopped(delta_time);
bullet_manager_->checkCollisions();
cleanVectors();
if (game_over_timer_ < GAME_OVER_DURATION_S) {
game_over_timer_ += deltaTime; // Incremento time-based primero
handleGameOverEvents(); // Maneja eventos después del incremento
game_over_timer_ += delta_time; // Incremento time-based primero
handleGameOverEvents(); // Maneja eventos después del incremento
}
if (Options::audio.enabled) {
const float progress = std::min(game_over_timer_ / GAME_OVER_DURATION_S, 1.0f);
const float VOL = 64.0f * (1.0f - progress);
const float PROGRESS = std::min(game_over_timer_ / GAME_OVER_DURATION_S, 1.0F);
const float VOL = 64.0F * (1.0F - PROGRESS);
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
}
@@ -378,16 +381,16 @@ void Game::updateGameStateGameOver(float deltaTime) {
}
// Gestiona eventos para el estado del final del juego
void Game::updateGameStateCompleted(float deltaTime) {
updatePlayers(deltaTime);
updateScoreboard(deltaTime);
updateBackground(deltaTime);
balloon_manager_->update(deltaTime);
tabe_->update(deltaTime);
bullet_manager_->update(deltaTime);
updateItems(deltaTime);
updateSmartSprites(deltaTime);
updatePathSprites(deltaTime);
void Game::updateGameStateCompleted(float delta_time) {
updatePlayers(delta_time);
updateScoreboard(delta_time);
updateBackground(delta_time);
balloon_manager_->update(delta_time);
tabe_->update(delta_time);
bullet_manager_->update(delta_time);
updateItems(delta_time);
updateSmartSprites(delta_time);
updatePathSprites(delta_time);
cleanVectors();
// Maneja eventos del juego completado
@@ -399,7 +402,7 @@ void Game::updateGameStateCompleted(float deltaTime) {
}
// Incrementa el acumulador al final
game_completed_timer_ += deltaTime;
game_completed_timer_ += delta_time;
}
// Comprueba el estado del juego
@@ -589,9 +592,9 @@ void Game::handleItemDrop(const std::shared_ptr<Balloon>& balloon, const std::sh
}
// Maneja la destrucción del globo y puntuación
void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std::shared_ptr<Player>& player) {
void Game::handleBalloonDestruction(const std::shared_ptr<Balloon>& balloon, const std::shared_ptr<Player>& player) {
if (player->isPlaying()) {
auto const SCORE = balloon_manager_->popBalloon(std::move(balloon)) * player->getScoreMultiplier() * difficulty_score_multiplier_;
auto const SCORE = balloon_manager_->popBalloon(balloon) * player->getScoreMultiplier() * difficulty_score_multiplier_;
player->addScore(SCORE, Options::settings.hi_score_table.back().score);
player->incScoreMultiplier();
}
@@ -600,13 +603,13 @@ void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std:
}
// Actualiza los items
void Game::updateItems(float deltaTime) {
void Game::updateItems(float delta_time) {
for (auto& item : items_) {
if (item->isEnabled()) {
item->update(deltaTime);
item->update(delta_time);
if (item->isOnFloor()) {
playSound("title.wav");
screen_->shake(1, 0.033f, 0.067f); // desp=1, delay=0.033s, length=0.067s
screen_->shake(1, 0.033F, 0.067F); // desp=1, delay=0.033s, length=0.067s
}
}
}
@@ -711,8 +714,8 @@ void Game::createItemText(int x, const std::shared_ptr<Texture>& texture) {
path_sprites_.back()->setWidth(W);
path_sprites_.back()->setHeight(H);
path_sprites_.back()->setSpriteClip({0, 0, static_cast<float>(W), static_cast<float>(H)});
path_sprites_.back()->addPath(Y0, Y1, PathType::VERTICAL, x, 1.667f, easeOutQuint, 0); // 100 frames → 1.667s
path_sprites_.back()->addPath(Y1, Y2, PathType::VERTICAL, x, 1.333f, easeInQuint, 0); // 80 frames → 1.333s
path_sprites_.back()->addPath(Y0, Y1, PathType::VERTICAL, x, 1.667F, easeOutQuint, 0); // 100 frames → 1.667s
path_sprites_.back()->addPath(Y1, Y2, PathType::VERTICAL, x, 1.333F, easeInQuint, 0); // 80 frames → 1.333s
path_sprites_.back()->enable();
}
@@ -757,10 +760,10 @@ void Game::throwCoffee(int x, int y) {
smart_sprites_.back()->setPosY(y - 8);
smart_sprites_.back()->setWidth(Item::WIDTH);
smart_sprites_.back()->setHeight(Item::HEIGHT);
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0f); // Convertir a pixels/segundo
smart_sprites_.back()->setVelY(-4.0F * 60.0f); // Convertir a pixels/segundo
smart_sprites_.back()->setVelX((-1.0F + ((rand() % 5) * 0.5F)) * 60.0F); // Convertir a pixels/segundo
smart_sprites_.back()->setVelY(-4.0F * 60.0F); // Convertir a pixels/segundo
smart_sprites_.back()->setAccelX(0.0F);
smart_sprites_.back()->setAccelY(0.2F * 60.0f * 60.0f); // Convertir a pixels/segundo² (0.2 × 60²)
smart_sprites_.back()->setAccelY(0.2F * 60.0F * 60.0F); // Convertir a pixels/segundo² (0.2 × 60²)
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
smart_sprites_.back()->setDestY(param.game.height + 1);
smart_sprites_.back()->setEnabled(true);
@@ -772,9 +775,9 @@ void Game::throwCoffee(int x, int y) {
}
// Actualiza los SmartSprites
void Game::updateSmartSprites(float deltaTime) {
void Game::updateSmartSprites(float delta_time) {
for (auto& sprite : smart_sprites_) {
sprite->update(deltaTime);
sprite->update(delta_time);
}
}
@@ -786,9 +789,9 @@ void Game::renderSmartSprites() {
}
// Actualiza los PathSprites
void Game::updatePathSprites(float deltaTime) {
void Game::updatePathSprites(float delta_time) {
for (auto& sprite : path_sprites_) {
sprite->update(deltaTime);
sprite->update(delta_time);
}
}
@@ -831,44 +834,44 @@ void Game::handlePlayerCollision(std::shared_ptr<Player>& player, std::shared_pt
}
// Actualiza el estado del tiempo detenido
void Game::updateTimeStopped(float deltaTime) {
static constexpr float WARNING_THRESHOLD_S = 2.0f; // 120 frames a 60fps → segundos
static constexpr float CLOCK_SOUND_INTERVAL_S = 0.5f; // 30 frames a 60fps → segundos
static constexpr float COLOR_FLASH_INTERVAL_S = 0.25f; // 15 frames a 60fps → segundos
void Game::updateTimeStopped(float delta_time) {
static constexpr float WARNING_THRESHOLD_S = 2.0F; // 120 frames a 60fps → segundos
static constexpr float CLOCK_SOUND_INTERVAL_S = 0.5F; // 30 frames a 60fps → segundos
static constexpr float COLOR_FLASH_INTERVAL_S = 0.25F; // 15 frames a 60fps → segundos
if (time_stopped_timer_ > 0) {
time_stopped_timer_ -= deltaTime;
time_stopped_timer_ -= delta_time;
// Fase de advertencia (últimos 2 segundos)
if (time_stopped_timer_ <= WARNING_THRESHOLD_S) {
static float last_sound_time = 0.0f;
static float last_sound_time_ = 0.0F;
// CLAC al entrar en fase de advertencia
if (!time_stopped_flags_.warning_phase_started) {
playSound("clock.wav");
time_stopped_flags_.warning_phase_started = true;
last_sound_time = 0.0f; // Reset para empezar el ciclo rápido
last_sound_time_ = 0.0F; // Reset para empezar el ciclo rápido
}
last_sound_time += deltaTime;
last_sound_time_ += delta_time;
if (last_sound_time >= CLOCK_SOUND_INTERVAL_S) {
if (last_sound_time_ >= CLOCK_SOUND_INTERVAL_S) {
balloon_manager_->normalColorsToAllBalloons();
playSound("clock.wav");
last_sound_time = 0.0f;
last_sound_time_ = 0.0F;
time_stopped_flags_.color_flash_sound_played = false; // Reset flag para el próximo intervalo
} else if (last_sound_time >= COLOR_FLASH_INTERVAL_S && !time_stopped_flags_.color_flash_sound_played) {
} else if (last_sound_time_ >= COLOR_FLASH_INTERVAL_S && !time_stopped_flags_.color_flash_sound_played) {
balloon_manager_->reverseColorsToAllBalloons();
playSound("clock.wav");
time_stopped_flags_.color_flash_sound_played = true; // Evita que suene múltiples veces
}
} else {
// Fase normal - solo sonido ocasional
static float sound_timer = 0.0f;
sound_timer += deltaTime;
if (sound_timer >= CLOCK_SOUND_INTERVAL_S) {
static float sound_timer_ = 0.0F;
sound_timer_ += delta_time;
if (sound_timer_ >= CLOCK_SOUND_INTERVAL_S) {
playSound("clock.wav");
sound_timer = 0.0f;
sound_timer_ = 0.0F;
}
}
@@ -881,15 +884,15 @@ void Game::updateTimeStopped(float deltaTime) {
}
// Actualiza toda la lógica del juego
void Game::update(float deltaTime) {
screen_->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
void Game::update(float delta_time) {
screen_->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
updateDemo(deltaTime);
updateDemo(delta_time);
#ifdef RECORDING
updateRecording(deltaTime);
#endif
updateGameStates(deltaTime);
updateGameStates(delta_time);
fillCanvas();
}
@@ -909,26 +912,26 @@ void Game::render() {
}
// Actualiza los estados del juego
void Game::updateGameStates(float deltaTime) {
void Game::updateGameStates(float delta_time) {
if (!pause_manager_->isPaused()) {
switch (state_) {
case State::FADE_IN:
updateGameStateFadeIn(deltaTime);
updateGameStateFadeIn(delta_time);
break;
case State::ENTERING_PLAYER:
updateGameStateEnteringPlayer(deltaTime);
updateGameStateEnteringPlayer(delta_time);
break;
case State::SHOWING_GET_READY_MESSAGE:
updateGameStateShowingGetReadyMessage(deltaTime);
updateGameStateShowingGetReadyMessage(delta_time);
break;
case State::PLAYING:
updateGameStatePlaying(deltaTime);
updateGameStatePlaying(delta_time);
break;
case State::COMPLETED:
updateGameStateCompleted(deltaTime);
updateGameStateCompleted(delta_time);
break;
case State::GAME_OVER:
updateGameStateGameOver(deltaTime);
updateGameStateGameOver(delta_time);
break;
default:
break;
@@ -937,8 +940,8 @@ void Game::updateGameStates(float deltaTime) {
}
// Actualiza el fondo
void Game::updateBackground(float deltaTime) {
background_->update(deltaTime);
void Game::updateBackground(float delta_time) {
background_->update(delta_time);
}
// Dibuja los elementos de la zona de juego en su textura
@@ -980,10 +983,10 @@ void Game::disableTimeStopItem() {
// Calcula el deltatime en segundos
auto Game::calculateDeltaTime() -> float {
const Uint64 current_time = SDL_GetTicks();
const float delta_time_ms = static_cast<float>(current_time - last_time_);
last_time_ = current_time;
return delta_time_ms / 1000.0f; // Convertir de milisegundos a segundos
const Uint64 CURRENT_TIME = SDL_GetTicks();
const auto DELTA_TIME_MS = static_cast<float>(CURRENT_TIME - last_time_);
last_time_ = CURRENT_TIME;
return DELTA_TIME_MS / 1000.0F; // Convertir de milisegundos a segundos
}
// Bucle para el juego
@@ -991,9 +994,9 @@ void Game::run() {
last_time_ = SDL_GetTicks();
while (Section::name == Section::Name::GAME) {
const float delta_time = calculateDeltaTime();
const float DELTA_TIME = calculateDeltaTime();
checkInput();
update(delta_time);
update(DELTA_TIME);
handleEvents(); // Tiene que ir antes del render
render();
}
@@ -1003,7 +1006,7 @@ void Game::run() {
void Game::initPaths() {
// --- Duración estándar para 80 frames ---
// (Basado en tu ejemplo: 80 frames → 1.333s)
const float DURATION_80F_S = 1.333f;
const float DURATION_80F_S = 1.333F;
// Recorrido para el texto de "Get Ready!" (0,1)
{
@@ -1013,9 +1016,9 @@ void Game::initPaths() {
const int X1 = param.game.play_area.center_x - (W / 2);
const int X2 = param.game.play_area.rect.w;
// Y_base es la LÍNEA CENTRAL. addPath(true) restará H/2
const int Y_base = param.game.play_area.center_y;
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.5f, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint);
const int Y_BASE = param.game.play_area.center_y;
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 0.5F, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
// Recorrido para el texto de "Last Stage!" o de "X stages left" (2,3)
@@ -1026,9 +1029,9 @@ void Game::initPaths() {
const int Y1 = param.game.play_area.center_y - (H / 2);
const int Y2 = -H;
// X_base es la LÍNEA CENTRAL. addPath(true) restará W/2
const int X_base = param.game.play_area.center_x;
paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_base, DURATION_80F_S, 0.5f, easeOutQuint);
paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_base, DURATION_80F_S, 0.0f, easeInQuint);
const int X_BASE = param.game.play_area.center_x;
paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_BASE, DURATION_80F_S, 0.5F, easeOutQuint);
paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
// Recorrido para el texto de "Congratulations!!" (4,5)
@@ -1040,9 +1043,9 @@ void Game::initPaths() {
const int X1 = param.game.play_area.center_x - (W / 2);
const int X2 = param.game.play_area.rect.w;
// Y_base es la LÍNEA CENTRAL. addPath(true) restará H/2
const int Y_base = param.game.play_area.center_y - (H / 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 7.0f, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint);
const int Y_BASE = param.game.play_area.center_y - (H / 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 7.0F, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
// Recorrido para el texto de "1.000.000 points!" (6,7)
@@ -1054,9 +1057,9 @@ void Game::initPaths() {
const int X1 = param.game.play_area.center_x - (W / 2);
const int X2 = -W;
// Y_base es la LÍNEA CENTRAL (desplazada PREV_H hacia abajo). addPath(true) restará H/2
const int Y_base = param.game.play_area.center_y + (H / 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 7.0f, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint);
const int Y_BASE = param.game.play_area.center_y + (H / 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 7.0F, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
// Recorrido para el texto de "New Record!" (8,9)
@@ -1068,9 +1071,9 @@ void Game::initPaths() {
const int X1 = param.game.play_area.center_x - (W / 2); // Destino (no-fijo), está bien
const int X2 = param.game.play_area.rect.w;
// Y_base es la LÍNEA CENTRAL (desplazada 2*H hacia arriba). addPath(true) restará H/2
const int Y_base = param.game.play_area.center_y - (H * 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 1.0f, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_base, DURATION_80F_S, 0.0f, easeInQuint);
const int Y_BASE = param.game.play_area.center_y - (H * 2);
paths_.emplace_back(X0, X1, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 1.0F, easeOutQuint);
paths_.emplace_back(X1, X2, PathType::HORIZONTAL, Y_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
// Recorrido para el texto de "Game Over" (10,11)
@@ -1081,9 +1084,9 @@ void Game::initPaths() {
const int Y1 = param.game.play_area.center_y - (H / 2); // Destino (no-fijo), está bien
const int Y2 = -H;
// X_base es la LÍNEA CENTRAL. addPath(true) restará W/2
const int X_base = param.game.play_area.center_x;
paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_base, DURATION_80F_S, 2.0f, easeOutQuint);
paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_base, DURATION_80F_S, 0.0f, easeInQuint);
const int X_BASE = param.game.play_area.center_x;
paths_.emplace_back(Y0, Y1, PathType::VERTICAL, X_BASE, DURATION_80F_S, 2.0F, easeOutQuint);
paths_.emplace_back(Y1, Y2, PathType::VERTICAL, X_BASE, DURATION_80F_S, 0.0F, easeInQuint);
}
}
@@ -1159,7 +1162,7 @@ void Game::handleEvents() {
}
// Actualiza el marcador
void Game::updateScoreboard(float deltaTime) {
void Game::updateScoreboard(float delta_time) {
for (const auto& player : players_) {
scoreboard_->setScore(player->getScoreBoardPanel(), player->getScore());
scoreboard_->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier());
@@ -1171,7 +1174,7 @@ void Game::updateScoreboard(float deltaTime) {
scoreboard_->setHiScore(hi_score_.score);
scoreboard_->setHiScoreName(hi_score_.name);
scoreboard_->update(deltaTime);
scoreboard_->update(delta_time);
}
// Pone en el marcador el nombre del primer jugador de la tabla
@@ -1207,7 +1210,7 @@ void Game::checkPlayersStatusPlaying() {
// Obtiene un jugador a partir de su "id"
auto Game::getPlayer(Player::Id id) -> std::shared_ptr<Player> {
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto& player) { return player->getId() == id; });
auto it = std::ranges::find_if(players_, [id](const auto& player) { return player->getId() == id; });
if (it != players_.end()) {
return *it;
@@ -1699,7 +1702,7 @@ void Game::stopMusic() const {
}
// Actualiza las variables durante el modo demo
void Game::updateDemo(float deltaTime) {
void Game::updateDemo(float delta_time) {
if (demo_.enabled) {
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
@@ -1708,7 +1711,7 @@ void Game::updateDemo(float deltaTime) {
fade_out_->update();
// Actualiza el contador de tiempo y el índice
demo_.elapsed_s += deltaTime;
demo_.elapsed_s += delta_time;
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
// Activa el fundido antes de acabar con los datos de la demo
@@ -1755,10 +1758,10 @@ void Game::updateRecording(float deltaTime) {
#endif
// Actualiza las variables durante dicho estado
void Game::updateGameStateFadeIn(float deltaTime) {
void Game::updateGameStateFadeIn(float delta_time) {
fade_in_->update();
updateScoreboard(deltaTime);
updateBackground(deltaTime);
updateScoreboard(delta_time);
updateBackground(delta_time);
if (fade_in_->hasEnded()) {
setState(State::ENTERING_PLAYER);
balloon_manager_->createTwoBigBalloons();
@@ -1767,11 +1770,11 @@ void Game::updateGameStateFadeIn(float deltaTime) {
}
// Actualiza las variables durante dicho estado
void Game::updateGameStateEnteringPlayer(float deltaTime) {
balloon_manager_->update(deltaTime);
updatePlayers(deltaTime);
updateScoreboard(deltaTime);
updateBackground(deltaTime);
void Game::updateGameStateEnteringPlayer(float delta_time) {
balloon_manager_->update(delta_time);
updatePlayers(delta_time);
updateScoreboard(delta_time);
updateBackground(delta_time);
for (const auto& player : players_) {
if (player->isPlaying()) {
setState(State::SHOWING_GET_READY_MESSAGE);
@@ -1782,38 +1785,38 @@ void Game::updateGameStateEnteringPlayer(float deltaTime) {
}
// Actualiza las variables durante dicho estado
void Game::updateGameStateShowingGetReadyMessage(float deltaTime) {
updateGameStatePlaying(deltaTime);
void Game::updateGameStateShowingGetReadyMessage(float delta_time) {
updateGameStatePlaying(delta_time);
constexpr float MUSIC_START_S = 1.67F;
static float music_timer = 0.0f;
music_timer += deltaTime;
if (music_timer >= MUSIC_START_S) {
static float music_timer_ = 0.0F;
music_timer_ += delta_time;
if (music_timer_ >= MUSIC_START_S) {
playMusic("playing.ogg");
music_timer = 0.0F;
music_timer_ = 0.0F;
setState(State::PLAYING);
}
}
// Actualiza las variables durante el transcurso normal del juego
void Game::updateGameStatePlaying(float deltaTime) {
void Game::updateGameStatePlaying(float delta_time) {
#ifdef _DEBUG
if (auto_pop_balloons_) {
stage_manager_->addPower(2);
}
#endif
updatePlayers(deltaTime);
updatePlayers(delta_time);
checkPlayersStatusPlaying();
updateScoreboard(deltaTime);
updateBackground(deltaTime);
balloon_manager_->update(deltaTime);
tabe_->update(deltaTime);
bullet_manager_->update(deltaTime);
updateItems(deltaTime);
updateScoreboard(delta_time);
updateBackground(delta_time);
balloon_manager_->update(delta_time);
tabe_->update(delta_time);
bullet_manager_->update(delta_time);
updateItems(delta_time);
updateStage();
updateSmartSprites(deltaTime);
updatePathSprites(deltaTime);
updateTimeStopped(deltaTime);
updateSmartSprites(delta_time);
updatePathSprites(delta_time);
updateTimeStopped(delta_time);
updateHelper();
bullet_manager_->checkCollisions();
updateMenace();
@@ -1916,9 +1919,9 @@ void Game::sortPlayersByZOrder() {
// Procesar jugadores que van al fondo (se dibujan primero)
if (!players_to_put_at_back_.empty()) {
for (auto& player : players_to_put_at_back_) {
auto it = std::find(players_.begin(), players_.end(), player);
auto it = std::ranges::find(players_, player);
if (it != players_.end() && it != players_.begin()) {
std::shared_ptr<Player> dying_player = *it;
const std::shared_ptr<Player>& dying_player = *it;
players_.erase(it);
players_.insert(players_.begin(), dying_player);
}
@@ -1929,9 +1932,9 @@ void Game::sortPlayersByZOrder() {
// Procesar jugadores que van al frente (se dibujan últimos)
if (!players_to_put_at_front_.empty()) {
for (auto& player : players_to_put_at_front_) {
auto it = std::find(players_.begin(), players_.end(), player);
auto it = std::ranges::find(players_, player);
if (it != players_.end() && it != players_.end() - 1) {
std::shared_ptr<Player> front_player = *it;
const std::shared_ptr<Player>& front_player = *it;
players_.erase(it);
players_.push_back(front_player);
}
@@ -1957,8 +1960,8 @@ void Game::onPauseStateChanged(bool is_paused) {
// Maneja eventos del juego completado usando flags para triggers únicos
void Game::handleGameCompletedEvents() {
constexpr float START_CELEBRATIONS_S = 6.0f;
constexpr float END_CELEBRATIONS_S = 14.0f;
constexpr float START_CELEBRATIONS_S = 6.0F;
constexpr float END_CELEBRATIONS_S = 14.0F;
// Inicio de celebraciones
if (!game_completed_flags_.start_celebrations_triggered && game_completed_timer_ >= START_CELEBRATIONS_S) {
@@ -1992,8 +1995,8 @@ void Game::handleGameCompletedEvents() {
// Maneja eventos discretos basados en tiempo durante el estado game over
void Game::handleGameOverEvents() {
constexpr float MESSAGE_TRIGGER_S = 1.5f;
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5f;
constexpr float MESSAGE_TRIGGER_S = 1.5F;
constexpr float FADE_TRIGGER_S = GAME_OVER_DURATION_S - 2.5F;
// Trigger inicial: fade out de música y sonidos de globos
if (!game_over_flags_.music_fade_triggered) {