clang-tidy readability-function-cognitive-complexity
This commit is contained in:
@@ -42,7 +42,7 @@ Credits::Credits()
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)) {
|
||||
if (!text_texture_) {
|
||||
if (text_texture_ == nullptr) {
|
||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||
}
|
||||
Section::name = Section::Name::CREDITS;
|
||||
@@ -133,7 +133,7 @@ void Credits::checkInput() {
|
||||
|
||||
if (!ServiceMenu::get()->isEnabled()) {
|
||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT)) {
|
||||
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT) != 0) {
|
||||
want_to_pass_ = true;
|
||||
fading_ = mini_logo_on_position_;
|
||||
} else {
|
||||
@@ -235,7 +235,7 @@ void Credits::fillTextTexture() {
|
||||
// Dibuja todos los sprites en la textura
|
||||
void Credits::fillCanvas() {
|
||||
// Cambia el destino del renderizador
|
||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
|
||||
|
||||
// Dibuja el fondo, los globos y los jugadores
|
||||
@@ -378,7 +378,7 @@ void Credits::updateBlackRects() {
|
||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
|
||||
|
||||
--current_step_;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
|
||||
setVolume((initial_volume_ * current_step_ / steps_));
|
||||
}
|
||||
} else {
|
||||
// Si los rectangulos superior e inferior han llegado al centro
|
||||
@@ -393,7 +393,7 @@ void Credits::updateBlackRects() {
|
||||
right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x);
|
||||
|
||||
--current_step_;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step_ / steps_));
|
||||
setVolume((initial_volume_ * current_step_ / steps_));
|
||||
} else {
|
||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||
setVolume(0);
|
||||
@@ -440,7 +440,7 @@ void Credits::setVolume(int amount) {
|
||||
}
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void Credits::resetVolume() {
|
||||
void Credits::resetVolume() const {
|
||||
Options::audio.music.volume = initial_volume_;
|
||||
Audio::get()->setMusicVolume(Options::audio.music.volume);
|
||||
}
|
||||
@@ -456,9 +456,9 @@ void Credits::cycleColors() {
|
||||
static auto r_ = static_cast<float>(UPPER_LIMIT);
|
||||
static auto g_ = static_cast<float>(LOWER_LIMIT);
|
||||
static auto b_ = static_cast<float>(LOWER_LIMIT);
|
||||
static float step_r_ = -0.5f; // Paso flotante para transiciones suaves
|
||||
static float step_g_ = 0.3f;
|
||||
static float step_b_ = 0.1f;
|
||||
static float step_r_ = -0.5F; // Paso flotante para transiciones suaves
|
||||
static float step_g_ = 0.3F;
|
||||
static float step_b_ = 0.1F;
|
||||
|
||||
// Ajustar valores de R
|
||||
r_ += step_r_;
|
||||
|
||||
@@ -103,7 +103,7 @@ class Credits {
|
||||
// --- Métodos del bucle principal ---
|
||||
void update(); // Actualización principal de la lógica
|
||||
void render(); // Renderizado de la escena
|
||||
void checkEvents(); // Manejo de eventos
|
||||
static void checkEvents(); // Manejo de eventos
|
||||
void checkInput(); // Procesamiento de entrada
|
||||
|
||||
// --- Métodos de renderizado ---
|
||||
@@ -124,6 +124,6 @@ class Credits {
|
||||
void updateRedRect(); // Actualizar rectángulo rojo (borde)
|
||||
|
||||
// --- Métodos de audio ---
|
||||
void setVolume(int amount); // Establecer volumen
|
||||
void resetVolume(); // Restablecer volumen
|
||||
static void setVolume(int amount); // Establecer volumen
|
||||
void resetVolume() const; // Restablecer volumen
|
||||
};
|
||||
@@ -90,10 +90,11 @@ Game::Game(int player_id, int current_stage, bool demo)
|
||||
|
||||
#ifdef DEBUG
|
||||
// Si se empieza en una fase que no es la primera
|
||||
if (!demo_.enabled)
|
||||
if (!demo_.enabled) {
|
||||
for (int i = 0; i < Stage::number; ++i) {
|
||||
Stage::total_power += Stage::get(i).power_to_complete;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ void Game::updateHiScore() {
|
||||
hi_score_.name.clear();
|
||||
|
||||
// Si se supera la máxima puntuación emite sonido
|
||||
if (hi_score_achieved_ == false) {
|
||||
if (!hi_score_achieved_) {
|
||||
hi_score_achieved_ = true;
|
||||
playSound("hi_score_achieved.wav");
|
||||
}
|
||||
@@ -299,7 +300,7 @@ void Game::updateGameStateGameOver() {
|
||||
|
||||
if (fade_out_->isEnabled()) {
|
||||
if (Options::audio.enabled) {
|
||||
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0f;
|
||||
const float VOL = static_cast<float>(64 * (100 - fade_out_->getValue())) / 100.0F;
|
||||
Audio::get()->setSoundVolume(static_cast<int>(VOL), Audio::Group::GAME);
|
||||
}
|
||||
}
|
||||
@@ -353,13 +354,14 @@ void Game::updateGameStateCompleted() {
|
||||
createMessage({paths_.at(4), paths_.at(5)}, Resource::get()->getTexture("game_text_congratulations"));
|
||||
createMessage({paths_.at(6), paths_.at(7)}, Resource::get()->getTexture("game_text_1000000_points"));
|
||||
|
||||
for (auto &player : players_)
|
||||
for (auto &player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
player->addScore(1000000);
|
||||
player->setPlayingState(PlayerState::CELEBRATING);
|
||||
} else {
|
||||
player->setPlayingState(PlayerState::GAME_OVER);
|
||||
}
|
||||
}
|
||||
|
||||
updateHiScore();
|
||||
}
|
||||
@@ -374,7 +376,7 @@ void Game::updateGameStateCompleted() {
|
||||
}
|
||||
|
||||
// Si los jugadores ya no estan y no quedan mensajes en pantalla
|
||||
if (allPlayersAreGameOver() && path_sprites_.size() == 0) {
|
||||
if (allPlayersAreGameOver() && path_sprites_.empty()) {
|
||||
setState(GameState::GAME_OVER);
|
||||
}
|
||||
|
||||
@@ -395,8 +397,9 @@ void Game::checkState() {
|
||||
|
||||
// Destruye todos los items
|
||||
void Game::destroyAllItems() {
|
||||
for (auto &item : items_)
|
||||
for (auto &item : items_) {
|
||||
item->disable();
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
@@ -414,8 +417,9 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
||||
|
||||
// Comprueba la colisión entre el jugador y los items
|
||||
void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||
if (!player->isPlaying())
|
||||
if (!player->isPlaying()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &item : items_) {
|
||||
if (item->isEnabled()) {
|
||||
@@ -492,7 +496,7 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||
void Game::checkBulletCollision() {
|
||||
for (auto &bullet : bullets_) {
|
||||
// Comprueba la colisión con el Tabe
|
||||
if (bullet->isEnabled() && tabe_->isEnabled())
|
||||
if (bullet->isEnabled() && tabe_->isEnabled()) {
|
||||
if (checkCollision(bullet->getCollider(), tabe_->getCollider())) {
|
||||
tabe_->setState(TabeState::HIT);
|
||||
bullet->disable();
|
||||
@@ -508,6 +512,7 @@ void Game::checkBulletCollision() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba la colisión con los globos
|
||||
for (auto &balloon : balloon_manager_->getBalloons()) {
|
||||
@@ -559,8 +564,9 @@ void Game::updateBullets() {
|
||||
|
||||
// Pinta las balas activas
|
||||
void Game::renderBullets() {
|
||||
for (auto &bullet : bullets_)
|
||||
for (auto &bullet : bullets_) {
|
||||
bullet->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Crea un objeto bala
|
||||
@@ -570,15 +576,18 @@ void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owne
|
||||
|
||||
// Vacia el vector de balas
|
||||
void Game::freeBullets() {
|
||||
if (!bullets_.empty())
|
||||
for (int i = bullets_.size() - 1; i >= 0; --i)
|
||||
if (!bullets_[i]->isEnabled())
|
||||
if (!bullets_.empty()) {
|
||||
for (int i = bullets_.size() - 1; i >= 0; --i) {
|
||||
if (!bullets_[i]->isEnabled()) {
|
||||
bullets_.erase(bullets_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los items
|
||||
void Game::updateItems() {
|
||||
for (auto &item : items_)
|
||||
for (auto &item : items_) {
|
||||
if (item->isEnabled()) {
|
||||
item->update();
|
||||
if (item->isOnFloor()) {
|
||||
@@ -586,12 +595,14 @@ void Game::updateItems() {
|
||||
screen_->shake(1, 2, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta los items activos
|
||||
void Game::renderItems() {
|
||||
for (auto &item : items_)
|
||||
for (auto &item : items_) {
|
||||
item->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve un item al azar y luego segun sus probabilidades
|
||||
@@ -657,10 +668,13 @@ void Game::createItem(ItemType type, float x, float y) {
|
||||
|
||||
// Vacia el vector de items
|
||||
void Game::freeItems() {
|
||||
if (!items_.empty())
|
||||
for (int i = items_.size() - 1; i >= 0; --i)
|
||||
if (!items_[i]->isEnabled())
|
||||
if (!items_.empty()) {
|
||||
for (int i = items_.size() - 1; i >= 0; --i) {
|
||||
if (!items_[i]->isEnabled()) {
|
||||
items_.erase(items_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea un objeto PathSprite
|
||||
@@ -699,18 +713,24 @@ void Game::createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture
|
||||
|
||||
// Vacia el vector de smartsprites
|
||||
void Game::freeSmartSprites() {
|
||||
if (!smart_sprites_.empty())
|
||||
for (int i = smart_sprites_.size() - 1; i >= 0; --i)
|
||||
if (smart_sprites_[i]->hasFinished())
|
||||
if (!smart_sprites_.empty()) {
|
||||
for (int i = smart_sprites_.size() - 1; i >= 0; --i) {
|
||||
if (smart_sprites_[i]->hasFinished()) {
|
||||
smart_sprites_.erase(smart_sprites_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Vacia el vector de pathsprites
|
||||
void Game::freePathSprites() {
|
||||
if (!path_sprites_.empty())
|
||||
for (int i = path_sprites_.size() - 1; i >= 0; --i)
|
||||
if (path_sprites_[i]->hasFinished())
|
||||
if (!path_sprites_.empty()) {
|
||||
for (int i = path_sprites_.size() - 1; i >= 0; --i) {
|
||||
if (path_sprites_[i]->hasFinished()) {
|
||||
path_sprites_.erase(path_sprites_.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea un SpriteSmart para arrojar el item café al recibir un impacto
|
||||
@@ -721,10 +741,10 @@ void Game::throwCoffee(int x, int y) {
|
||||
smart_sprites_.back()->setPosY(y - 8);
|
||||
smart_sprites_.back()->setWidth(param.game.item_size);
|
||||
smart_sprites_.back()->setHeight(param.game.item_size);
|
||||
smart_sprites_.back()->setVelX(-1.0f + ((rand() % 5) * 0.5f));
|
||||
smart_sprites_.back()->setVelY(-4.0f);
|
||||
smart_sprites_.back()->setAccelX(0.0f);
|
||||
smart_sprites_.back()->setAccelY(0.2f);
|
||||
smart_sprites_.back()->setVelX(-1.0F + ((rand() % 5) * 0.5F));
|
||||
smart_sprites_.back()->setVelY(-4.0F);
|
||||
smart_sprites_.back()->setAccelX(0.0F);
|
||||
smart_sprites_.back()->setAccelY(0.2F);
|
||||
smart_sprites_.back()->setDestX(x + (smart_sprites_.back()->getVelX() * 50));
|
||||
smart_sprites_.back()->setDestY(param.game.height + 1);
|
||||
smart_sprites_.back()->setEnabled(true);
|
||||
@@ -865,14 +885,14 @@ void Game::updateBackground() {
|
||||
}
|
||||
|
||||
// Calcula la velocidad en función de los globos explotados y el total de globos a explotar para acabar el juego
|
||||
constexpr float CLOUDS_INITIAL_SPEED = 0.05f;
|
||||
constexpr float CLOUDS_FINAL_SPEED = 2.00f - CLOUDS_INITIAL_SPEED;
|
||||
constexpr float CLOUDS_INITIAL_SPEED = 0.05F;
|
||||
constexpr float CLOUDS_FINAL_SPEED = 2.00F - CLOUDS_INITIAL_SPEED;
|
||||
const float CLOUDS_SPEED = (-CLOUDS_INITIAL_SPEED) + (-CLOUDS_FINAL_SPEED * (static_cast<float>(Stage::total_power) / total_power_to_complete_game_));
|
||||
background_->setCloudsSpeed(CLOUDS_SPEED);
|
||||
|
||||
// Calcula la transición de los diferentes fondos
|
||||
constexpr float NUM = 1525.0f; // total_power_to_complete div 4
|
||||
const float GRADIENT_NUMBER = std::min(Stage::total_power / NUM, 3.0f);
|
||||
constexpr float NUM = 1525.0F; // total_power_to_complete div 4
|
||||
const float GRADIENT_NUMBER = std::min(Stage::total_power / NUM, 3.0F);
|
||||
const float PERCENT = GRADIENT_NUMBER - static_cast<int>(GRADIENT_NUMBER);
|
||||
background_->setGradientNumber(static_cast<int>(GRADIENT_NUMBER));
|
||||
background_->setTransition(PERCENT);
|
||||
@@ -889,7 +909,7 @@ void Game::updateBackground() {
|
||||
// Dibuja los elementos de la zona de juego en su textura
|
||||
void Game::fillCanvas() {
|
||||
// Dibujamos el contenido de la zona de juego en su textura
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, canvas_);
|
||||
|
||||
// Dibuja los objetos
|
||||
@@ -1024,8 +1044,9 @@ void Game::updateHelper() {
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
auto Game::allPlayersAreWaitingOrGameOver() -> bool {
|
||||
auto success = true;
|
||||
for (const auto &player : players_)
|
||||
for (const auto &player : players_) {
|
||||
success &= player->isWaiting() || player->isGameOver();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -1033,8 +1054,9 @@ auto Game::allPlayersAreWaitingOrGameOver() -> bool {
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
auto Game::allPlayersAreGameOver() -> bool {
|
||||
auto success = true;
|
||||
for (const auto &player : players_)
|
||||
for (const auto &player : players_) {
|
||||
success &= player->isGameOver();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -1042,8 +1064,9 @@ auto Game::allPlayersAreGameOver() -> bool {
|
||||
// Comprueba si todos los jugadores han terminado de jugar
|
||||
auto Game::allPlayersAreNotPlaying() -> bool {
|
||||
auto success = true;
|
||||
for (const auto &player : players_)
|
||||
for (const auto &player : players_) {
|
||||
success &= !player->isPlaying();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -1190,7 +1213,7 @@ void Game::checkPauseInput() {
|
||||
|
||||
// Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
|
||||
void Game::demoHandlePassInput() {
|
||||
if (input_->checkAnyButton()) {
|
||||
if (input_->checkAnyButton() != 0) {
|
||||
Section::name = Section::Name::TITLE; // Salir del modo demo y regresar al menú principal.
|
||||
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO; // El juego volverá a mostrar la demo
|
||||
return;
|
||||
@@ -1423,8 +1446,9 @@ void Game::initDemo(int player_id) {
|
||||
|
||||
// Asigna cafes a los jugadores
|
||||
for (auto &player : players_) {
|
||||
for (int i = 0; i < rand() % 3; ++i)
|
||||
for (int i = 0; i < rand() % 3; ++i) {
|
||||
player->giveExtraHit();
|
||||
}
|
||||
|
||||
player->setInvulnerable(true);
|
||||
}
|
||||
@@ -1472,21 +1496,21 @@ void Game::initDifficultyVars() {
|
||||
switch (difficulty_) {
|
||||
case Options::DifficultyCode::EASY: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||
difficulty_score_multiplier_ = 0.5f;
|
||||
difficulty_score_multiplier_ = 0.5F;
|
||||
scoreboard_->setColor(param.scoreboard.easy_color);
|
||||
break;
|
||||
}
|
||||
|
||||
case Options::DifficultyCode::NORMAL: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[0]);
|
||||
difficulty_score_multiplier_ = 1.0f;
|
||||
difficulty_score_multiplier_ = 1.0F;
|
||||
scoreboard_->setColor(param.scoreboard.normal_color);
|
||||
break;
|
||||
}
|
||||
|
||||
case Options::DifficultyCode::HARD: {
|
||||
balloon_manager_->setDefaultBalloonSpeed(BALLOON_SPEED[4]);
|
||||
difficulty_score_multiplier_ = 1.5f;
|
||||
difficulty_score_multiplier_ = 1.5F;
|
||||
scoreboard_->setColor(param.scoreboard.hard_color);
|
||||
break;
|
||||
}
|
||||
@@ -1530,7 +1554,7 @@ void Game::playMusic() {
|
||||
}
|
||||
|
||||
// Detiene la música
|
||||
void Game::stopMusic() {
|
||||
void Game::stopMusic() const {
|
||||
if (!demo_.enabled) {
|
||||
Audio::get()->stopMusic();
|
||||
}
|
||||
@@ -1539,7 +1563,7 @@ void Game::stopMusic() {
|
||||
// Actualiza las variables durante el modo demo
|
||||
void Game::updateDemo() {
|
||||
if (demo_.enabled) {
|
||||
balloon_manager_->setCreationTimeEnabled((balloon_manager_->getNumBalloons() == 0) ? false : true);
|
||||
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||
|
||||
// Actualiza ambos fades
|
||||
fade_in_->update();
|
||||
@@ -1618,7 +1642,7 @@ void Game::updateGameStateShowingGetReadyMessage() {
|
||||
updateScoreboard();
|
||||
updateBackground();
|
||||
freePathSprites();
|
||||
if (path_sprites_.size() == 0) {
|
||||
if (path_sprites_.empty()) {
|
||||
setState(GameState::PLAYING);
|
||||
}
|
||||
if (counter_ == 100) {
|
||||
@@ -1692,11 +1716,12 @@ void Game::evaluateAndSetMenace() {
|
||||
|
||||
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
|
||||
void Game::checkAndUpdateBalloonSpeed() {
|
||||
if (difficulty_ != Options::DifficultyCode::NORMAL)
|
||||
if (difficulty_ != Options::DifficultyCode::NORMAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const float PERCENT = static_cast<float>(Stage::power) / Stage::get(Stage::number).power_to_complete;
|
||||
constexpr std::array<float, 4> THRESHOLDS = {0.2f, 0.4f, 0.6f, 0.8f};
|
||||
constexpr std::array<float, 4> THRESHOLDS = {0.2F, 0.4F, 0.6F, 0.8F};
|
||||
|
||||
for (size_t i = 0; i < std::size(THRESHOLDS); ++i) {
|
||||
if (balloon_manager_->getBalloonSpeed() == BALLOON_SPEED[i] && PERCENT > THRESHOLDS[i]) {
|
||||
@@ -1712,18 +1737,20 @@ void Game::setState(GameState state) {
|
||||
counter_ = 0;
|
||||
}
|
||||
|
||||
void Game::playSound(const std::string &name) {
|
||||
if (demo_.enabled)
|
||||
void Game::playSound(const std::string &name) const {
|
||||
if (demo_.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
static auto audio_ = Audio::get();
|
||||
static auto *audio_ = Audio::get();
|
||||
audio_->playSound(name);
|
||||
}
|
||||
|
||||
// Organiza los jugadores para que los vivos se pinten sobre los muertos
|
||||
void Game::movePlayersToFront() {
|
||||
if (players_to_reorder_.empty())
|
||||
if (players_to_reorder_.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &player : players_to_reorder_) {
|
||||
auto it = std::find(players_.begin(), players_.end(), player);
|
||||
@@ -1738,8 +1765,9 @@ void Game::movePlayersToFront() {
|
||||
|
||||
// Comprueba si está activo el menu de servicio para poner el juego en pausa
|
||||
void Game::checkServiceMenu() {
|
||||
if (demo_.enabled)
|
||||
if (demo_.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
static bool was_paused_before_service_menu_ = false;
|
||||
static bool service_menu_was_active_ = false;
|
||||
@@ -1761,7 +1789,7 @@ void Game::checkServiceMenu() {
|
||||
#ifdef DEBUG
|
||||
// Comprueba los eventos en el modo DEBUG
|
||||
void Game::checkDebugEvents(const SDL_Event &event) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDLK_1: // Crea una powerball
|
||||
{
|
||||
|
||||
@@ -205,7 +205,7 @@ class Game {
|
||||
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); // Saca del estado de GAME OVER al jugador si el otro está activo
|
||||
void checkPlayersStatusPlaying(); // Comprueba el estado de juego de los jugadores
|
||||
auto getPlayer(int id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
|
||||
auto getController(int player_id) -> int; // Obtiene un controlador a partir del "id" del jugador
|
||||
static auto getController(int player_id) -> int; // Obtiene un controlador a partir del "id" del jugador
|
||||
void checkInput(); // Gestiona la entrada durante el juego
|
||||
void checkPauseInput(); // Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
|
||||
void demoHandleInput(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
||||
@@ -222,9 +222,9 @@ class Game {
|
||||
void initScoreboard(); // Inicializa el marcador
|
||||
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
|
||||
void initPlayers(int player_id); // Inicializa los jugadores
|
||||
void playMusic(); // Hace sonar la música
|
||||
void stopMusic(); // Detiene la música
|
||||
void playSound(const std::string &name); // Hace sonar un sonido
|
||||
static void playMusic(); // Hace sonar la música
|
||||
void stopMusic() const; // Detiene la música
|
||||
void playSound(const std::string &name) const; // Hace sonar un sonido
|
||||
void updateDemo(); // Actualiza las variables durante el modo demo
|
||||
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
|
||||
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado
|
||||
|
||||
@@ -108,55 +108,67 @@ void Title::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
#ifdef DEBUG
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 1) {
|
||||
static Color color_ = param.title.bg_color;
|
||||
switch (event.key.key) {
|
||||
case SDLK_A:
|
||||
if (color_.r < 255)
|
||||
if (color_.r < 255) {
|
||||
++color_.r;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_Z:
|
||||
if (color_.r > 0)
|
||||
if (color_.r > 0) {
|
||||
--color_.r;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_S:
|
||||
if (color_.g < 255)
|
||||
if (color_.g < 255) {
|
||||
++color_.g;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_X:
|
||||
if (color_.g > 0)
|
||||
if (color_.g > 0) {
|
||||
--color_.g;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_D:
|
||||
if (color_.b < 255)
|
||||
if (color_.b < 255) {
|
||||
++color_.b;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_C:
|
||||
if (color_.b > 0)
|
||||
if (color_.b > 0) {
|
||||
--color_.b;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_F:
|
||||
if (color_.r < 255)
|
||||
if (color_.r < 255) {
|
||||
++color_.r;
|
||||
if (color_.g < 255)
|
||||
}
|
||||
if (color_.g < 255) {
|
||||
++color_.g;
|
||||
if (color_.b < 255)
|
||||
}
|
||||
if (color_.b < 255) {
|
||||
++color_.b;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_V:
|
||||
if (color_.r > 0)
|
||||
if (color_.r > 0) {
|
||||
--color_.r;
|
||||
if (color_.g > 0)
|
||||
}
|
||||
if (color_.g > 0) {
|
||||
--color_.g;
|
||||
if (color_.b > 0)
|
||||
}
|
||||
if (color_.b > 0) {
|
||||
--color_.b;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -171,7 +183,7 @@ void Title::checkEvents() {
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDLK_1: // Redefine los botones del mando #0
|
||||
define_buttons_->enable(0);
|
||||
@@ -211,8 +223,9 @@ void Title::checkEvents() {
|
||||
// Comprueba las entradas
|
||||
void Title::checkInput() {
|
||||
// Comprueba las entradas solo si no se estan definiendo los botones
|
||||
if (define_buttons_->isEnabled())
|
||||
if (define_buttons_->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Input::get()->update();
|
||||
|
||||
@@ -263,8 +276,9 @@ void Title::resetCounter() { counter_ = 0; }
|
||||
|
||||
// Intercambia la asignación de mandos a los jugadores
|
||||
void Title::swapControllers() {
|
||||
if (Input::get()->getNumControllers() == 0)
|
||||
if (Input::get()->getNumControllers() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Options::swapControllers();
|
||||
showControllers();
|
||||
@@ -443,8 +457,9 @@ void Title::renderCopyright() {
|
||||
|
||||
// Cambia el estado
|
||||
void Title::setState(TitleState state) {
|
||||
if (state_ == state)
|
||||
if (state_ == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
state_ = state;
|
||||
switch (state_) {
|
||||
|
||||
@@ -83,8 +83,8 @@ class Title {
|
||||
void checkInput(); // Comprueba las entradas
|
||||
void resetCounter(); // Reinicia el contador interno
|
||||
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
|
||||
void swapKeyboard(); // Intercambia el teclado de jugador
|
||||
void showControllers(); // Muestra información sobre los controles y los jugadores
|
||||
static void swapKeyboard(); // Intercambia el teclado de jugador
|
||||
static void showControllers(); // Muestra información sobre los controles y los jugadores
|
||||
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
|
||||
void updateState(); // Actualiza el estado actual del título
|
||||
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
|
||||
|
||||
Reference in New Issue
Block a user