Afegit dos timeouts per a posar nom: uno total i altre que suma nomes quan no es toca res

This commit is contained in:
2025-07-01 10:56:55 +02:00
parent c00738b8e2
commit 586d5df015
6 changed files with 87 additions and 69 deletions

View File

@@ -1,20 +1,19 @@
#include "player.h"
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <stdlib.h> // Para rand
#include <algorithm> // Para clamp, max, min
#include <array> // Para array
#include "animated_sprite.h" // Para AnimatedSprite
#include "input.h" // Para InputAction
#include "audio.h" // Para JA_PlaySound
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
#include "stage.h" // Para power_can_be_added
#include "texture.h" // Para Texture
#include <SDL3/SDL_surface.h> // Para SDL_FlipMode
#include <SDL3/SDL_timer.h> // Para SDL_GetTicks
#include <stdlib.h> // Para rand
#include <algorithm> // Para clamp, max, min
#include <array> // Para array
#include "animated_sprite.h" // Para AnimatedSprite
#include "input.h" // Para InputAction
#include "audio.h" // Para JA_PlaySound
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "scoreboard.h" // Para Scoreboard, ScoreboardMode
#include "stage.h" // Para power_can_be_added
#include "texture.h" // Para Texture
#include "manage_hiscore_table.h" // Para ManageHiScoreTable, HiScoreEntry
// Constructor
Player::Player(int id, float x, int y, bool demo, SDL_FRect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
: player_sprite_(std::make_unique<AnimatedSprite>(texture[0], animations[0])),
@@ -53,8 +52,9 @@ void Player::init()
coffees_ = 0;
continue_ticks_ = 0;
continue_counter_ = 10;
enter_name_ticks_ = 0;
enter_name_counter_ = param.game.enter_name_seconds;
name_entry_ticks_ = 0;
name_entry_idle_counter_ = 0;
name_entry_total_counter_ = 0;
shiftColliders();
vel_x_ = 0;
vel_y_ = 0;
@@ -156,6 +156,7 @@ void Player::setInputEnteringName(InputAction input)
default:
break;
}
name_entry_idle_counter_ = 0;
}
// Mueve el jugador a la posición y animación que le corresponde
@@ -738,9 +739,9 @@ void Player::updateEnterNameCounter()
if (playing_state_ == PlayerState::ENTERING_NAME || playing_state_ == PlayerState::ENTERING_NAME_GAME_COMPLETED)
{
constexpr int TICKS_SPEED = 1000;
if (SDL_GetTicks() - enter_name_ticks_ > TICKS_SPEED)
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED)
{
decEnterNameCounter();
decNameEntryCounter();
}
}
}
@@ -751,7 +752,7 @@ void Player::updateShowingName()
if (playing_state_ == PlayerState::SHOWING_NAME)
{
constexpr int TICKS_SPEED = 5000;
if (SDL_GetTicks() - enter_name_ticks_ > TICKS_SPEED)
if (SDL_GetTicks() - name_entry_ticks_ > TICKS_SPEED)
{
game_completed_ ? setPlayingState(PlayerState::LEAVING_SCREEN) : setPlayingState(PlayerState::CONTINUE);
}
@@ -774,13 +775,20 @@ void Player::decContinueCounter()
}
// Decrementa el contador de entrar nombre
void Player::decEnterNameCounter()
void Player::decNameEntryCounter()
{
enter_name_ticks_ = SDL_GetTicks();
--enter_name_counter_;
if (enter_name_counter_ < 0)
name_entry_ticks_ = SDL_GetTicks();
// Actualiza contadores
++name_entry_idle_counter_;
++name_entry_total_counter_;
// Comprueba los contadores
if ((name_entry_total_counter_ >= param.game.name_entry_total_time) ||
(name_entry_idle_counter_ >= param.game.name_entry_idle_time))
{
enter_name_counter_ = param.game.enter_name_seconds;
name_entry_total_counter_ = 0;
name_entry_idle_counter_ = 0;
if (playing_state_ == PlayerState::ENTERING_NAME)
{
last_enter_name_ = getRecordName();