linter: varios
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
bool AssetIntegrated::resource_pack_enabled_ = false;
|
bool AssetIntegrated::resource_pack_enabled = false;
|
||||||
|
|
||||||
void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
|
void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
|
||||||
const std::string& resource_pack_path) {
|
const std::string& resource_pack_path) {
|
||||||
@@ -14,29 +14,29 @@ void AssetIntegrated::initWithResourcePack(const std::string& executable_path,
|
|||||||
// Inicializar ResourceLoader
|
// Inicializar ResourceLoader
|
||||||
auto& loader = ResourceLoader::getInstance();
|
auto& loader = ResourceLoader::getInstance();
|
||||||
if (loader.initialize(resource_pack_path, true)) {
|
if (loader.initialize(resource_pack_path, true)) {
|
||||||
resource_pack_enabled_ = true;
|
resource_pack_enabled = true;
|
||||||
std::cout << "Asset system initialized with resource pack: " << resource_pack_path << std::endl;
|
std::cout << "Asset system initialized with resource pack: " << resource_pack_path << std::endl;
|
||||||
} else {
|
} else {
|
||||||
resource_pack_enabled_ = false;
|
resource_pack_enabled = false;
|
||||||
std::cout << "Asset system initialized in fallback mode (filesystem)" << std::endl;
|
std::cout << "Asset system initialized in fallback mode (filesystem)" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
||||||
if (shouldUseResourcePack(filename) && resource_pack_enabled_) {
|
if (shouldUseResourcePack(filename) && resource_pack_enabled) {
|
||||||
// Intentar cargar del pack de recursos
|
// Intentar cargar del pack de recursos
|
||||||
auto& loader = ResourceLoader::getInstance();
|
auto& loader = ResourceLoader::getInstance();
|
||||||
|
|
||||||
// Convertir ruta completa a ruta relativa para el pack
|
// Convertir ruta completa a ruta relativa para el pack
|
||||||
std::string relativePath = filename;
|
std::string relative_path = filename;
|
||||||
|
|
||||||
// Si la ruta contiene "data/", extraer la parte relativa
|
// Si la ruta contiene "data/", extraer la parte relativa
|
||||||
size_t dataPos = filename.find("data/");
|
size_t data_pos = filename.find("data/");
|
||||||
if (dataPos != std::string::npos) {
|
if (data_pos != std::string::npos) {
|
||||||
relativePath = filename.substr(dataPos + 5); // +5 para saltar "data/"
|
relative_path = filename.substr(data_pos + 5); // +5 para saltar "data/"
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = loader.loadResource(relativePath);
|
auto data = loader.loadResource(relative_path);
|
||||||
if (!data.empty()) {
|
if (!data.empty()) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -49,11 +49,11 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::streamsize fileSize = file.tellg();
|
std::streamsize file_size = file.tellg();
|
||||||
file.seekg(0, std::ios::beg);
|
file.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
std::vector<uint8_t> data(fileSize);
|
std::vector<uint8_t> data(file_size);
|
||||||
if (!file.read(reinterpret_cast<char*>(data.data()), fileSize)) {
|
if (!file.read(reinterpret_cast<char*>(data.data()), file_size)) {
|
||||||
std::cerr << "Error: Could not read file: " << filename << std::endl;
|
std::cerr << "Error: Could not read file: " << filename << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -62,14 +62,14 @@ std::vector<uint8_t> AssetIntegrated::loadFile(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool AssetIntegrated::fileExists(const std::string& filename) const {
|
bool AssetIntegrated::fileExists(const std::string& filename) const {
|
||||||
if (shouldUseResourcePack(filename) && resource_pack_enabled_) {
|
if (shouldUseResourcePack(filename) && resource_pack_enabled) {
|
||||||
auto& loader = ResourceLoader::getInstance();
|
auto& loader = ResourceLoader::getInstance();
|
||||||
|
|
||||||
// Convertir ruta completa a ruta relativa para el pack
|
// Convertir ruta completa a ruta relativa para el pack
|
||||||
std::string relativePath = filename;
|
std::string relativePath = filename;
|
||||||
size_t dataPos = filename.find("data/");
|
size_t data_pos = filename.find("data/");
|
||||||
if (dataPos != std::string::npos) {
|
if (data_pos != std::string::npos) {
|
||||||
relativePath = filename.substr(dataPos + 5);
|
relativePath = filename.substr(data_pos + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loader.resourceExists(relativePath)) {
|
if (loader.resourceExists(relativePath)) {
|
||||||
|
|||||||
@@ -2,23 +2,23 @@
|
|||||||
|
|
||||||
class Cooldown {
|
class Cooldown {
|
||||||
public:
|
public:
|
||||||
Cooldown(float first_delay_s = 0.0f, float repeat_delay_s = 0.0f)
|
Cooldown(float first_delay_s = 0.0F, float repeat_delay_s = 0.0F)
|
||||||
: first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s),
|
: first_delay_s_(first_delay_s), repeat_delay_s_(repeat_delay_s),
|
||||||
remaining_s_(0.0f), held_before_(false) {}
|
remaining_s_(0.0F), held_before_(false) {}
|
||||||
|
|
||||||
// Llamar cada frame con delta en segundos (float)
|
// Llamar cada frame con delta en segundos (float)
|
||||||
void update(float delta_s) {
|
void update(float delta_s) {
|
||||||
if (remaining_s_ <= 0.0f) {
|
if (remaining_s_ <= 0.0F) {
|
||||||
remaining_s_ = 0.0f;
|
remaining_s_ = 0.0F;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remaining_s_ -= delta_s;
|
remaining_s_ -= delta_s;
|
||||||
if (remaining_s_ < 0.0f) remaining_s_ = 0.0f;
|
if (remaining_s_ < 0.0F) remaining_s_ = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Llamar cuando el input está activo. Devuelve true si debe ejecutarse la acción ahora.
|
// Llamar cuando el input está activo. Devuelve true si debe ejecutarse la acción ahora.
|
||||||
bool tryConsumeOnHeld() {
|
bool tryConsumeOnHeld() {
|
||||||
if (remaining_s_ > 0.0f) return false;
|
if (remaining_s_ > 0.0F) return false;
|
||||||
|
|
||||||
float delay = held_before_ ? repeat_delay_s_ : first_delay_s_;
|
float delay = held_before_ ? repeat_delay_s_ : first_delay_s_;
|
||||||
remaining_s_ = delay;
|
remaining_s_ = delay;
|
||||||
@@ -29,13 +29,13 @@ public:
|
|||||||
// Llamar cuando el input se suelta
|
// Llamar cuando el input se suelta
|
||||||
void onReleased() {
|
void onReleased() {
|
||||||
held_before_ = false;
|
held_before_ = false;
|
||||||
remaining_s_ = 0.0f;
|
remaining_s_ = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool empty() const { return remaining_s_ == 0.0f; }
|
bool empty() const { return remaining_s_ == 0.0F; }
|
||||||
|
|
||||||
// Fuerza un valor en segundos (útil para tests o resets)
|
// Fuerza un valor en segundos (útil para tests o resets)
|
||||||
void forceSet(float seconds) { remaining_s_ = seconds > 0.0f ? seconds : 0.0f; }
|
void forceSet(float seconds) { remaining_s_ = seconds > 0.0F ? seconds : 0.0F; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float first_delay_s_;
|
float first_delay_s_;
|
||||||
|
|||||||
@@ -228,14 +228,14 @@ void Fade::updateRandomSquare2Fade() {
|
|||||||
squares_to_activate = total_squares;
|
squares_to_activate = total_squares;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < squares_to_activate; ++i) {
|
for (int i = 0; i < squares_to_activate; ++i) {
|
||||||
if (square_age_[i] == -1) square_age_[i] = elapsed_time;
|
if (square_age_[i] == -1) {square_age_[i] = elapsed_time;}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
squares_to_activate = total_squares;
|
squares_to_activate = total_squares;
|
||||||
float activation_progress = static_cast<float>(elapsed_time) / activation_time;
|
float activation_progress = static_cast<float>(elapsed_time) / activation_time;
|
||||||
int squares_starting_transition = std::min(total_squares, std::max(1, static_cast<int>(activation_progress * total_squares)));
|
int squares_starting_transition = std::min(total_squares, std::max(1, static_cast<int>(activation_progress * total_squares)));
|
||||||
for (int i = 0; i < squares_starting_transition; ++i) {
|
for (int i = 0; i < squares_starting_transition; ++i) {
|
||||||
if (square_age_[i] == -1) square_age_[i] = elapsed_time;
|
if (square_age_[i] == -1) {square_age_[i] = elapsed_time;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,8 +452,8 @@ void Fade::activate() {
|
|||||||
// Ahora, inicializamos la modulación de alfa correctamente:
|
// Ahora, inicializamos la modulación de alfa correctamente:
|
||||||
// - IN: Empieza opaco (255) y se desvanece a transparente.
|
// - IN: Empieza opaco (255) y se desvanece a transparente.
|
||||||
// - OUT: Empieza transparente (0) y se desvanece a opaco.
|
// - OUT: Empieza transparente (0) y se desvanece a opaco.
|
||||||
const Uint8 initial_alpha = (mode_ == Mode::IN) ? 255 : 0;
|
const Uint8 INITIAL_ALPHA = (mode_ == Mode::IN) ? 255 : 0;
|
||||||
SDL_SetTextureAlphaMod(backbuffer_, initial_alpha);
|
SDL_SetTextureAlphaMod(backbuffer_, INITIAL_ALPHA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,62 +124,84 @@ void Player::setInputPlaying(Input::Action action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procesa inputs para cuando está introduciendo el nombre
|
// Gestiona la adición de un carácter o la confirmación del nombre.
|
||||||
void Player::setInputEnteringName(Input::Action action) {
|
void Player::handleNameCharacterAddition() {
|
||||||
switch (action) {
|
|
||||||
case Input::Action::FIRE_LEFT: // Añade una letra
|
|
||||||
if (isShowingName()) {
|
|
||||||
passShowingName();
|
|
||||||
} else {
|
|
||||||
if (enter_name_->endCharSelected()) {
|
if (enter_name_->endCharSelected()) {
|
||||||
last_enter_name_ = getRecordName();
|
confirmNameEntry();
|
||||||
setPlayingState(Player::State::SHOWING_NAME);
|
|
||||||
playSound("name_input_accept.wav");
|
|
||||||
} else {
|
} else {
|
||||||
enter_name_->addCharacter();
|
enter_name_->addCharacter();
|
||||||
playSound("service_menu_select.wav");
|
playSound("service_menu_select.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case Input::Action::FIRE_CENTER: // Borra una letra
|
// Gestiona la eliminación del último carácter.
|
||||||
if (isShowingName()) {
|
void Player::handleNameCharacterRemoval() {
|
||||||
passShowingName();
|
|
||||||
} else {
|
|
||||||
if (!enter_name_->nameIsEmpty()) {
|
if (!enter_name_->nameIsEmpty()) {
|
||||||
enter_name_->removeLastCharacter();
|
enter_name_->removeLastCharacter();
|
||||||
playSound("service_menu_back.wav");
|
playSound("service_menu_back.wav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case Input::Action::RIGHT:
|
// Gestiona el movimiento del cursor de selección de letras (izquierda/derecha).
|
||||||
if (!isShowingName() && !enter_name_->nameIsFull()) {
|
void Player::handleNameSelectionMove(Input::Action action) {
|
||||||
|
if (isShowingName() || enter_name_->nameIsFull()) {
|
||||||
|
return; // No hacer nada si se muestra el nombre o si está lleno
|
||||||
|
}
|
||||||
|
|
||||||
if (cooldown_->tryConsumeOnHeld()) {
|
if (cooldown_->tryConsumeOnHeld()) {
|
||||||
|
if (action == Input::Action::RIGHT) {
|
||||||
enter_name_->incIndex();
|
enter_name_->incIndex();
|
||||||
playSound("service_menu_move.wav");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Input::Action::LEFT:
|
|
||||||
if (!isShowingName() && !enter_name_->nameIsFull()) {
|
|
||||||
if (cooldown_->tryConsumeOnHeld()) {
|
|
||||||
enter_name_->decIndex();
|
|
||||||
playSound("service_menu_move.wav");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Input::Action::START:
|
|
||||||
if (isShowingName()) {
|
|
||||||
passShowingName();
|
|
||||||
} else {
|
} else {
|
||||||
|
enter_name_->decIndex();
|
||||||
|
}
|
||||||
|
playSound("service_menu_move.wav");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirma el nombre introducido y cambia el estado del jugador.
|
||||||
|
void Player::confirmNameEntry() {
|
||||||
last_enter_name_ = getRecordName();
|
last_enter_name_ = getRecordName();
|
||||||
setPlayingState(Player::State::SHOWING_NAME);
|
setPlayingState(Player::State::SHOWING_NAME);
|
||||||
playSound("name_input_accept.wav");
|
playSound("name_input_accept.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Procesa inputs para cuando está introduciendo el nombre
|
||||||
|
void Player::setInputEnteringName(Input::Action action) {
|
||||||
|
switch (action) {
|
||||||
|
case Input::Action::FIRE_LEFT:
|
||||||
|
if (isShowingName()) {
|
||||||
|
passShowingName();
|
||||||
|
} else {
|
||||||
|
handleNameCharacterAddition();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Input::Action::FIRE_CENTER:
|
||||||
|
if (isShowingName()) {
|
||||||
|
passShowingName();
|
||||||
|
} else {
|
||||||
|
handleNameCharacterRemoval();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Input::Action::START:
|
||||||
|
if (isShowingName()) {
|
||||||
|
passShowingName();
|
||||||
|
} else {
|
||||||
|
confirmNameEntry();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Input::Action::RIGHT:
|
||||||
|
case Input::Action::LEFT:
|
||||||
|
handleNameSelectionMove(action);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cooldown_->onReleased();
|
cooldown_->onReleased();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
name_entry_idle_time_accumulator_ = 0.0F;
|
name_entry_idle_time_accumulator_ = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -394,6 +394,12 @@ class Player {
|
|||||||
void handleWaitingMovement(float delta_time); // Animación del jugador saludando
|
void handleWaitingMovement(float delta_time); // Animación del jugador saludando
|
||||||
void updateWalkingStateForCredits(); // Actualiza estado de caminata en créditos
|
void updateWalkingStateForCredits(); // Actualiza estado de caminata en créditos
|
||||||
|
|
||||||
|
// --- Introducción de nombre ---
|
||||||
|
void handleNameCharacterAddition();
|
||||||
|
void handleNameCharacterRemoval();
|
||||||
|
void handleNameSelectionMove(Input::Action action);
|
||||||
|
void confirmNameEntry();
|
||||||
|
|
||||||
// --- Utilidades de animación ---
|
// --- Utilidades de animación ---
|
||||||
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula animación de movimiento y disparo
|
[[nodiscard]] auto computeAnimation() const -> std::pair<std::string, SDL_FlipMode>; // Calcula animación de movimiento y disparo
|
||||||
};
|
};
|
||||||
@@ -151,22 +151,22 @@ void OpenGLShader::createQuadGeometry() {
|
|||||||
// Formato: x, y, u, v
|
// Formato: x, y, u, v
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
// Posición // TexCoords
|
// Posición // TexCoords
|
||||||
-1.0f,
|
-1.0F,
|
||||||
-1.0f,
|
-1.0F,
|
||||||
0.0f,
|
0.0F,
|
||||||
0.0f, // Inferior izquierda
|
0.0F, // Inferior izquierda
|
||||||
1.0f,
|
1.0F,
|
||||||
-1.0f,
|
-1.0F,
|
||||||
1.0f,
|
1.0F,
|
||||||
0.0f, // Inferior derecha
|
0.0F, // Inferior derecha
|
||||||
1.0f,
|
1.0F,
|
||||||
1.0f,
|
1.0F,
|
||||||
1.0f,
|
1.0F,
|
||||||
1.0f, // Superior derecha
|
1.0F, // Superior derecha
|
||||||
-1.0f,
|
-1.0F,
|
||||||
1.0f,
|
1.0F,
|
||||||
0.0f,
|
0.0F,
|
||||||
1.0f // Superior izquierda
|
1.0F // Superior izquierda
|
||||||
};
|
};
|
||||||
|
|
||||||
// Índices para dibujar el quad con dos triángulos
|
// Índices para dibujar el quad con dos triángulos
|
||||||
|
|||||||
@@ -126,8 +126,11 @@ void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* ente
|
|||||||
// ===== Calcular salto circular =====
|
// ===== Calcular salto circular =====
|
||||||
int delta = selected_index - prev_index;
|
int delta = selected_index - prev_index;
|
||||||
const int LIST_SIZE = static_cast<int>(enter_name_ptr->getCharacterList().size());
|
const int LIST_SIZE = static_cast<int>(enter_name_ptr->getCharacterList().size());
|
||||||
if (delta > LIST_SIZE / 2) delta -= LIST_SIZE;
|
if (delta > LIST_SIZE / 2) {
|
||||||
else if (delta < -LIST_SIZE / 2) delta += LIST_SIZE;
|
delta -= LIST_SIZE;
|
||||||
|
} else if (delta < -LIST_SIZE / 2) {
|
||||||
|
delta += LIST_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Alinear posición actual antes de moverse =====
|
// ===== Alinear posición actual antes de moverse =====
|
||||||
carousel_position_.at(idx) = std::round(carousel_position_.at(idx));
|
carousel_position_.at(idx) = std::round(carousel_position_.at(idx));
|
||||||
@@ -141,8 +144,8 @@ void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* ente
|
|||||||
} else {
|
} else {
|
||||||
// Movimiento largo → animado pero limitado en tiempo
|
// Movimiento largo → animado pero limitado en tiempo
|
||||||
// Normalizamos el salto para que visualmente tarde como mucho el doble
|
// Normalizamos el salto para que visualmente tarde como mucho el doble
|
||||||
const float MAX_DURATION_FACTOR = 2.0f; // máximo 2x la duración de una letra
|
const float MAX_DURATION_FACTOR = 2.0F; // máximo 2x la duración de una letra
|
||||||
const float SPEED_SCALE = std::min(1.0f, MAX_DURATION_FACTOR / static_cast<float>(ABS_DELTA));
|
const float SPEED_SCALE = std::min(1.0F, MAX_DURATION_FACTOR / static_cast<float>(ABS_DELTA));
|
||||||
|
|
||||||
// Guardamos el destino real
|
// Guardamos el destino real
|
||||||
float target = std::round(carousel_position_.at(idx)) + static_cast<float>(delta);
|
float target = std::round(carousel_position_.at(idx)) + static_cast<float>(delta);
|
||||||
@@ -257,7 +260,7 @@ void Scoreboard::updateCarouselAnimation(float delta_time) {
|
|||||||
} else {
|
} else {
|
||||||
// Forzar al target exacto cuando estamos muy cerca
|
// Forzar al target exacto cuando estamos muy cerca
|
||||||
carousel_position_.at(i) = carousel_target_.at(i);
|
carousel_position_.at(i) = carousel_target_.at(i);
|
||||||
carousel_speed_scale_.at(i) = 1.0f; // restaurar velocidad normal
|
carousel_speed_scale_.at(i) = 1.0F; // restaurar velocidad normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,7 +305,7 @@ void Scoreboard::updatePanelPulses(float delta_time) {
|
|||||||
// Desactivar el pulso si ha terminado
|
// Desactivar el pulso si ha terminado
|
||||||
if (pulse.elapsed_s >= pulse.duration_s) {
|
if (pulse.elapsed_s >= pulse.duration_s) {
|
||||||
pulse.active = false;
|
pulse.active = false;
|
||||||
pulse.elapsed_s = 0.0f;
|
pulse.elapsed_s = 0.0F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,7 +314,7 @@ void Scoreboard::updatePanelPulses(float delta_time) {
|
|||||||
void Scoreboard::triggerPanelPulse(Id id, float duration_s) {
|
void Scoreboard::triggerPanelPulse(Id id, float duration_s) {
|
||||||
auto idx = static_cast<size_t>(id);
|
auto idx = static_cast<size_t>(id);
|
||||||
panel_pulse_.at(idx).active = true;
|
panel_pulse_.at(idx).active = true;
|
||||||
panel_pulse_.at(idx).elapsed_s = 0.0f;
|
panel_pulse_.at(idx).elapsed_s = 0.0F;
|
||||||
panel_pulse_.at(idx).duration_s = duration_s;
|
panel_pulse_.at(idx).duration_s = duration_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,7 +740,7 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
|
|||||||
constexpr int HALF_VISIBLE = CAROUSEL_VISIBLE_LETTERS / 2; // 4 letras a cada lado
|
constexpr int HALF_VISIBLE = CAROUSEL_VISIBLE_LETTERS / 2; // 4 letras a cada lado
|
||||||
|
|
||||||
// Posición flotante actual del carrusel (índice en la lista de caracteres)
|
// Posición flotante actual del carrusel (índice en la lista de caracteres)
|
||||||
float CAROUSEL_POS = carousel_position_.at(panel_index);
|
float carousel_pos = carousel_position_.at(panel_index);
|
||||||
const int CHAR_LIST_SIZE = static_cast<int>(char_list.size());
|
const int CHAR_LIST_SIZE = static_cast<int>(char_list.size());
|
||||||
|
|
||||||
// Calcular ancho promedio de una letra (asumimos ancho uniforme)
|
// Calcular ancho promedio de una letra (asumimos ancho uniforme)
|
||||||
@@ -745,17 +748,17 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
|
|||||||
const int CHAR_STEP = AVG_CHAR_WIDTH + EXTRA_SPACING;
|
const int CHAR_STEP = AVG_CHAR_WIDTH + EXTRA_SPACING;
|
||||||
|
|
||||||
// --- Corrección visual de residuales flotantes (evita “baile”) ---
|
// --- Corrección visual de residuales flotantes (evita “baile”) ---
|
||||||
float frac = CAROUSEL_POS - std::floor(CAROUSEL_POS);
|
float frac = carousel_pos - std::floor(carousel_pos);
|
||||||
if (frac > 0.999f || frac < 0.001f) {
|
if (frac > 0.999F || frac < 0.001F) {
|
||||||
CAROUSEL_POS = std::round(CAROUSEL_POS);
|
carousel_pos = std::round(carousel_pos);
|
||||||
frac = 0.0f;
|
frac = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float FRACTIONAL_OFFSET = frac;
|
const float FRACTIONAL_OFFSET = frac;
|
||||||
const int PIXEL_OFFSET = static_cast<int>(FRACTIONAL_OFFSET * CHAR_STEP + 0.5f);
|
const int PIXEL_OFFSET = static_cast<int>(FRACTIONAL_OFFSET * CHAR_STEP + 0.5f);
|
||||||
|
|
||||||
// Índice base en la lista de caracteres (posición central)
|
// Índice base en la lista de caracteres (posición central)
|
||||||
const int BASE_INDEX = static_cast<int>(std::floor(CAROUSEL_POS));
|
const int BASE_INDEX = static_cast<int>(std::floor(carousel_pos));
|
||||||
|
|
||||||
// Calcular posición X inicial (centrar las 9 letras visibles)
|
// Calcular posición X inicial (centrar las 9 letras visibles)
|
||||||
int start_x = center_x - (HALF_VISIBLE * CHAR_STEP) - (AVG_CHAR_WIDTH / 2) - PIXEL_OFFSET;
|
int start_x = center_x - (HALF_VISIBLE * CHAR_STEP) - (AVG_CHAR_WIDTH / 2) - PIXEL_OFFSET;
|
||||||
@@ -770,24 +773,24 @@ void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Calcular distancia circular correcta (corregido el bug de wrap) ---
|
// --- Calcular distancia circular correcta (corregido el bug de wrap) ---
|
||||||
float normalized_pos = std::fmod(CAROUSEL_POS, static_cast<float>(CHAR_LIST_SIZE));
|
float normalized_pos = std::fmod(carousel_pos, static_cast<float>(CHAR_LIST_SIZE));
|
||||||
if (normalized_pos < 0.0f) normalized_pos += static_cast<float>(CHAR_LIST_SIZE);
|
if (normalized_pos < 0.0F) normalized_pos += static_cast<float>(CHAR_LIST_SIZE);
|
||||||
|
|
||||||
float diff = std::abs(static_cast<float>(char_index) - normalized_pos);
|
float diff = std::abs(static_cast<float>(char_index) - normalized_pos);
|
||||||
if (diff > static_cast<float>(CHAR_LIST_SIZE) / 2.0f)
|
if (diff > static_cast<float>(CHAR_LIST_SIZE) / 2.0F)
|
||||||
diff = static_cast<float>(CHAR_LIST_SIZE) - diff;
|
diff = static_cast<float>(CHAR_LIST_SIZE) - diff;
|
||||||
|
|
||||||
const float distance_from_center = diff;
|
const float DISTANCE_FROM_CENTER = diff;
|
||||||
|
|
||||||
// --- Seleccionar color con LERP según la distancia ---
|
// --- Seleccionar color con LERP según la distancia ---
|
||||||
Color letter_color;
|
Color letter_color;
|
||||||
if (distance_from_center < 0.5F) {
|
if (DISTANCE_FROM_CENTER < 0.5F) {
|
||||||
// Letra central → transiciona hacia animated_color_
|
// Letra central → transiciona hacia animated_color_
|
||||||
float lerp_to_animated = distance_from_center / 0.5F; // 0.0 a 1.0
|
float lerp_to_animated = DISTANCE_FROM_CENTER / 0.5F; // 0.0 a 1.0
|
||||||
letter_color = animated_color_.LERP(text_color1_, lerp_to_animated);
|
letter_color = animated_color_.LERP(text_color1_, lerp_to_animated);
|
||||||
} else {
|
} else {
|
||||||
// Letras alejadas → degradan hacia color_ base
|
// Letras alejadas → degradan hacia color_ base
|
||||||
float base_lerp = (distance_from_center - 0.5F) / (HALF_VISIBLE - 0.5F);
|
float base_lerp = (DISTANCE_FROM_CENTER - 0.5F) / (HALF_VISIBLE - 0.5F);
|
||||||
base_lerp = std::min(base_lerp, 1.0F);
|
base_lerp = std::min(base_lerp, 1.0F);
|
||||||
const float LERP_FACTOR = base_lerp * 0.85F;
|
const float LERP_FACTOR = base_lerp * 0.85F;
|
||||||
letter_color = text_color1_.LERP(color_, LERP_FACTOR);
|
letter_color = text_color1_.LERP(color_, LERP_FACTOR);
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ class Scoreboard {
|
|||||||
|
|
||||||
struct PanelPulse {
|
struct PanelPulse {
|
||||||
bool active = false; // Si el pulso está activo
|
bool active = false; // Si el pulso está activo
|
||||||
float elapsed_s = 0.0f; // Tiempo transcurrido desde el inicio
|
float elapsed_s = 0.0F; // Tiempo transcurrido desde el inicio
|
||||||
float duration_s = 0.5f; // Duración total del pulso
|
float duration_s = 0.5F; // Duración total del pulso
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Métodos de singleton ---
|
// --- Métodos de singleton ---
|
||||||
@@ -80,7 +80,7 @@ class Scoreboard {
|
|||||||
void setScore(Id id, int score) { score_.at(static_cast<size_t>(id)) = score; }
|
void setScore(Id id, int score) { score_.at(static_cast<size_t>(id)) = score; }
|
||||||
void setSelectorPos(Id id, int pos) { selector_pos_.at(static_cast<size_t>(id)) = pos; }
|
void setSelectorPos(Id id, int pos) { selector_pos_.at(static_cast<size_t>(id)) = pos; }
|
||||||
void setStage(int stage) { stage_ = stage; }
|
void setStage(int stage) { stage_ = stage; }
|
||||||
void triggerPanelPulse(Id id, float duration_s = 0.5f); // Activa un pulso en el panel especificado
|
void triggerPanelPulse(Id id, float duration_s = 0.5F); // Activa un pulso en el panel especificado
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Objetos y punteros ---
|
// --- Objetos y punteros ---
|
||||||
@@ -117,8 +117,8 @@ class Scoreboard {
|
|||||||
int time_counter_ = 0; // Contador de segundos
|
int time_counter_ = 0; // Contador de segundos
|
||||||
Uint32 name_color_index_ = 0; // Índice actual del color en el ciclo de animación del nombre
|
Uint32 name_color_index_ = 0; // Índice actual del color en el ciclo de animación del nombre
|
||||||
Uint64 name_color_last_update_ = 0; // Último tick de actualización del color del nombre
|
Uint64 name_color_last_update_ = 0; // Último tick de actualización del color del nombre
|
||||||
float power_ = 0; // Poder actual de la fase
|
float power_ = 0.0F; // Poder actual de la fase
|
||||||
std::array<float, static_cast<size_t>(Id::SIZE)> carousel_speed_scale_ = {1.0f, 1.0f, 1.0f};
|
std::array<float, static_cast<size_t>(Id::SIZE)> carousel_speed_scale_ = {1.0F, 1.0F, 1.0F};
|
||||||
|
|
||||||
// --- Constantes ---
|
// --- Constantes ---
|
||||||
static constexpr int CAROUSEL_VISIBLE_LETTERS = 9;
|
static constexpr int CAROUSEL_VISIBLE_LETTERS = 9;
|
||||||
|
|||||||
@@ -409,8 +409,8 @@ void Credits::initPlayers() {
|
|||||||
|
|
||||||
// Actualiza los rectangulos negros (time-based)
|
// Actualiza los rectangulos negros (time-based)
|
||||||
void Credits::updateBlackRects(float delta_time) {
|
void Credits::updateBlackRects(float delta_time) {
|
||||||
if (!initialized_) return;
|
if (!initialized_) { return; }
|
||||||
if (delta_time < 0.0f) delta_time = 0.0f;
|
delta_time = std::max(delta_time, 0.0F);
|
||||||
|
|
||||||
// Fase vertical: hasta que ambos rects verticales estén exactos en su target
|
// Fase vertical: hasta que ambos rects verticales estén exactos en su target
|
||||||
if (!vertical_done_) {
|
if (!vertical_done_) {
|
||||||
@@ -420,15 +420,15 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
|
|
||||||
// top
|
// top
|
||||||
int prev_top_h = static_cast<int>(top_black_rect_.h);
|
int prev_top_h = static_cast<int>(top_black_rect_.h);
|
||||||
top_black_rect_.h = std::min(top_black_rect_.h + 1.0f,
|
top_black_rect_.h = std::min(top_black_rect_.h + 1.0F,
|
||||||
static_cast<float>(param.game.game_area.center_y - 1));
|
static_cast<float>(param.game.game_area.center_y - 1));
|
||||||
int top_delta = static_cast<int>(top_black_rect_.h) - prev_top_h;
|
int top_delta = static_cast<int>(top_black_rect_.h) - prev_top_h;
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
int prev_bottom_h = static_cast<int>(bottom_black_rect_.h);
|
int prev_bottom_h = static_cast<int>(bottom_black_rect_.h);
|
||||||
int prev_bottom_y = static_cast<int>(bottom_black_rect_.y);
|
int prev_bottom_y = static_cast<int>(bottom_black_rect_.y);
|
||||||
bottom_black_rect_.h = bottom_black_rect_.h + 1.0f;
|
bottom_black_rect_.h = bottom_black_rect_.h + 1.0F;
|
||||||
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1.0f,
|
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1.0F,
|
||||||
static_cast<float>(param.game.game_area.center_y + 1));
|
static_cast<float>(param.game.game_area.center_y + 1));
|
||||||
int bottom_steps_by_h = static_cast<int>(bottom_black_rect_.h) - prev_bottom_h;
|
int bottom_steps_by_h = static_cast<int>(bottom_black_rect_.h) - prev_bottom_h;
|
||||||
int bottom_steps_by_y = prev_bottom_y - static_cast<int>(bottom_black_rect_.y);
|
int bottom_steps_by_y = prev_bottom_y - static_cast<int>(bottom_black_rect_.y);
|
||||||
@@ -436,18 +436,18 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
|
|
||||||
int steps_done = top_delta + bottom_steps;
|
int steps_done = top_delta + bottom_steps;
|
||||||
if (steps_done > 0) {
|
if (steps_done > 0) {
|
||||||
current_step_ = std::max(0.0f, current_step_ - static_cast<float>(steps_done));
|
current_step_ = std::max(0.0F, current_step_ - static_cast<float>(steps_done));
|
||||||
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
||||||
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0f, static_cast<float>(initial_volume_)));
|
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_)));
|
||||||
Audio::get()->setMusicVolume(vol_i); // usa tu API de audio aquí
|
Audio::get()->setMusicVolume(vol_i); // usa tu API de audio aquí
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si han alcanzado los objetivos, fijarlos exactamente y marcar done
|
// Si han alcanzado los objetivos, fijarlos exactamente y marcar done
|
||||||
bool top_at_target = static_cast<int>(top_black_rect_.h) == param.game.game_area.center_y - 1;
|
bool top_at_target = static_cast<int>(top_black_rect_.h) == param.game.game_area.center_y - 1.0F;
|
||||||
bool bottom_at_target = static_cast<int>(bottom_black_rect_.y) == param.game.game_area.center_y + 1;
|
bool bottom_at_target = static_cast<int>(bottom_black_rect_.y) == param.game.game_area.center_y + 1.0F;
|
||||||
if (top_at_target && bottom_at_target) {
|
if (top_at_target && bottom_at_target) {
|
||||||
top_black_rect_.h = static_cast<float>(param.game.game_area.center_y - 1);
|
top_black_rect_.h = param.game.game_area.center_y - 1.0F;
|
||||||
bottom_black_rect_.y = static_cast<float>(param.game.game_area.center_y + 1);
|
bottom_black_rect_.y = param.game.game_area.center_y + 1.0F;
|
||||||
vertical_done_ = true;
|
vertical_done_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -480,8 +480,8 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
bool left_at_target = static_cast<int>(left_black_rect_.w) == param.game.game_area.center_x;
|
bool left_at_target = static_cast<int>(left_black_rect_.w) == param.game.game_area.center_x;
|
||||||
bool right_at_target = static_cast<int>(right_black_rect_.x) == param.game.game_area.center_x;
|
bool right_at_target = static_cast<int>(right_black_rect_.x) == param.game.game_area.center_x;
|
||||||
if (left_at_target && right_at_target) {
|
if (left_at_target && right_at_target) {
|
||||||
left_black_rect_.w = static_cast<float>(param.game.game_area.center_x);
|
left_black_rect_.w = param.game.game_area.center_x;
|
||||||
right_black_rect_.x = static_cast<float>(param.game.game_area.center_x);
|
right_black_rect_.x = param.game.game_area.center_x;
|
||||||
horizontal_done_ = true;
|
horizontal_done_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,13 +504,13 @@ void Credits::updateBlackRects(float delta_time) {
|
|||||||
// Actualiza el rectangulo del borde
|
// Actualiza el rectangulo del borde
|
||||||
void Credits::updateBorderRect() {
|
void Credits::updateBorderRect() {
|
||||||
border_rect_.x = left_black_rect_.x + left_black_rect_.w;
|
border_rect_.x = left_black_rect_.x + left_black_rect_.w;
|
||||||
border_rect_.y = top_black_rect_.y + top_black_rect_.h - 1;
|
border_rect_.y = top_black_rect_.y + top_black_rect_.h - 1.0F;
|
||||||
|
|
||||||
float raw_w = right_black_rect_.x - border_rect_.x;
|
float raw_w = right_black_rect_.x - border_rect_.x;
|
||||||
float raw_h = bottom_black_rect_.y - border_rect_.y + 1.0f;
|
float raw_h = bottom_black_rect_.y - border_rect_.y + 1.0F;
|
||||||
|
|
||||||
border_rect_.w = std::max(0.0f, raw_w);
|
border_rect_.w = std::max(0.0F, raw_w);
|
||||||
border_rect_.h = std::max(0.0f, raw_h);
|
border_rect_.h = std::max(0.0F, raw_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado de fade (time-based)
|
// Actualiza el estado de fade (time-based)
|
||||||
@@ -612,25 +612,25 @@ void Credits::renderPlayers() {
|
|||||||
void Credits::initVars() {
|
void Credits::initVars() {
|
||||||
// Inicialización segura de rects tal y como los mostraste
|
// Inicialización segura de rects tal y como los mostraste
|
||||||
top_black_rect_ = {
|
top_black_rect_ = {
|
||||||
play_area_.x,
|
.x = play_area_.x,
|
||||||
param.game.game_area.rect.y,
|
.y = param.game.game_area.rect.y,
|
||||||
play_area_.w,
|
.w = play_area_.w,
|
||||||
black_bars_size_};
|
.h = black_bars_size_};
|
||||||
bottom_black_rect_ = {
|
bottom_black_rect_ = {
|
||||||
play_area_.x,
|
.x = play_area_.x,
|
||||||
param.game.game_area.rect.h - black_bars_size_,
|
.y = param.game.game_area.rect.h - black_bars_size_,
|
||||||
play_area_.w,
|
.w = play_area_.w,
|
||||||
black_bars_size_};
|
.h = black_bars_size_};
|
||||||
left_black_rect_ = {
|
left_black_rect_ = {
|
||||||
play_area_.x,
|
.x = play_area_.x,
|
||||||
param.game.game_area.center_y - 1,
|
.y = param.game.game_area.center_y - 1.0F,
|
||||||
0,
|
.w = 0.0F,
|
||||||
2};
|
.h = 2.0F};
|
||||||
right_black_rect_ = {
|
right_black_rect_ = {
|
||||||
play_area_.x + play_area_.w,
|
.x = play_area_.x + play_area_.w,
|
||||||
param.game.game_area.center_y - 1,
|
.y = param.game.game_area.center_y - 1.0F,
|
||||||
0,
|
.w = 0.0F,
|
||||||
2};
|
.h = 2.0F};
|
||||||
|
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
|
|
||||||
@@ -659,10 +659,10 @@ void Credits::initVars() {
|
|||||||
|
|
||||||
void Credits::startCredits() {
|
void Credits::startCredits() {
|
||||||
// Guardar iniciales (enteros para contar "pasos" por píxel)
|
// Guardar iniciales (enteros para contar "pasos" por píxel)
|
||||||
init_top_h = static_cast<int>(top_black_rect_.h);
|
init_top_h_ = static_cast<int>(top_black_rect_.h);
|
||||||
init_bottom_y = static_cast<int>(bottom_black_rect_.y);
|
init_bottom_y_ = static_cast<int>(bottom_black_rect_.y);
|
||||||
init_left_w = static_cast<int>(left_black_rect_.w);
|
init_left_w_ = static_cast<int>(left_black_rect_.w);
|
||||||
init_right_x = static_cast<int>(right_black_rect_.x);
|
init_right_x_ = static_cast<int>(right_black_rect_.x);
|
||||||
|
|
||||||
// Objetivos
|
// Objetivos
|
||||||
int top_target_h = param.game.game_area.center_y - 1;
|
int top_target_h = param.game.game_area.center_y - 1;
|
||||||
@@ -671,12 +671,12 @@ void Credits::startCredits() {
|
|||||||
int right_target_x = param.game.game_area.center_x;
|
int right_target_x = param.game.game_area.center_x;
|
||||||
|
|
||||||
// Pasos verticales
|
// Pasos verticales
|
||||||
int pasos_top = std::max(0, top_target_h - init_top_h);
|
int pasos_top = std::max(0, top_target_h - init_top_h_);
|
||||||
int pasos_bottom = std::max(0, init_bottom_y - bottom_target_y);
|
int pasos_bottom = std::max(0, init_bottom_y_ - bottom_target_y);
|
||||||
|
|
||||||
// Pasos horizontales. right se mueve a velocidad HORIZONTAL_SPEED, contamos pasos como unidades de movimiento equivalentes
|
// Pasos horizontales. right se mueve a velocidad HORIZONTAL_SPEED, contamos pasos como unidades de movimiento equivalentes
|
||||||
int pasos_left = std::max(0, left_target_w - init_left_w);
|
int pasos_left = std::max(0, left_target_w - init_left_w_);
|
||||||
int dx_right = std::max(0, init_right_x - right_target_x);
|
int dx_right = std::max(0, init_right_x_ - right_target_x);
|
||||||
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
|
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
|
||||||
|
|
||||||
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
|
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
|
||||||
@@ -685,20 +685,20 @@ void Credits::startCredits() {
|
|||||||
current_step_ = static_cast<float>(total_steps_);
|
current_step_ = static_cast<float>(total_steps_);
|
||||||
|
|
||||||
// Reiniciar contadores y estado
|
// Reiniciar contadores y estado
|
||||||
credits_state_.black_rect_accumulator = 0.0f;
|
credits_state_.black_rect_accumulator = 0.0F;
|
||||||
counter_pre_fade_ = 0.0f;
|
counter_pre_fade_ = 0.0F;
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
|
|
||||||
// Asegurar volumen inicial consistente
|
// Asegurar volumen inicial consistente
|
||||||
if (steps_ <= 0) steps_ = 1;
|
if (steps_ <= 0) steps_ = 1;
|
||||||
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
|
||||||
setVolume(static_cast<int>(std::clamp(vol_f, 0.0f, static_cast<float>(initial_volume_))));
|
setVolume(static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el rectángulo del borde si es visible
|
// Dibuja el rectángulo del borde si es visible
|
||||||
void Credits::drawBorderRect() {
|
void Credits::drawBorderRect() {
|
||||||
// Umbral: cualquier valor menor que 1 píxel no se considera visible
|
// Umbral: cualquier valor menor que 1 píxel no se considera visible
|
||||||
constexpr float VISIBLE_THRESHOLD = 1.0f;
|
constexpr float VISIBLE_THRESHOLD = 1.0F;
|
||||||
if (border_rect_.w < VISIBLE_THRESHOLD || border_rect_.h < VISIBLE_THRESHOLD) {
|
if (border_rect_.w < VISIBLE_THRESHOLD || border_rect_.h < VISIBLE_THRESHOLD) {
|
||||||
return; // no dibujar
|
return; // no dibujar
|
||||||
}
|
}
|
||||||
@@ -709,10 +709,10 @@ void Credits::drawBorderRect() {
|
|||||||
|
|
||||||
// Convertir a enteros de forma conservadora para evitar líneas de 1px por redondeo extraño
|
// Convertir a enteros de forma conservadora para evitar líneas de 1px por redondeo extraño
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
r.x = static_cast<int>(std::floor(border_rect_.x + 0.5f));
|
r.x = static_cast<int>(std::floor(border_rect_.x + 0.5F));
|
||||||
r.y = static_cast<int>(std::floor(border_rect_.y + 0.5f));
|
r.y = static_cast<int>(std::floor(border_rect_.y + 0.5F));
|
||||||
r.w = static_cast<int>(std::max(0.0f, std::floor(border_rect_.w + 0.5f)));
|
r.w = static_cast<int>(std::max(0.0f, std::floor(border_rect_.w + 0.5F)));
|
||||||
r.h = static_cast<int>(std::max(0.0f, std::floor(border_rect_.h + 0.5f)));
|
r.h = static_cast<int>(std::max(0.0f, std::floor(border_rect_.h + 0.5F)));
|
||||||
|
|
||||||
if (r.w > 0 && r.h > 0) {
|
if (r.w > 0 && r.h > 0) {
|
||||||
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ class Credits {
|
|||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|
||||||
// --- Guardar estados iniciales para cálculo de pasos ---
|
// --- Guardar estados iniciales para cálculo de pasos ---
|
||||||
int init_top_h = 0;
|
int init_top_h_ = 0;
|
||||||
int init_bottom_y = 0;
|
int init_bottom_y_ = 0;
|
||||||
int init_left_w = 0;
|
int init_left_w_ = 0;
|
||||||
int init_right_x = 0;
|
int init_right_x_ = 0;
|
||||||
|
|
||||||
// --- Variables de estado ---
|
// --- Variables de estado ---
|
||||||
bool fading_ = false; // Estado del fade final
|
bool fading_ = false; // Estado del fade final
|
||||||
|
|||||||
@@ -1961,68 +1961,68 @@ void Game::handleGameOverEvents() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construye (una vez) el drawList a partir del vector principal
|
// Construye (una vez) el draw_list a partir del vector principal
|
||||||
// drawList almacena punteros a los elementos y queda reservado
|
// draw_list almacena punteros a los elementos y queda reservado
|
||||||
void Game::buildPlayerDrawList(const Players& elements, Players& drawList) {
|
void Game::buildPlayerDrawList(const Players& elements, Players& draw_list) {
|
||||||
drawList.clear();
|
draw_list.clear();
|
||||||
drawList.reserve(elements.size());
|
draw_list.reserve(elements.size());
|
||||||
for (const auto& e : elements) drawList.push_back(e); // copia el shared_ptr
|
for (const auto& e : elements) draw_list.push_back(e); // copia el shared_ptr
|
||||||
std::stable_sort(drawList.begin(), drawList.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||||
return a->getZOrder() < b->getZOrder();
|
return a->getZOrder() < b->getZOrder();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza drawList tras cambios en los z_order. Implementación simple:
|
// Actualiza draw_list tras cambios en los z_order. Implementación simple:
|
||||||
// reordena drawList según los z_order actuales. Llamar cuando cambian z_order
|
// reordena draw_list según los z_order actuales. Llamar cuando cambian z_order
|
||||||
void Game::updatePlayerDrawList(const Players& elements, Players& drawList) {
|
void Game::updatePlayerDrawList(const Players& elements, Players& draw_list) {
|
||||||
// Si drawList está vacío o su tamaño no coincide, reconstruirlo.
|
// Si draw_list está vacío o su tamaño no coincide, reconstruirlo.
|
||||||
if (drawList.size() != elements.size()) {
|
if (draw_list.size() != elements.size()) {
|
||||||
buildPlayerDrawList(elements, drawList);
|
buildPlayerDrawList(elements, draw_list);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Dado que apuntan a los mismos elementos, basta ordenar por los z_order actuales.
|
// Dado que apuntan a los mismos elementos, basta ordenar por los z_order actuales.
|
||||||
std::stable_sort(drawList.begin(), drawList.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
std::stable_sort(draw_list.begin(), draw_list.end(), [](const std::shared_ptr<Player>& a, const std::shared_ptr<Player>& b) {
|
||||||
return a->getZOrder() < b->getZOrder();
|
return a->getZOrder() < b->getZOrder();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja en el orden definido por drawList
|
// Dibuja en el orden definido por draw_list
|
||||||
void Game::renderPlayerDrawList(const Players& drawList) {
|
void Game::renderPlayerDrawList(const Players& draw_list) {
|
||||||
for (const auto& e : drawList) e->render();
|
for (const auto& e : draw_list) e->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operaciones sobre z_order que mantienen la invariante y actualizan drawList.
|
// Operaciones sobre z_order que mantienen la invariante y actualizan draw_list.
|
||||||
auto Game::findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t {
|
auto Game::findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t {
|
||||||
for (size_t i = 0; i < elems.size(); ++i)
|
for (size_t i = 0; i < elems.size(); ++i)
|
||||||
if (elems[i] == who) return static_cast<int>(i); // compara shared_ptr directamente
|
if (elems[i] == who) return static_cast<int>(i); // compara shared_ptr directamente
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& drawList) {
|
void Game::sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||||
int idx = findPlayerIndex(elements, who);
|
int idx = findPlayerIndex(elements, who);
|
||||||
if (idx < 0) return; // no encontrado
|
if (idx < 0) return; // no encontrado
|
||||||
const int oldZ = elements[idx]->getZOrder();
|
const int OLD_Z = elements[idx]->getZOrder();
|
||||||
if (oldZ <= 0) return;
|
if (OLD_Z <= 0) return;
|
||||||
for (auto& p : elements) {
|
for (auto& p : elements) {
|
||||||
int z = p->getZOrder();
|
int z = p->getZOrder();
|
||||||
if (z < oldZ) p->setZOrder(z + 1);
|
if (z < OLD_Z) { p->setZOrder(z + 1); }
|
||||||
}
|
}
|
||||||
elements[idx]->setZOrder(0);
|
elements[idx]->setZOrder(0);
|
||||||
updatePlayerDrawList(elements, drawList);
|
updatePlayerDrawList(elements, draw_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& drawList) {
|
void Game::bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list) {
|
||||||
int idx = findPlayerIndex(elements, who);
|
int idx = findPlayerIndex(elements, who);
|
||||||
if (idx < 0) return; // no encontrado
|
if (idx < 0) return; // no encontrado
|
||||||
const int oldZ = elements[idx]->getZOrder();
|
const int OLD_Z = elements[idx]->getZOrder();
|
||||||
const int N = static_cast<int>(elements.size());
|
const int N = static_cast<int>(elements.size());
|
||||||
if (oldZ >= N - 1) return;
|
if (OLD_Z >= N - 1) return;
|
||||||
for (auto& p : elements) {
|
for (auto& p : elements) {
|
||||||
int z = p->getZOrder();
|
int z = p->getZOrder();
|
||||||
if (z > oldZ) p->setZOrder(z - 1);
|
if (z > OLD_Z) p->setZOrder(z - 1);
|
||||||
}
|
}
|
||||||
elements[idx]->setZOrder(N - 1);
|
elements[idx]->setZOrder(N - 1);
|
||||||
updatePlayerDrawList(elements, drawList);
|
updatePlayerDrawList(elements, draw_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|||||||
@@ -336,12 +336,12 @@ class Game {
|
|||||||
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
|
void playSound(const std::string& name) const; // Reproduce un efecto de sonido específico
|
||||||
|
|
||||||
// --- Gestion y dibujado de jugadores en z-order ---
|
// --- Gestion y dibujado de jugadores en z-order ---
|
||||||
void buildPlayerDrawList(const Players& elements, Players& drawList); // Construye el drawList a partir del vector principal
|
void buildPlayerDrawList(const Players& elements, Players& draw_list); // Construye el draw_list a partir del vector principal
|
||||||
void updatePlayerDrawList(const Players& elements, Players& drawList); // Actualiza drawList tras cambios en los z_order
|
void updatePlayerDrawList(const Players& elements, Players& draw_list); // Actualiza draw_list tras cambios en los z_order
|
||||||
void renderPlayerDrawList(const Players& drawList); // Dibuja en el orden definido
|
void renderPlayerDrawList(const Players& draw_list); // Dibuja en el orden definido
|
||||||
static auto findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t;
|
static auto findPlayerIndex(const Players& elems, const std::shared_ptr<Player>& who) -> size_t;
|
||||||
void sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& drawList); // Envia al jugador al fondo de la pantalla
|
void sendPlayerToBack(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list); // Envia al jugador al fondo de la pantalla
|
||||||
void bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& drawList); // Envia al jugador al frente de la pantalla
|
void bringPlayerToFront(Players& elements, const std::shared_ptr<Player>& who, Players& draw_list); // Envia al jugador al frente de la pantalla
|
||||||
|
|
||||||
// --- Varios ---
|
// --- Varios ---
|
||||||
void onPauseStateChanged(bool is_paused);
|
void onPauseStateChanged(bool is_paused);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void UIMessage::updateAnimation(float delta_time) {
|
|||||||
float t = animation_timer_ / ANIMATION_DURATION_S;
|
float t = animation_timer_ / ANIMATION_DURATION_S;
|
||||||
|
|
||||||
// Clamp t entre 0 y 1
|
// Clamp t entre 0 y 1
|
||||||
t = std::min(t, 1.0f);
|
t = std::min(t, 1.0F);
|
||||||
|
|
||||||
if (target_y_ > start_y_) {
|
if (target_y_ > start_y_) {
|
||||||
// Animación de entrada (ease out cubic)
|
// Animación de entrada (ease out cubic)
|
||||||
|
|||||||
Reference in New Issue
Block a user