From ef1a514c9b7d4e07554ee3a2ff8f440351b58861 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 22 Oct 2025 19:55:02 +0200 Subject: [PATCH] style: ja pots mouret pel carrusel de posar nom mantenint la direccio apretada (ja no vas lletra a lletra) --- source/player.cpp | 20 ++++++++++++++------ source/player.hpp | 6 ++++-- source/sections/game.cpp | 7 +++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/source/player.cpp b/source/player.cpp index 1c97c9a..df325d4 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -9,6 +9,7 @@ #include "animated_sprite.hpp" // Para AnimatedSprite #include "asset.hpp" // Para Asset #include "audio.hpp" // Para Audio +#include "cooldown.hpp" // Para Cooldown #include "input.hpp" // Para Input #include "input_types.hpp" // Para InputAction #include "manage_hiscore_table.hpp" // Para ManageHiScoreTable, HiScoreEntry @@ -22,6 +23,7 @@ Player::Player(const Config& config) : player_sprite_(std::make_unique(config.texture.at(0), config.animations.at(0))), power_sprite_(std::make_unique(config.texture.at(4), config.animations.at(1))), enter_name_(std::make_unique()), + cooldown_(std::make_unique(0.300F, 0.140F)), hi_score_table_(config.hi_score_table), glowing_entry_(config.glowing_entry), stage_info_(config.stage_info), @@ -150,15 +152,19 @@ void Player::setInputEnteringName(Input::Action action) { } break; case Input::Action::RIGHT: - if (!enter_name_->nameIsFull()) { - enter_name_->incIndex(); - playSound("service_menu_move.wav"); + if (!isShowingName() && !enter_name_->nameIsFull()) { + if (cooldown_->tryConsumeOnHeld()) { + enter_name_->incIndex(); + playSound("service_menu_move.wav"); + } } break; case Input::Action::LEFT: - if (!enter_name_->nameIsFull()) { - enter_name_->decIndex(); - playSound("service_menu_move.wav"); + if (!isShowingName() && !enter_name_->nameIsFull()) { + if (cooldown_->tryConsumeOnHeld()) { + enter_name_->decIndex(); + playSound("service_menu_move.wav"); + } } break; case Input::Action::START: @@ -171,6 +177,7 @@ void Player::setInputEnteringName(Input::Action action) { } break; default: + cooldown_->onReleased(); break; } name_entry_idle_time_accumulator_ = 0.0F; @@ -543,6 +550,7 @@ void Player::update(float delta_time) { updateContinueCounter(delta_time); // Sistema de continue updateEnterNameCounter(delta_time); // Sistema de name entry updateShowingName(delta_time); // Sistema de showing name + cooldown_->update(delta_time); } void Player::passShowingName() { diff --git a/source/player.hpp b/source/player.hpp index 6ea1cc6..de5b4bb 100644 --- a/source/player.hpp +++ b/source/player.hpp @@ -9,8 +9,9 @@ #include // Para move, pair #include // Para vector -#include "animated_sprite.hpp" // for AnimatedSprite -#include "bullet.hpp" // for Bullet +#include "animated_sprite.hpp" // for AnimatedSprite +#include "bullet.hpp" // for Bullet +#include "cooldown.hpp" #include "enter_name.hpp" // for EnterName #include "input.hpp" // for Input #include "manage_hiscore_table.hpp" // for Table @@ -249,6 +250,7 @@ class Player { std::unique_ptr player_sprite_; // Sprite para dibujar el jugador std::unique_ptr power_sprite_; // Sprite para dibujar el aura del jugador con el poder a tope std::unique_ptr enter_name_; // Clase utilizada para introducir el nombre + std::unique_ptr cooldown_ = nullptr; // Objeto para gestionar cooldowns de teclado std::shared_ptr gamepad_ = nullptr; // Dispositivo asociado Table* hi_score_table_ = nullptr; // Tabla de máximas puntuaciones int* glowing_entry_ = nullptr; // Entrada de la tabla de puntuaciones para hacerla brillar diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 18951f2..853c8de 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -1448,12 +1448,12 @@ void Game::handleNameInput(const std::shared_ptr& player) { return; } - if (input_->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { + if (input_->checkAction(Input::Action::LEFT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { player->setInput(Input::Action::LEFT); return; } - if (input_->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { + if (input_->checkAction(Input::Action::RIGHT, Input::ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { player->setInput(Input::Action::RIGHT); return; } @@ -1461,7 +1461,10 @@ void Game::handleNameInput(const std::shared_ptr& player) { if (input_->checkAction(Input::Action::START, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) { player->setInput(Input::Action::START); updateHiScoreName(); + return; } + + player->setInput(Input::Action::NONE); } // Inicializa las variables para el modo DEMO