Compare commits
17 Commits
merdes-nov
...
79033346c0
| Author | SHA1 | Date | |
|---|---|---|---|
| 79033346c0 | |||
| 62b73d6f41 | |||
| 218ddabb5e | |||
| 427f40632a | |||
| a29b4d4379 | |||
| d851cdd2fe | |||
| 3354d00814 | |||
| 7bd7ba84e0 | |||
| 6ad34eaf57 | |||
| b4f2251508 | |||
| 473a52f986 | |||
| bcdd48d622 | |||
| 6985569573 | |||
| 5db43e674d | |||
| 34baa3c97d | |||
| bddb790fe2 | |||
| 6fae12ba02 |
@@ -64,6 +64,7 @@ set(APP_SOURCES
|
||||
source/balloon_manager.cpp
|
||||
source/balloon.cpp
|
||||
source/bullet.cpp
|
||||
source/bullet_manager.cpp
|
||||
source/enter_name.cpp
|
||||
source/explosions.cpp
|
||||
source/game_logo.cpp
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# Variables: ${PREFIX}, ${SYSTEM_FOLDER}
|
||||
|
||||
# Archivos de configuración del sistema (absolutos y opcionales)
|
||||
DATA|${SYSTEM_FOLDER}/config.txt|optional,absolute
|
||||
DATA|${SYSTEM_FOLDER}/config_v2.txt|optional,absolute
|
||||
DATA|${SYSTEM_FOLDER}/controllers.json|optional,absolute
|
||||
DATA|${SYSTEM_FOLDER}/score.bin|optional,absolute
|
||||
|
||||
|
||||
109
source/bullet_manager.cpp
Normal file
109
source/bullet_manager.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "bullet_manager.h"
|
||||
|
||||
#include <algorithm> // Para remove_if
|
||||
|
||||
#include "bullet.h" // Para Bullet
|
||||
#include "param.h" // Para param
|
||||
#include "player.h" // Para Player
|
||||
|
||||
// Constructor
|
||||
BulletManager::BulletManager()
|
||||
: play_area_(param.game.play_area.rect) {
|
||||
}
|
||||
|
||||
// Actualiza el estado de todas las balas
|
||||
void BulletManager::update(float deltaTime) {
|
||||
for (auto& bullet : bullets_) {
|
||||
if (bullet->isEnabled()) {
|
||||
processBulletUpdate(bullet, deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza todas las balas activas
|
||||
void BulletManager::render() {
|
||||
for (auto& bullet : bullets_) {
|
||||
if (bullet->isEnabled()) {
|
||||
bullet->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea una nueva bala
|
||||
void BulletManager::createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner) {
|
||||
bullets_.emplace_back(std::make_shared<Bullet>(x, y, type, color, owner));
|
||||
}
|
||||
|
||||
// Libera balas que ya no están habilitadas
|
||||
void BulletManager::freeBullets() {
|
||||
if (!bullets_.empty()) {
|
||||
// Elimina las balas deshabilitadas del vector
|
||||
bullets_.erase(
|
||||
std::remove_if(bullets_.begin(), bullets_.end(),
|
||||
[](const std::shared_ptr<Bullet>& bullet) {
|
||||
return !bullet->isEnabled();
|
||||
}),
|
||||
bullets_.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Elimina todas las balas
|
||||
void BulletManager::clearAllBullets() {
|
||||
bullets_.clear();
|
||||
}
|
||||
|
||||
// Verifica colisiones de todas las balas
|
||||
void BulletManager::checkCollisions() {
|
||||
for (auto& bullet : bullets_) {
|
||||
if (!bullet->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Verifica colisión con Tabe
|
||||
if (tabe_collision_callback_ && tabe_collision_callback_(bullet)) {
|
||||
break; // Sale del bucle si hubo colisión
|
||||
}
|
||||
|
||||
// Verifica colisión con globos
|
||||
if (balloon_collision_callback_ && balloon_collision_callback_(bullet)) {
|
||||
break; // Sale del bucle si hubo colisión
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el callback para colisión con Tabe
|
||||
void BulletManager::setTabeCollisionCallback(CollisionCallback callback) {
|
||||
tabe_collision_callback_ = callback;
|
||||
}
|
||||
|
||||
// Establece el callback para colisión con globos
|
||||
void BulletManager::setBalloonCollisionCallback(CollisionCallback callback) {
|
||||
balloon_collision_callback_ = callback;
|
||||
}
|
||||
|
||||
// Establece el callback para balas fuera de límites
|
||||
void BulletManager::setOutOfBoundsCallback(OutOfBoundsCallback callback) {
|
||||
out_of_bounds_callback_ = callback;
|
||||
}
|
||||
|
||||
// --- Métodos privados ---
|
||||
|
||||
// Procesa la actualización individual de una bala
|
||||
void BulletManager::processBulletUpdate(const std::shared_ptr<Bullet>& bullet, float deltaTime) {
|
||||
auto status = bullet->update(deltaTime);
|
||||
|
||||
// Si la bala salió de los límites, llama al callback
|
||||
if (status == Bullet::MoveStatus::OUT && out_of_bounds_callback_) {
|
||||
out_of_bounds_callback_(bullet);
|
||||
}
|
||||
}
|
||||
|
||||
// Verifica si la bala está fuera de los límites del área de juego
|
||||
auto BulletManager::isBulletOutOfBounds(const std::shared_ptr<Bullet>& bullet) -> bool {
|
||||
auto collider = bullet->getCollider();
|
||||
|
||||
return (collider.x < play_area_.x ||
|
||||
collider.x > play_area_.x + play_area_.w ||
|
||||
collider.y < play_area_.y ||
|
||||
collider.y > play_area_.y + play_area_.h);
|
||||
}
|
||||
79
source/bullet_manager.h
Normal file
79
source/bullet_manager.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_FRect
|
||||
|
||||
#include <functional> // Para function
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "bullet.h" // Para Bullet
|
||||
#include "utils.h" // Para Circle
|
||||
|
||||
// --- Types ---
|
||||
using Bullets = std::vector<std::shared_ptr<Bullet>>;
|
||||
|
||||
// --- Forward declarations ---
|
||||
class Player;
|
||||
|
||||
// --- Clase BulletManager: gestiona todas las balas del juego ---
|
||||
//
|
||||
// Esta clase se encarga de la gestión completa de las balas del juego,
|
||||
// incluyendo su creación, actualización, renderizado y colisiones.
|
||||
//
|
||||
// Funcionalidades principales:
|
||||
// • Gestión del ciclo de vida: creación, actualización y destrucción de balas
|
||||
// • Renderizado: dibuja todas las balas activas en pantalla
|
||||
// • Detección de colisiones: mediante sistema de callbacks
|
||||
// • Limpieza automática: elimina balas deshabilitadas del contenedor
|
||||
// • Configuración flexible: permite ajustar parámetros de las balas
|
||||
//
|
||||
// La clase utiliza un sistema de callbacks para manejar las colisiones,
|
||||
// permitiendo que la lógica específica del juego permanezca en Game.
|
||||
class BulletManager {
|
||||
public:
|
||||
// --- Types para callbacks ---
|
||||
using CollisionCallback = std::function<bool(const std::shared_ptr<Bullet>&)>;
|
||||
using OutOfBoundsCallback = std::function<void(const std::shared_ptr<Bullet>&)>;
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
BulletManager();
|
||||
~BulletManager() = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(float deltaTime); // Actualiza el estado de las balas (time-based)
|
||||
void render(); // Renderiza las balas en pantalla
|
||||
|
||||
// --- Gestión de balas ---
|
||||
void createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner); // Crea una nueva bala
|
||||
void freeBullets(); // Libera balas que ya no sirven
|
||||
void clearAllBullets(); // Elimina todas las balas
|
||||
|
||||
// --- Detección de colisiones ---
|
||||
void checkCollisions(); // Verifica colisiones de todas las balas
|
||||
void setTabeCollisionCallback(CollisionCallback callback); // Establece callback para colisión con Tabe
|
||||
void setBalloonCollisionCallback(CollisionCallback callback); // Establece callback para colisión con globos
|
||||
void setOutOfBoundsCallback(OutOfBoundsCallback callback); // Establece callback para balas fuera de límites
|
||||
|
||||
// --- Configuración ---
|
||||
void setPlayArea(SDL_FRect play_area) { play_area_ = play_area; }; // Define el área de juego
|
||||
|
||||
// --- Getters ---
|
||||
auto getBullets() -> Bullets& { return bullets_; } // Obtiene referencia al vector de balas
|
||||
[[nodiscard]] auto getNumBullets() const -> int { return bullets_.size(); } // Obtiene el número de balas activas
|
||||
|
||||
private:
|
||||
// --- Objetos y punteros ---
|
||||
Bullets bullets_; // Vector con las balas activas
|
||||
|
||||
// --- Variables de configuración ---
|
||||
SDL_FRect play_area_; // Área de juego para límites
|
||||
|
||||
// --- Callbacks para colisiones ---
|
||||
CollisionCallback tabe_collision_callback_; // Callback para colisión con Tabe
|
||||
CollisionCallback balloon_collision_callback_; // Callback para colisión con globos
|
||||
OutOfBoundsCallback out_of_bounds_callback_; // Callback para balas fuera de límites
|
||||
|
||||
// --- Métodos internos ---
|
||||
void processBulletUpdate(const std::shared_ptr<Bullet>& bullet, float deltaTime); // Procesa actualización individual
|
||||
auto isBulletOutOfBounds(const std::shared_ptr<Bullet>& bullet) -> bool; // Verifica si la bala está fuera de límites
|
||||
};
|
||||
@@ -95,6 +95,29 @@ struct Color {
|
||||
return Color(new_r, new_g, new_b, new_a);
|
||||
}
|
||||
|
||||
// Interpolación lineal hacia otro color (t=0.0: this, t=1.0: target)
|
||||
[[nodiscard]] constexpr auto LERP(const Color &target, float t) const -> Color {
|
||||
// Asegurar que t esté en el rango [0.0, 1.0]
|
||||
t = std::clamp(t, 0.0f, 1.0f);
|
||||
|
||||
// Interpolación lineal para cada componente
|
||||
auto lerp_component = [t](Uint8 start, Uint8 end) -> Uint8 {
|
||||
return static_cast<Uint8>(start + (end - start) * t);
|
||||
};
|
||||
|
||||
return Color(
|
||||
lerp_component(r, target.r),
|
||||
lerp_component(g, target.g),
|
||||
lerp_component(b, target.b),
|
||||
lerp_component(a, target.a)
|
||||
);
|
||||
}
|
||||
|
||||
// Sobrecarga para aceptar componentes RGBA directamente
|
||||
[[nodiscard]] constexpr auto LERP(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, float t) const -> Color {
|
||||
return LERP(Color(red, green, blue, alpha), t);
|
||||
}
|
||||
|
||||
// Convierte el color a un entero de 32 bits en formato RGBA
|
||||
[[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 {
|
||||
return (static_cast<Uint32>(r) << 24) |
|
||||
|
||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
@@ -86,7 +86,7 @@ void Director::init() {
|
||||
#endif
|
||||
loadAssets(); // Crea el índice de archivos
|
||||
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
|
||||
Options::setConfigFile(Asset::get()->get("config.txt")); // Establece el fichero de configuración
|
||||
Options::setConfigFile(Asset::get()->get("config_v2.txt")); // Establece el fichero de configuración
|
||||
Options::setControllersFile(Asset::get()->get("controllers.json")); // Establece el fichero de configuración de mandos
|
||||
Options::loadFromFile(); // Carga el archivo de configuración
|
||||
loadParams(); // Carga los parámetros del programa
|
||||
|
||||
@@ -1,147 +1,96 @@
|
||||
#include "enter_name.h"
|
||||
|
||||
#include <cstddef> // Para size_t
|
||||
#include <array> // Para array
|
||||
#include <cstdlib> // Para rand
|
||||
#include <string_view> // Para basic_string_view, string_view
|
||||
|
||||
#include "utils.h" // Para trim
|
||||
|
||||
// Constructor
|
||||
EnterName::EnterName()
|
||||
: character_list_(" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789."),
|
||||
character_index_{0} {}
|
||||
: character_list_("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789."),
|
||||
selected_index_(0) {}
|
||||
|
||||
// Inicializa el objeto
|
||||
void EnterName::init(const std::string &name) {
|
||||
// No se pasa ningún nombre
|
||||
if (name.empty()) {
|
||||
name_ = "A";
|
||||
position_ = 0;
|
||||
position_overflow_ = false;
|
||||
}
|
||||
// Se pasa un nombre
|
||||
else {
|
||||
name_ = name;
|
||||
position_ = name_.length();
|
||||
position_overflow_ = position_ >= NAME_SIZE;
|
||||
}
|
||||
|
||||
// Inicializa el vector de indices con el nombre y espacios
|
||||
initCharacterIndex(name_);
|
||||
name_ = sanitizeName(name);
|
||||
selected_index_ = 0;
|
||||
}
|
||||
|
||||
// Incrementa la posición
|
||||
void EnterName::incPosition() {
|
||||
if (position_overflow_) {
|
||||
// Si ya estamos en overflow, no incrementamos más.
|
||||
return;
|
||||
}
|
||||
|
||||
++position_;
|
||||
|
||||
if (position_ >= NAME_SIZE) {
|
||||
position_ = NAME_SIZE; // Mantenemos en el índice máximo válido.
|
||||
position_overflow_ = true; // Activamos el flag de overflow.
|
||||
} else if (position_ > 0) // No es necesario verificar position_ < MAX_NAME_LENGTH
|
||||
{
|
||||
// Copiamos el índice del carácter anterior si es posible.
|
||||
// character_index_[position_] = character_index_[position_ - 1];
|
||||
|
||||
// Ponemos el caracter "espacio"
|
||||
character_index_[position_] = 0;
|
||||
} else {
|
||||
// Si position_ es 0, inicializamos el carácter actual.
|
||||
character_index_[position_] = 0;
|
||||
}
|
||||
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
// Decrementa la posición
|
||||
void EnterName::decPosition() {
|
||||
if (position_overflow_) {
|
||||
// Si estaba en overflow, lo desactivamos y mantenemos position_ en el máximo.
|
||||
position_overflow_ = false;
|
||||
position_ = NAME_SIZE - 1;
|
||||
} else {
|
||||
if (position_ > 0) {
|
||||
--position_;
|
||||
|
||||
// Limpiamos el carácter siguiente si el índice es válido.
|
||||
if (position_ + 1 < NAME_SIZE) {
|
||||
character_index_[position_ + 1] = 0;
|
||||
}
|
||||
} else {
|
||||
// Si position_ es 0, aseguramos que no vaya a ser negativo y limpiamos el carácter actual.
|
||||
position_ = 0;
|
||||
// character_index_[position_] = 0;
|
||||
}
|
||||
|
||||
// Si position_ es menor que NAME_LENGTH, aseguramos que el overflow esté desactivado.
|
||||
if (position_ < NAME_SIZE) {
|
||||
position_overflow_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
// Incrementa el índice
|
||||
// Incrementa el índice del carácter seleccionado
|
||||
void EnterName::incIndex() {
|
||||
if (position_overflow_) {
|
||||
return;
|
||||
++selected_index_;
|
||||
if (selected_index_ >= static_cast<int>(character_list_.size())) {
|
||||
selected_index_ = 0;
|
||||
}
|
||||
|
||||
++character_index_[position_];
|
||||
if (character_index_[position_] >= static_cast<int>(character_list_.size())) {
|
||||
character_index_[position_] = 0;
|
||||
}
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
// Decrementa el índice
|
||||
// Decrementa el índice del carácter seleccionado
|
||||
void EnterName::decIndex() {
|
||||
if (position_overflow_) {
|
||||
return;
|
||||
}
|
||||
|
||||
--character_index_[position_];
|
||||
if (character_index_[position_] < 0) {
|
||||
character_index_[position_] = character_list_.size() - 1;
|
||||
}
|
||||
updateNameFromCharacterIndex();
|
||||
}
|
||||
|
||||
// Actualiza el nombre a partir de la lista de índices
|
||||
void EnterName::updateNameFromCharacterIndex() {
|
||||
name_.clear();
|
||||
for (size_t i = 0; i < NAME_SIZE; ++i) {
|
||||
name_.push_back(character_list_[character_index_[i]]);
|
||||
}
|
||||
name_ = trim(name_);
|
||||
}
|
||||
|
||||
// Actualiza la variable
|
||||
void EnterName::initCharacterIndex(const std::string &name) {
|
||||
// Rellena de espacios
|
||||
for (size_t i = 0; i < NAME_SIZE; ++i) {
|
||||
character_index_[i] = 0;
|
||||
}
|
||||
|
||||
// Coloca los índices en función de los caracteres que forman el nombre
|
||||
for (size_t i = 0; i < name.substr(0, NAME_SIZE).size(); ++i) {
|
||||
character_index_[i] = findIndex(name.at(i));
|
||||
--selected_index_;
|
||||
if (selected_index_ < 0) {
|
||||
selected_index_ = character_list_.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Encuentra el indice de un caracter en "character_list_"
|
||||
auto EnterName::findIndex(char character) const -> int {
|
||||
for (size_t i = 0; i < character_list_.size(); ++i) {
|
||||
if (character == character_list_.at(i)) {
|
||||
return i;
|
||||
// Añade el carácter seleccionado al nombre
|
||||
void EnterName::addCharacter() {
|
||||
if (name_.length() < MAX_NAME_SIZE) {
|
||||
name_.push_back(character_list_[selected_index_]);
|
||||
}
|
||||
}
|
||||
|
||||
// Elimina el último carácter del nombre
|
||||
void EnterName::removeLastCharacter() {
|
||||
if (!name_.empty()) {
|
||||
name_.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el carácter seleccionado con offset relativo como string
|
||||
auto EnterName::getSelectedCharacter(int offset) const -> std::string {
|
||||
// Calcular el índice con offset, con wrap-around circular
|
||||
int size = static_cast<int>(character_list_.size());
|
||||
int index = (selected_index_ + offset) % size;
|
||||
|
||||
// Manejar índices negativos (hacer wrap-around hacia atrás)
|
||||
if (index < 0) {
|
||||
index += size;
|
||||
}
|
||||
|
||||
return std::string(1, character_list_[index]);
|
||||
}
|
||||
|
||||
// Devuelve el carrusel completo de caracteres centrado en el seleccionado
|
||||
auto EnterName::getCarousel(int size) const -> std::string {
|
||||
// Asegurar que el tamaño sea impar para tener un centro claro
|
||||
if (size % 2 == 0) {
|
||||
++size;
|
||||
}
|
||||
|
||||
std::string carousel;
|
||||
carousel.reserve(size); // Optimización: reservar memoria de antemano
|
||||
|
||||
int half = size / 2;
|
||||
|
||||
// Construir desde -half hasta +half (inclusive)
|
||||
for (int offset = -half; offset <= half; ++offset) {
|
||||
carousel += getSelectedCharacter(offset);
|
||||
}
|
||||
|
||||
return carousel;
|
||||
}
|
||||
|
||||
// Valida y limpia el nombre: solo caracteres legales y longitud máxima
|
||||
auto EnterName::sanitizeName(const std::string &name) const -> std::string {
|
||||
std::string sanitized;
|
||||
|
||||
for (size_t i = 0; i < name.length() && sanitized.length() < MAX_NAME_SIZE; ++i) {
|
||||
// Verifica si el carácter está en la lista permitida
|
||||
if (character_list_.find(name[i]) != std::string::npos) {
|
||||
sanitized.push_back(name[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
// Devuelve un nombre al azar
|
||||
@@ -157,12 +106,11 @@ auto EnterName::getRandomName() -> std::string {
|
||||
"PEPE"};
|
||||
return std::string(NAMES[rand() % NAMES.size()]);
|
||||
}
|
||||
|
||||
// Obtiene el nombre final introducido
|
||||
auto EnterName::getFinalName() -> std::string {
|
||||
auto name = trim(name_.substr(0, position_ + 1)); // Devuelve el texto intruducido incluyendo el del selector
|
||||
if (name.empty()) {
|
||||
name = getRandomName();
|
||||
if (name_.empty()) {
|
||||
name_ = getRandomName();
|
||||
}
|
||||
name_ = name;
|
||||
return name_;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <array> // Para array
|
||||
#include <cstddef> // Para size_t
|
||||
#include <string> // Para allocator, string
|
||||
|
||||
#include "utils.h" // Para trim
|
||||
|
||||
// --- Constantes ---
|
||||
constexpr size_t NAME_SIZE = 5; // Tamaño máximo del nombre
|
||||
|
||||
// --- Clase EnterName: gestor de entrada de nombre del jugador ---
|
||||
class EnterName {
|
||||
public:
|
||||
// --- Constantes ---
|
||||
static constexpr size_t MAX_NAME_SIZE = 6; // Tamaño máximo del nombre
|
||||
|
||||
EnterName();
|
||||
~EnterName() = default;
|
||||
|
||||
void init(const std::string &name = ""); // Inicializa con un nombre opcional
|
||||
void init(const std::string &name = ""); // Inicializa con nombre opcional (vacío por defecto)
|
||||
|
||||
void incPosition(); // Incrementa la posición del carácter actual
|
||||
void decPosition(); // Decrementa la posición del carácter actual
|
||||
void incIndex(); // Incrementa el índice del carácter en la lista
|
||||
void decIndex(); // Decrementa el índice del carácter en la lista
|
||||
void incIndex(); // Incrementa el índice del carácter seleccionado en la lista
|
||||
void decIndex(); // Decrementa el índice del carácter seleccionado en la lista
|
||||
|
||||
auto getFinalName() -> std::string; // Obtiene el nombre final introducido
|
||||
[[nodiscard]] auto getCurrentName() const -> std::string { return trim(name_); } // Obtiene el nombre actual en proceso
|
||||
void addCharacter(); // Añade el carácter seleccionado al nombre
|
||||
void removeLastCharacter(); // Elimina el último carácter del nombre
|
||||
|
||||
[[nodiscard]] auto getPosition() const -> int { return position_; } // Posición actual del carácter editado
|
||||
[[nodiscard]] auto getPositionOverflow() const -> bool { return position_overflow_; } // Indica si la posición excede el límite
|
||||
auto getFinalName() -> std::string; // Obtiene el nombre final (o aleatorio si vacío)
|
||||
[[nodiscard]] auto getCurrentName() const -> std::string { return name_; } // Obtiene el nombre actual en proceso
|
||||
[[nodiscard]] auto getSelectedCharacter(int offset = 0) const -> std::string; // Devuelve el carácter seleccionado con offset relativo
|
||||
[[nodiscard]] auto getCarousel(int size) const -> std::string; // Devuelve el carrusel de caracteres (size debe ser impar)
|
||||
[[nodiscard]] auto getSelectedIndex() const -> int { return selected_index_; } // Obtiene el índice del carácter seleccionado
|
||||
[[nodiscard]] auto getCharacterList() const -> const std::string& { return character_list_; } // Obtiene la lista completa de caracteres
|
||||
|
||||
private:
|
||||
// --- Variables de estado ---
|
||||
std::string character_list_; // Lista de caracteres permitidos
|
||||
std::string name_; // Nombre en proceso
|
||||
std::array<int, NAME_SIZE> character_index_; // Índices a "character_list_"
|
||||
size_t position_ = 0; // Índice del carácter que se edita
|
||||
bool position_overflow_ = false; // Flag para exceder límite
|
||||
std::string character_list_; // Lista de caracteres permitidos
|
||||
std::string name_; // Nombre en proceso
|
||||
int selected_index_ = 0; // Índice del carácter seleccionado en "character_list_"
|
||||
|
||||
void updateNameFromCharacterIndex(); // Actualiza "name_" según "character_index_"
|
||||
void initCharacterIndex(const std::string &name); // Inicializa índices desde el nombre
|
||||
[[nodiscard]] auto findIndex(char character) const -> int; // Busca el índice de un carácter en "character_list_"
|
||||
static auto getRandomName() -> std::string; // Devuelve un nombre al azar
|
||||
[[nodiscard]] auto sanitizeName(const std::string &name) const -> std::string; // Valida y limpia el nombre
|
||||
static auto getRandomName() -> std::string; // Devuelve un nombre al azar
|
||||
};
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <cstddef> // Para size_t
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ostream::operator<<, basic_ofstream, basic_istream, basic_ifstream, ifstream, ofstream
|
||||
#include <functional> // Para function
|
||||
#include <sstream> // Para istringstream
|
||||
#include <map> // Para map, operator==, _Rb_tree_const_iterator
|
||||
#include <ranges> // Para std::ranges::any_of
|
||||
#include <stdexcept> // Para invalid_argument, out_of_range
|
||||
@@ -64,11 +65,27 @@ auto loadFromFile() -> bool {
|
||||
// --- CASO: EL FICHERO EXISTE ---
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(settings.config_file).c_str());
|
||||
std::string line;
|
||||
std::string param_name;
|
||||
std::string param_value;
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
if (line.substr(0, 1) != "#") {
|
||||
int pos = line.find('=');
|
||||
if (!set(line.substr(0, pos), line.substr(pos + 1, line.length()))) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", line.substr(0, pos).c_str());
|
||||
// Elimina comentarios
|
||||
auto comment_pos = line.find('#');
|
||||
if (comment_pos != std::string::npos) {
|
||||
line.resize(comment_pos);
|
||||
}
|
||||
|
||||
// Si la línea contiene '=', lo reemplazamos por un espacio para compatibilidad
|
||||
auto equals_pos = line.find('=');
|
||||
if (equals_pos != std::string::npos) {
|
||||
line[equals_pos] = ' ';
|
||||
}
|
||||
|
||||
// Usa un stream para separar palabras (elimina automáticamente espacios extra)
|
||||
std::istringstream iss(line);
|
||||
if (iss >> param_name >> param_value) {
|
||||
if (!set(param_name, param_value)) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown parameter: %s", param_name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,49 +117,51 @@ auto saveToFile() -> bool {
|
||||
|
||||
applyPendingChanges();
|
||||
|
||||
// Versión del archivo
|
||||
file << "# Coffee Crisis Arcade Edition - Configuration File\n";
|
||||
file << "# Format: key value\n";
|
||||
file << "config.version " << settings.config_version << "\n";
|
||||
|
||||
// Opciones de ventana
|
||||
file << "## WINDOW\n";
|
||||
file << "window.zoom=" << window.zoom << "\n";
|
||||
file << "\n# WINDOW\n";
|
||||
file << "window.zoom " << window.zoom << "\n";
|
||||
|
||||
// Opciones de video
|
||||
file << "\n## VIDEO\n";
|
||||
file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n";
|
||||
|
||||
file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n";
|
||||
file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n";
|
||||
file << "video.vsync=" << boolToString(video.vsync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(video.shaders) << "\n";
|
||||
file << "\n# VIDEO\n";
|
||||
file << "# video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": linear]\n";
|
||||
file << "video.fullscreen " << boolToString(video.fullscreen) << "\n";
|
||||
file << "video.scale_mode " << static_cast<int>(video.scale_mode) << "\n";
|
||||
file << "video.vsync " << boolToString(video.vsync) << "\n";
|
||||
file << "video.integer_scale " << boolToString(video.integer_scale) << "\n";
|
||||
file << "video.shaders " << boolToString(video.shaders) << "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n## AUDIO\n";
|
||||
file << "## volume [0 .. 100]\n";
|
||||
|
||||
file << "audio.enabled=" << boolToString(audio.enabled) << "\n";
|
||||
file << "audio.volume=" << audio.volume << "\n";
|
||||
file << "audio.music.enabled=" << boolToString(audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume=" << audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled=" << boolToString(audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume=" << audio.sound.volume << "\n";
|
||||
file << "\n# AUDIO\n";
|
||||
file << "# volume range: [0 .. 100]\n";
|
||||
file << "audio.enabled " << boolToString(audio.enabled) << "\n";
|
||||
file << "audio.volume " << audio.volume << "\n";
|
||||
file << "audio.music.enabled " << boolToString(audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume " << audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled " << boolToString(audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume " << audio.sound.volume << "\n";
|
||||
|
||||
// Opciones del juego
|
||||
file << "\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [" << static_cast<int>(Difficulty::Code::EASY) << ": easy, " << static_cast<int>(Difficulty::Code::NORMAL) << ": normal, " << static_cast<int>(Difficulty::Code::HARD) << ": hard]\n";
|
||||
|
||||
file << "game.language=" << static_cast<int>(settings.language) << "\n";
|
||||
file << "game.difficulty=" << static_cast<int>(settings.difficulty) << "\n";
|
||||
file << "game.autofire=" << boolToString(settings.autofire) << "\n";
|
||||
file << "game.shutdown_enabled=" << boolToString(settings.shutdown_enabled) << "\n";
|
||||
file << "game.params_file=" << settings.params_file << "\n";
|
||||
file << "\n# GAME\n";
|
||||
file << "# game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "# game.difficulty [" << static_cast<int>(Difficulty::Code::EASY) << ": easy, " << static_cast<int>(Difficulty::Code::NORMAL) << ": normal, " << static_cast<int>(Difficulty::Code::HARD) << ": hard]\n";
|
||||
file << "game.language " << static_cast<int>(settings.language) << "\n";
|
||||
file << "game.difficulty " << static_cast<int>(settings.difficulty) << "\n";
|
||||
file << "game.autofire " << boolToString(settings.autofire) << "\n";
|
||||
file << "game.shutdown_enabled " << boolToString(settings.shutdown_enabled) << "\n";
|
||||
file << "game.params_file " << settings.params_file << "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n## CONTROLLERS\n";
|
||||
file << "\n# CONTROLLERS\n";
|
||||
gamepad_manager.saveToFile(file);
|
||||
|
||||
// Opciones de teclado
|
||||
file << "\n## KEYBOARD\n";
|
||||
file << "keyboard.player=" << static_cast<int>(keyboard.player_id) << "\n";
|
||||
file << "\n# KEYBOARD\n";
|
||||
file << "keyboard.player " << static_cast<int>(keyboard.player_id) << "\n";
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
@@ -177,6 +196,8 @@ auto set(const std::string& var, const std::string& value) -> bool {
|
||||
|
||||
// Un mapa estático asegura que se inicializa solo una vez
|
||||
static const std::map<std::string, std::function<void(const std::string&)>> SETTINGS_MAP = {
|
||||
// Configuración
|
||||
{"config.version", [](const auto& val) { settings.config_version = std::stoi(val); }},
|
||||
// Ventana
|
||||
{"window.zoom", [](const auto& val) { window.zoom = std::stoi(val); }},
|
||||
// Vídeo
|
||||
|
||||
@@ -58,6 +58,7 @@ struct Audio {
|
||||
};
|
||||
|
||||
struct Settings {
|
||||
int config_version = 2; // Versión del archivo de configuración
|
||||
Difficulty::Code difficulty = Difficulty::Code::NORMAL; // Dificultad del juego
|
||||
Lang::Code language = Lang::Code::VALENCIAN; // Idioma usado en el juego
|
||||
bool autofire = GameDefaults::Options::SETTINGS_AUTOFIRE; // Indicador de autofire
|
||||
@@ -158,12 +159,12 @@ class GamepadManager {
|
||||
const auto& gamepad = gamepads_[i];
|
||||
// Guardar el nombre solo si hay path (mando real asignado)
|
||||
if (!gamepad.path.empty()) {
|
||||
file << "controller." << i << ".name=" << gamepad.name << "\n";
|
||||
file << "controller." << i << ".name " << gamepad.name << "\n";
|
||||
} else {
|
||||
file << "controller." << i << ".name=\n"; // vacío
|
||||
file << "controller." << i << ".name \n"; // vacío
|
||||
}
|
||||
file << "controller." << i << ".path=" << gamepad.path << "\n";
|
||||
file << "controller." << i << ".player=" << static_cast<int>(gamepad.player_id) << "\n";
|
||||
file << "controller." << i << ".path " << gamepad.path << "\n";
|
||||
file << "controller." << i << ".player " << static_cast<int>(gamepad.player_id) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,16 +128,16 @@ void Player::setInputPlaying(Input::Action action) {
|
||||
// Procesa inputs para cuando está introduciendo el nombre
|
||||
void Player::setInputEnteringName(Input::Action action) {
|
||||
switch (action) {
|
||||
case Input::Action::LEFT:
|
||||
enter_name_->decPosition();
|
||||
case Input::Action::FIRE_LEFT:
|
||||
enter_name_->addCharacter();
|
||||
break;
|
||||
case Input::Action::FIRE_CENTER:
|
||||
enter_name_->removeLastCharacter();
|
||||
break;
|
||||
case Input::Action::RIGHT:
|
||||
enter_name_->incPosition();
|
||||
break;
|
||||
case Input::Action::UP:
|
||||
enter_name_->incIndex();
|
||||
break;
|
||||
case Input::Action::DOWN:
|
||||
case Input::Action::LEFT:
|
||||
enter_name_->decIndex();
|
||||
break;
|
||||
case Input::Action::START:
|
||||
@@ -540,8 +540,9 @@ void Player::updateScoreboard() {
|
||||
}
|
||||
case State::ENTERING_NAME:
|
||||
case State::ENTERING_NAME_GAME_COMPLETED: {
|
||||
Scoreboard::get()->setRecordName(scoreboard_panel_, enter_name_->getCurrentName());
|
||||
Scoreboard::get()->setSelectorPos(scoreboard_panel_, getRecordNamePos());
|
||||
Scoreboard::get()->setEnterName(scoreboard_panel_, enter_name_->getCurrentName());
|
||||
Scoreboard::get()->setCharacterSelected(scoreboard_panel_, enter_name_->getSelectedCharacter());
|
||||
Scoreboard::get()->setCarouselAnimation(scoreboard_panel_, enter_name_->getSelectedIndex(), enter_name_.get());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -610,13 +611,13 @@ void Player::setPlayingState(State state) {
|
||||
break;
|
||||
}
|
||||
case State::ENTERING_NAME: {
|
||||
setScoreboardMode(Scoreboard::Mode::ENTER_NAME);
|
||||
setScoreboardMode(Scoreboard::Mode::SCORE_TO_ENTER_NAME); // Iniciar animación de transición
|
||||
break;
|
||||
}
|
||||
case State::SHOWING_NAME: {
|
||||
showing_name_time_accumulator_ = 0.0f; // Inicializar acumulador time-based
|
||||
setScoreboardMode(Scoreboard::Mode::SHOW_NAME);
|
||||
Scoreboard::get()->setRecordName(scoreboard_panel_, last_enter_name_);
|
||||
setScoreboardMode(Scoreboard::Mode::ENTER_TO_SHOW_NAME); // Iniciar animación de transición
|
||||
Scoreboard::get()->setEnterName(scoreboard_panel_, last_enter_name_);
|
||||
addScoreToScoreBoard();
|
||||
break;
|
||||
}
|
||||
@@ -665,7 +666,7 @@ void Player::setPlayingState(State state) {
|
||||
case State::ENTERING_NAME_GAME_COMPLETED: {
|
||||
// setWalkingState(State::WALKING_STOP);
|
||||
// setFiringState(State::FIRING_NONE);
|
||||
setScoreboardMode(Scoreboard::Mode::ENTER_NAME);
|
||||
setScoreboardMode(Scoreboard::Mode::SCORE_TO_ENTER_NAME); // Iniciar animación de transición
|
||||
break;
|
||||
}
|
||||
case State::LEAVING_SCREEN: {
|
||||
@@ -901,15 +902,6 @@ void Player::decNameEntryCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
auto Player::getRecordNamePos() const -> int {
|
||||
if (enter_name_) {
|
||||
return enter_name_->getPosition();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Recoloca los sprites
|
||||
void Player::shiftSprite() {
|
||||
player_sprite_->setPosX(pos_x_);
|
||||
|
||||
@@ -204,10 +204,8 @@ class Player {
|
||||
|
||||
// Contadores y timers
|
||||
[[nodiscard]] auto getContinueCounter() const -> int { return continue_counter_; }
|
||||
[[nodiscard]] auto getRecordNamePos() const -> int; // Obtiene la posición que se está editando del nombre del jugador para la tabla de mejores puntuaciones
|
||||
[[nodiscard]] auto getRecordName() const -> std::string { return enter_name_ ? enter_name_->getFinalName() : "xxx"; }
|
||||
[[nodiscard]] auto getLastEnterName() const -> std::string { return last_enter_name_; }
|
||||
[[nodiscard]] auto getEnterNamePositionOverflow() const -> bool { return enter_name_ ? enter_name_->getPositionOverflow() : false; }
|
||||
|
||||
// --- Configuración e interfaz externa ---
|
||||
void setName(const std::string& name) { name_ = name; }
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, Text::CENTER, Text::COLOR
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para easeOutCubic
|
||||
|
||||
// .at(SINGLETON) Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||
Scoreboard *Scoreboard::instance = nullptr;
|
||||
Scoreboard* Scoreboard::instance = nullptr;
|
||||
|
||||
// .at(SINGLETON) Crearemos el objeto score_board con esta función estática
|
||||
void Scoreboard::init() {
|
||||
@@ -31,7 +32,7 @@ void Scoreboard::destroy() {
|
||||
}
|
||||
|
||||
// .at(SINGLETON) Con este método obtenemos el objeto score_board y podemos trabajar con él
|
||||
auto Scoreboard::get() -> Scoreboard * {
|
||||
auto Scoreboard::get() -> Scoreboard* {
|
||||
return Scoreboard::instance;
|
||||
}
|
||||
|
||||
@@ -40,16 +41,18 @@ Scoreboard::Scoreboard()
|
||||
: renderer_(Screen::get()->getRenderer()),
|
||||
game_power_meter_texture_(Resource::get()->getTexture("game_power_meter.png")),
|
||||
power_meter_sprite_(std::make_unique<Sprite>(game_power_meter_texture_)),
|
||||
text_(Resource::get()->getText("8bithud")),
|
||||
enter_name_text_(Resource::get()->getText("smb2")) {
|
||||
text_(Resource::get()->getText("8bithud")) {
|
||||
// Inicializa variables
|
||||
for (size_t i = 0; i < static_cast<size_t>(Id::SIZE); ++i) {
|
||||
name_.at(i).clear();
|
||||
record_name_.at(i).clear();
|
||||
enter_name_.at(i).clear();
|
||||
selector_pos_.at(i) = 0;
|
||||
score_.at(i) = 0;
|
||||
mult_.at(i) = 0;
|
||||
continue_counter_.at(i) = 0;
|
||||
carousel_prev_index_.at(i) = -1; // Inicializar a -1 para detectar primera inicialización
|
||||
enter_name_ref_.at(i) = nullptr;
|
||||
text_slide_offset_.at(i) = 0.0f;
|
||||
}
|
||||
|
||||
panel_.at(static_cast<size_t>(Id::LEFT)).mode = Mode::SCORE;
|
||||
@@ -74,8 +77,9 @@ Scoreboard::Scoreboard()
|
||||
// Rellena la textura de fondo
|
||||
fillBackgroundTexture();
|
||||
|
||||
// Inicializa el vector de colores para el nombre
|
||||
iniNameColors();
|
||||
// Inicializa el ciclo de colores para el nombre
|
||||
name_color_cycle_ = Colors::generateMirroredCycle(color_.INVERSE(), ColorCycleStyle::VIBRANT);
|
||||
animated_color_ = name_color_cycle_.at(0);
|
||||
}
|
||||
|
||||
Scoreboard::~Scoreboard() {
|
||||
@@ -83,13 +87,104 @@ Scoreboard::~Scoreboard() {
|
||||
SDL_DestroyTexture(background_);
|
||||
}
|
||||
|
||||
for (auto *texture : panel_texture_) {
|
||||
for (auto* texture : panel_texture_) {
|
||||
if (texture != nullptr) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configura la animación del carrusel
|
||||
void Scoreboard::setCarouselAnimation(Id id, int selected_index, EnterName* enter_name_ptr) {
|
||||
size_t idx = static_cast<size_t>(id);
|
||||
|
||||
// Guardar referencia a EnterName
|
||||
enter_name_ref_.at(idx) = enter_name_ptr;
|
||||
|
||||
if (!enter_name_ptr || selected_index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Primera inicialización: posicionar directamente sin animar
|
||||
if (carousel_prev_index_.at(idx) == -1) {
|
||||
carousel_position_.at(idx) = static_cast<float>(selected_index);
|
||||
carousel_target_.at(idx) = static_cast<float>(selected_index);
|
||||
carousel_prev_index_.at(idx) = selected_index;
|
||||
} else {
|
||||
// Detectar cambio en el índice del carácter seleccionado
|
||||
int prev_index = carousel_prev_index_.at(idx);
|
||||
|
||||
if (selected_index != prev_index) {
|
||||
// Calcular dirección del movimiento
|
||||
int direction = selected_index - prev_index;
|
||||
|
||||
// Obtener tamaño de la lista para manejar wrap-around
|
||||
const int LIST_SIZE = enter_name_ptr->getCharacterList().size();
|
||||
|
||||
// Manejar wrap-around circular
|
||||
if (direction > LIST_SIZE / 2) {
|
||||
direction = -(LIST_SIZE - direction); // Wrap backward (ej: Z → A)
|
||||
} else if (direction < -LIST_SIZE / 2) {
|
||||
direction = LIST_SIZE + direction; // Wrap forward (ej: A → Z)
|
||||
}
|
||||
|
||||
// Normalizar a -1 o +1
|
||||
direction = (direction > 0) ? 1 : ((direction < 0) ? -1 : 0);
|
||||
|
||||
if (direction != 0) {
|
||||
// Actualizar target con movimiento relativo
|
||||
carousel_target_.at(idx) = carousel_position_.at(idx) + static_cast<float>(direction);
|
||||
|
||||
// Guardar nuevo índice
|
||||
carousel_prev_index_.at(idx) = selected_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el modo del panel y gestiona transiciones
|
||||
void Scoreboard::setMode(Id id, Mode mode) {
|
||||
size_t idx = static_cast<size_t>(id);
|
||||
|
||||
// Cambiar el modo
|
||||
panel_.at(idx).mode = mode;
|
||||
|
||||
// Gestionar inicialización/transiciones según el nuevo modo
|
||||
switch (mode) {
|
||||
case Mode::SCORE_TO_ENTER_NAME:
|
||||
// Iniciar animación de transición SCORE → ENTER_NAME
|
||||
text_slide_offset_.at(idx) = 0.0f;
|
||||
// Resetear carrusel para que se inicialice correctamente en ENTER_NAME
|
||||
if (carousel_prev_index_.at(idx) != -1) {
|
||||
carousel_prev_index_.at(idx) = -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case Mode::ENTER_NAME:
|
||||
// Resetear carrusel al entrar en modo de entrada de nombre
|
||||
// Esto fuerza una reinicialización en la próxima llamada a setCarouselAnimation()
|
||||
if (carousel_prev_index_.at(idx) != -1) {
|
||||
carousel_prev_index_.at(idx) = -1;
|
||||
}
|
||||
text_slide_offset_.at(idx) = 0.0f;
|
||||
break;
|
||||
|
||||
case Mode::ENTER_TO_SHOW_NAME:
|
||||
// Iniciar animación de transición ENTER_NAME → SHOW_NAME
|
||||
text_slide_offset_.at(idx) = 0.0f;
|
||||
break;
|
||||
|
||||
case Mode::SHOW_NAME:
|
||||
// Asegurar que la animación está completa
|
||||
text_slide_offset_.at(idx) = 1.0f;
|
||||
break;
|
||||
|
||||
// Otros modos no requieren inicialización especial
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Transforma un valor numérico en una cadena de 7 cifras
|
||||
auto Scoreboard::updateScoreText(int num) -> std::string {
|
||||
std::ostringstream oss;
|
||||
@@ -107,11 +202,80 @@ void Scoreboard::updateTimeCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el índice del color animado del nombre
|
||||
void Scoreboard::updateNameColorIndex() {
|
||||
constexpr Uint64 COLOR_UPDATE_INTERVAL = 100; // 100ms entre cambios de color
|
||||
|
||||
if (SDL_GetTicks() - name_color_last_update_ >= COLOR_UPDATE_INTERVAL) {
|
||||
++name_color_index_;
|
||||
name_color_last_update_ = SDL_GetTicks();
|
||||
}
|
||||
|
||||
// Precalcular el color actual del ciclo
|
||||
animated_color_ = name_color_cycle_.at(name_color_index_ % name_color_cycle_.size());
|
||||
}
|
||||
|
||||
// Actualiza la animación del carrusel
|
||||
void Scoreboard::updateCarouselAnimation(float deltaTime) {
|
||||
constexpr float CAROUSEL_SPEED = 8.0f; // Posiciones por segundo
|
||||
|
||||
for (size_t i = 0; i < carousel_position_.size(); ++i) {
|
||||
// Solo animar si no hemos llegado al target
|
||||
if (std::abs(carousel_position_.at(i) - carousel_target_.at(i)) > 0.01f) {
|
||||
// Determinar dirección
|
||||
float direction = (carousel_target_.at(i) > carousel_position_.at(i)) ? 1.0f : -1.0f;
|
||||
|
||||
// Calcular movimiento
|
||||
float movement = CAROUSEL_SPEED * deltaTime * direction;
|
||||
|
||||
// Mover, pero no sobrepasar el target
|
||||
float new_position = carousel_position_.at(i) + movement;
|
||||
|
||||
// Clamp para no sobrepasar
|
||||
if (direction > 0) {
|
||||
carousel_position_.at(i) = std::min(new_position, carousel_target_.at(i));
|
||||
} else {
|
||||
carousel_position_.at(i) = std::max(new_position, carousel_target_.at(i));
|
||||
}
|
||||
} else {
|
||||
// Forzar al target exacto cuando estamos muy cerca
|
||||
carousel_position_.at(i) = carousel_target_.at(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las animaciones de deslizamiento de texto
|
||||
void Scoreboard::updateTextSlideAnimation(float deltaTime) {
|
||||
for (size_t i = 0; i < static_cast<size_t>(Id::SIZE); ++i) {
|
||||
Mode current_mode = panel_.at(i).mode;
|
||||
|
||||
if (current_mode == Mode::SCORE_TO_ENTER_NAME) {
|
||||
// Incrementar progreso de animación SCORE → ENTER_NAME (0.0 a 1.0)
|
||||
text_slide_offset_.at(i) += deltaTime / TEXT_SLIDE_DURATION;
|
||||
|
||||
// Terminar animación y cambiar a ENTER_NAME cuando se complete
|
||||
if (text_slide_offset_.at(i) >= 1.0f) {
|
||||
setMode(static_cast<Id>(i), Mode::ENTER_NAME);
|
||||
}
|
||||
} else if (current_mode == Mode::ENTER_TO_SHOW_NAME) {
|
||||
// Incrementar progreso de animación ENTER_NAME → SHOW_NAME (0.0 a 1.0)
|
||||
text_slide_offset_.at(i) += deltaTime / TEXT_SLIDE_DURATION;
|
||||
|
||||
// Terminar animación y cambiar a SHOW_NAME cuando se complete
|
||||
if (text_slide_offset_.at(i) >= 1.0f) {
|
||||
setMode(static_cast<Id>(i), Mode::SHOW_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica del marcador
|
||||
void Scoreboard::update() {
|
||||
fillBackgroundTexture();
|
||||
void Scoreboard::update(float deltaTime) {
|
||||
updateTimeCounter();
|
||||
++loop_counter_;
|
||||
updateNameColorIndex();
|
||||
updateCarouselAnimation(deltaTime);
|
||||
updateTextSlideAnimation(deltaTime);
|
||||
fillBackgroundTexture(); // Renderizar DESPUÉS de actualizar
|
||||
}
|
||||
|
||||
// Pinta el marcador
|
||||
@@ -129,7 +293,7 @@ void Scoreboard::setColor(Color color) {
|
||||
// Aplica los colores
|
||||
power_meter_sprite_->getTexture()->setColor(text_color2_);
|
||||
fillBackgroundTexture();
|
||||
iniNameColors();
|
||||
name_color_cycle_ = Colors::generateMirroredCycle(color_.INVERSE(), ColorCycleStyle::VIBRANT);
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
@@ -145,7 +309,7 @@ void Scoreboard::setPos(SDL_FRect rect) {
|
||||
// Rellena los diferentes paneles del marcador
|
||||
void Scoreboard::fillPanelTextures() {
|
||||
// Guarda a donde apunta actualmente el renderizador
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
auto* temp = SDL_GetRenderTarget(renderer_);
|
||||
|
||||
// Genera el contenido de cada panel_
|
||||
for (size_t i = 0; i < static_cast<int>(Id::SIZE); ++i) {
|
||||
@@ -183,9 +347,15 @@ void Scoreboard::renderPanelContent(size_t panel_index) {
|
||||
case Mode::CONTINUE:
|
||||
renderContinueMode(panel_index);
|
||||
break;
|
||||
case Mode::SCORE_TO_ENTER_NAME:
|
||||
renderScoreToEnterNameMode(panel_index);
|
||||
break;
|
||||
case Mode::ENTER_NAME:
|
||||
renderEnterNameMode(panel_index);
|
||||
break;
|
||||
case Mode::ENTER_TO_SHOW_NAME:
|
||||
renderEnterToShowNameMode(panel_index);
|
||||
break;
|
||||
case Mode::SHOW_NAME:
|
||||
renderShowNameMode(panel_index);
|
||||
break;
|
||||
@@ -266,7 +436,40 @@ void Scoreboard::renderContinueMode(size_t panel_index) {
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, std::to_string(continue_counter_.at(panel_index)), 1, text_color2_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderScoreToEnterNameMode(size_t panel_index) {
|
||||
// Calcular progreso suavizado de la animación (0.0 a 1.0)
|
||||
const float t = static_cast<float>(easeInOutSine(text_slide_offset_.at(panel_index)));
|
||||
|
||||
// Calcular desplazamientos reales entre slots (no son exactamente ROW_SIZE)
|
||||
const float delta_1_to_2 = slot4_2_.y - slot4_1_.y; // Diferencia real entre ROW1 y ROW2
|
||||
const float delta_2_to_3 = slot4_3_.y - slot4_2_.y; // Diferencia real entre ROW2 y ROW3
|
||||
const float delta_3_to_4 = slot4_4_.y - slot4_3_.y; // Diferencia real entre ROW3 y ROW4
|
||||
|
||||
// ========== Texto que SALE hacia arriba ==========
|
||||
// name_ (sale desde ROW1 hacia arriba)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y - t * delta_1_to_2,
|
||||
name_.at(panel_index), 1, text_color1_);
|
||||
|
||||
// ========== Textos que SE MUEVEN hacia arriba ==========
|
||||
// score_ (se mueve de ROW2 a ROW1)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y - t * delta_1_to_2,
|
||||
updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// "ENTER NAME" (se mueve de ROW3 a ROW2)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y - t * delta_2_to_3,
|
||||
Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// enter_name_ (se mueve de ROW4 a ROW3)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y - t * delta_3_to_4,
|
||||
enter_name_.at(panel_index), 1, text_color2_);
|
||||
|
||||
// ========== Elemento que ENTRA desde abajo ==========
|
||||
// CARRUSEL (entra desde debajo de ROW4 hacia ROW4)
|
||||
renderCarousel(panel_index, slot4_4_.x, static_cast<int>(slot4_4_.y + delta_3_to_4 - t * delta_3_to_4));
|
||||
}
|
||||
|
||||
void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
/*
|
||||
// SCORE
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
@@ -275,41 +478,66 @@ void Scoreboard::renderEnterNameMode(size_t panel_index) {
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
renderNameInputField(panel_index);
|
||||
*/
|
||||
|
||||
// SCORE
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// ENTER NAME
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// NAME
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, enter_name_.at(panel_index), 1, text_color2_);
|
||||
|
||||
// CARRUSEL
|
||||
renderCarousel(panel_index, slot4_4_.x, slot4_4_.y);
|
||||
}
|
||||
|
||||
void Scoreboard::renderNameInputField(size_t panel_index) {
|
||||
SDL_FRect rect = {
|
||||
.x = enter_name_pos_.x,
|
||||
.y = enter_name_pos_.y,
|
||||
.w = static_cast<float>(enter_name_text_->getCharacterSize() - 2),
|
||||
.h = static_cast<float>(enter_name_text_->getCharacterSize())};
|
||||
void Scoreboard::renderEnterToShowNameMode(size_t panel_index) {
|
||||
// Calcular progreso suavizado de la animación (0.0 a 1.0)
|
||||
const float t = static_cast<float>(easeInOutSine(text_slide_offset_.at(panel_index)));
|
||||
|
||||
// Recorre todos los slots de letras del nombre
|
||||
for (size_t j = 0; j < NAME_SIZE; ++j) {
|
||||
// Dibuja la linea. Si coincide con el selector solo se dibuja 2 de cada 4 veces
|
||||
if (j != selector_pos_.at(panel_index) || time_counter_ % 4 >= 2) {
|
||||
SDL_SetRenderDrawColor(renderer_, text_color1_.r, text_color1_.g, text_color1_.b, 255);
|
||||
SDL_RenderLine(renderer_, rect.x, rect.y + rect.h, rect.x + rect.w, rect.y + rect.h);
|
||||
}
|
||||
// Calcular desplazamientos reales entre slots (no son exactamente ROW_SIZE)
|
||||
const float delta_1_to_2 = slot4_2_.y - slot4_1_.y; // Diferencia real entre ROW1 y ROW2
|
||||
const float delta_2_to_3 = slot4_3_.y - slot4_2_.y; // Diferencia real entre ROW2 y ROW3
|
||||
const float delta_3_to_4 = slot4_4_.y - slot4_3_.y; // Diferencia real entre ROW3 y ROW4
|
||||
|
||||
// Dibuja la letra
|
||||
if (j < record_name_.at(panel_index).size()) {
|
||||
enter_name_text_->writeColored(rect.x, rect.y, record_name_.at(panel_index).substr(j, 1), text_color2_);
|
||||
}
|
||||
rect.x += enter_name_text_->getCharacterSize();
|
||||
}
|
||||
// ========== Texto que ENTRA desde arriba ==========
|
||||
// name_ (entra desde arriba hacia ROW1)
|
||||
// Debe venir desde donde estaría ROW0, que está a delta_1_to_2 píxeles arriba de ROW1
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + t * delta_1_to_2 - delta_1_to_2,
|
||||
name_.at(panel_index), 1, text_color1_);
|
||||
|
||||
// ========== Textos que SE MUEVEN (renderizar UNA sola vez) ==========
|
||||
// SCORE (se mueve de ROW1 a ROW2)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y + t * delta_1_to_2,
|
||||
updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// "ENTER NAME" (se mueve de ROW2 a ROW3)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y + t * delta_2_to_3,
|
||||
Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// enter_name_ (se mueve de ROW3 a ROW4)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y + t * delta_3_to_4,
|
||||
enter_name_.at(panel_index), 1, text_color2_);
|
||||
|
||||
// ========== Elemento que SALE hacia abajo ==========
|
||||
// CARRUSEL (sale desde ROW4 hacia abajo, fuera de pantalla)
|
||||
renderCarousel(panel_index, slot4_4_.x, static_cast<int>(slot4_4_.y + t * delta_3_to_4));
|
||||
}
|
||||
|
||||
void Scoreboard::renderShowNameMode(size_t panel_index) {
|
||||
// SCORE
|
||||
// NOMBRE DEL JUGADOR
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_1_.x, slot4_1_.y, name_.at(panel_index), 1, text_color1_);
|
||||
|
||||
// SCORE
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_2_.x, slot4_2_.y, updateScoreText(score_.at(panel_index)), 1, text_color2_);
|
||||
|
||||
// NAME
|
||||
// "ENTER NAME"
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_3_.x, slot4_3_.y, Lang::getText("[SCOREBOARD] 11"), 1, text_color1_);
|
||||
|
||||
// NOMBRE INTRODUCIDO
|
||||
enter_name_text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, record_name_.at(panel_index), 1, Colors::getColorLikeKnightRider(name_colors_, loop_counter_ / 5));
|
||||
// NOMBRE INTRODUCIDO (con color animado)
|
||||
text_->writeDX(Text::CENTER | Text::COLOR, slot4_4_.x, slot4_4_.y, enter_name_.at(panel_index), 1, animated_color_);
|
||||
}
|
||||
|
||||
void Scoreboard::renderGameCompletedMode(size_t panel_index) {
|
||||
@@ -329,7 +557,7 @@ void Scoreboard::fillBackgroundTexture() {
|
||||
fillPanelTextures();
|
||||
|
||||
// Cambia el destino del renderizador
|
||||
SDL_Texture *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_Texture* temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, background_);
|
||||
|
||||
// Dibuja el fondo del marcador
|
||||
@@ -379,7 +607,7 @@ void Scoreboard::recalculateAnchors() {
|
||||
slot4_4_ = {.x = COL, .y = ROW4};
|
||||
|
||||
// Primer cuadrado para poner el nombre de record
|
||||
const int ENTER_NAME_LENGTH = enter_name_text_->length(std::string(NAME_SIZE, 'A'));
|
||||
const int ENTER_NAME_LENGTH = text_->length(std::string(EnterName::MAX_NAME_SIZE, 'A'));
|
||||
enter_name_pos_.x = COL - (ENTER_NAME_LENGTH / 2);
|
||||
enter_name_pos_.y = ROW4;
|
||||
|
||||
@@ -405,7 +633,7 @@ void Scoreboard::createBackgroundTexture() {
|
||||
// Crea las texturas de los paneles
|
||||
void Scoreboard::createPanelTextures() {
|
||||
// Elimina las texturas en caso de existir
|
||||
for (auto *texture : panel_texture_) {
|
||||
for (auto* texture : panel_texture_) {
|
||||
if (texture != nullptr) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
@@ -413,8 +641,8 @@ void Scoreboard::createPanelTextures() {
|
||||
panel_texture_.clear();
|
||||
|
||||
// Crea las texturas para cada panel_
|
||||
for (auto &i : panel_) {
|
||||
SDL_Texture *tex = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, i.pos.w, i.pos.h);
|
||||
for (auto& i : panel_) {
|
||||
SDL_Texture* tex = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, i.pos.w, i.pos.h);
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
panel_texture_.push_back(tex);
|
||||
}
|
||||
@@ -428,13 +656,87 @@ void Scoreboard::renderSeparator() {
|
||||
SDL_RenderLine(renderer_, 0, 0, rect_.w, 0);
|
||||
}
|
||||
|
||||
// Inicializa el vector de colores para el nombre
|
||||
void Scoreboard::iniNameColors() {
|
||||
Color color = color_.INVERSE();
|
||||
// Pinta el carrusel de caracteres con efecto de color LERP y animación suave
|
||||
void Scoreboard::renderCarousel(size_t panel_index, int center_x, int y) {
|
||||
// Obtener referencia a EnterName
|
||||
EnterName* enter_name = enter_name_ref_.at(panel_index);
|
||||
if (!enter_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
name_colors_.clear();
|
||||
name_colors_.emplace_back(color.LIGHTEN(50));
|
||||
name_colors_.emplace_back(color.LIGHTEN(25));
|
||||
name_colors_.emplace_back(color);
|
||||
name_colors_.emplace_back(color.DARKEN(25));
|
||||
// Obtener la lista completa de caracteres
|
||||
const std::string& char_list = enter_name->getCharacterList();
|
||||
if (char_list.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Espacio extra entre letras
|
||||
constexpr int EXTRA_SPACING = 2;
|
||||
|
||||
// Carrusel extendido: usar constante de clase
|
||||
constexpr int HALF_VISIBLE = CAROUSEL_VISIBLE_LETTERS / 2; // 4
|
||||
|
||||
// Posición flotante actual del carrusel (índice en character_list_)
|
||||
const float carousel_pos = carousel_position_.at(panel_index);
|
||||
|
||||
// Calcular ancho promedio de una letra (asumimos ancho uniforme)
|
||||
std::string sample_char(1, char_list[0]);
|
||||
const int AVG_CHAR_WIDTH = text_->length(sample_char, 1);
|
||||
const int CHAR_STEP = AVG_CHAR_WIDTH + EXTRA_SPACING;
|
||||
|
||||
// Calcular offset de píxeles basado en la parte fraccionaria de carousel_pos
|
||||
const float fractional_offset = carousel_pos - std::floor(carousel_pos);
|
||||
const int pixel_offset = static_cast<int>(fractional_offset * CHAR_STEP);
|
||||
|
||||
// Índice base en character_list_ (centro del carrusel)
|
||||
const int base_index = static_cast<int>(std::floor(carousel_pos));
|
||||
const int char_list_size = static_cast<int>(char_list.size());
|
||||
|
||||
// Calcular posición X inicial (centrar el conjunto de 9 letras)
|
||||
int start_x = center_x - (HALF_VISIBLE * CHAR_STEP) - (AVG_CHAR_WIDTH / 2) - pixel_offset;
|
||||
|
||||
// Renderizar las 9 letras visibles
|
||||
for (int i = -HALF_VISIBLE; i <= HALF_VISIBLE; ++i) {
|
||||
// Índice real en character_list_ (con wrap-around circular)
|
||||
int char_index = base_index + i;
|
||||
|
||||
// Wrap-around circular
|
||||
char_index = char_index % char_list_size;
|
||||
if (char_index < 0) {
|
||||
char_index += char_list_size;
|
||||
}
|
||||
|
||||
// Obtener el carácter directamente de character_list_
|
||||
std::string single_char(1, char_list[char_index]);
|
||||
|
||||
// Calcular distancia flotante al centro visual basada en posición real del carácter
|
||||
float distance_from_center = std::abs(static_cast<float>(char_index) - carousel_pos);
|
||||
|
||||
// Manejar wrap-around circular: elegir el camino más corto
|
||||
if (distance_from_center > static_cast<float>(char_list_size) / 2.0f) {
|
||||
distance_from_center = static_cast<float>(char_list_size) - distance_from_center;
|
||||
}
|
||||
|
||||
// Calcular color con LERP dinámico continuo
|
||||
Color letter_color;
|
||||
|
||||
if (distance_from_center < 0.5f) {
|
||||
// Letra cerca del centro: LERP hacia animated_color_
|
||||
// distance_from_center va de 0.0 (centro exacto) a 0.5 (borde)
|
||||
float lerp_to_animated = distance_from_center / 0.5f; // 0.0 a 1.0
|
||||
letter_color = animated_color_.LERP(text_color1_, lerp_to_animated);
|
||||
} else {
|
||||
// Letras alejadas: LERP hacia color_ (fade out)
|
||||
float base_lerp = (distance_from_center - 0.5f) / (HALF_VISIBLE - 0.5f);
|
||||
base_lerp = std::min(base_lerp, 1.0f);
|
||||
const float LERP_FACTOR = base_lerp * 0.85f;
|
||||
letter_color = text_color1_.LERP(color_, LERP_FACTOR);
|
||||
}
|
||||
|
||||
// Calcular posición X de esta letra
|
||||
const int letter_x = start_x + (i + HALF_VISIBLE) * CHAR_STEP;
|
||||
|
||||
// Pintar la letra
|
||||
text_->writeDX(Text::COLOR, letter_x, y, single_char, 1, letter_color);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@
|
||||
#include <string> // Para string, basic_string
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Forward declarations
|
||||
class EnterName;
|
||||
|
||||
#include "color.h" // Para Color
|
||||
|
||||
class Sprite;
|
||||
@@ -32,7 +35,9 @@ class Scoreboard {
|
||||
WAITING,
|
||||
GAME_OVER,
|
||||
DEMO,
|
||||
SCORE_TO_ENTER_NAME, // Transición animada: SCORE → ENTER_NAME
|
||||
ENTER_NAME,
|
||||
ENTER_TO_SHOW_NAME, // Transición animada: ENTER_NAME → SHOW_NAME
|
||||
SHOW_NAME,
|
||||
GAME_COMPLETED,
|
||||
NUM_MODES,
|
||||
@@ -45,57 +50,70 @@ class Scoreboard {
|
||||
};
|
||||
|
||||
// --- Métodos de singleton ---
|
||||
static void init(); // Crea el objeto Scoreboard
|
||||
static void destroy(); // Libera el objeto Scoreboard
|
||||
static auto get() -> Scoreboard *; // Obtiene el puntero al objeto Scoreboard
|
||||
static void init(); // Crea el objeto Scoreboard
|
||||
static void destroy(); // Libera el objeto Scoreboard
|
||||
static auto get() -> Scoreboard*; // Obtiene el puntero al objeto Scoreboard
|
||||
|
||||
// --- Métodos principales ---
|
||||
void update(); // Actualiza la lógica del marcador
|
||||
void render(); // Pinta el marcador
|
||||
void update(float deltaTime); // Actualiza la lógica del marcador
|
||||
void render(); // Pinta el marcador
|
||||
|
||||
// --- Setters ---
|
||||
void setColor(Color color); // Establece el color del marcador
|
||||
void setPos(SDL_FRect rect); // Establece la posición y tamaño del marcador
|
||||
void setContinue(Id id, int continue_counter) { continue_counter_.at(static_cast<size_t>(id)) = continue_counter; }
|
||||
void setHiScore(int hi_score) { hi_score_ = hi_score; }
|
||||
void setHiScoreName(const std::string &name) { hi_score_name_ = name; }
|
||||
void setMode(Id id, Mode mode) { panel_.at(static_cast<size_t>(id)).mode = mode; }
|
||||
void setHiScoreName(const std::string& name) { hi_score_name_ = name; }
|
||||
void setMode(Id id, Mode mode); // Establece el modo del panel y gestiona transiciones
|
||||
void setMult(Id id, float mult) { mult_.at(static_cast<size_t>(id)) = mult; }
|
||||
void setName(Id id, const std::string &name) { name_.at(static_cast<size_t>(id)) = name; }
|
||||
void setName(Id id, const std::string& name) { name_.at(static_cast<size_t>(id)) = name; }
|
||||
void setPower(float power) { power_ = power; }
|
||||
void setRecordName(Id id, const std::string &record_name) { record_name_.at(static_cast<size_t>(id)) = record_name; }
|
||||
void setEnterName(Id id, const std::string& enter_name) { enter_name_.at(static_cast<size_t>(id)) = enter_name; }
|
||||
void setCharacterSelected(Id id, const std::string& character_selected) { character_selected_.at(static_cast<size_t>(id)) = character_selected; }
|
||||
void setCarouselAnimation(Id id, int selected_index, EnterName* enter_name_ptr); // Configura la animación del carrusel
|
||||
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 setStage(int stage) { stage_ = stage; }
|
||||
|
||||
private:
|
||||
// --- Objetos y punteros ---
|
||||
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||
SDL_Renderer* renderer_; // El renderizador de la ventana
|
||||
std::shared_ptr<Texture> game_power_meter_texture_; // Textura con el marcador de poder de la fase
|
||||
std::unique_ptr<Sprite> power_meter_sprite_; // Sprite para el medidor de poder de la fase
|
||||
std::shared_ptr<Text> text_; // Fuente para el marcador del juego
|
||||
std::shared_ptr<Text> enter_name_text_; // Fuente para la introducción de nombre del jugador
|
||||
SDL_Texture *background_ = nullptr; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture *> panel_texture_; // Texturas para dibujar cada panel
|
||||
SDL_Texture* background_ = nullptr; // Textura para dibujar el marcador
|
||||
std::vector<SDL_Texture*> panel_texture_; // Texturas para dibujar cada panel
|
||||
|
||||
// --- Variables de estado ---
|
||||
std::array<std::string, static_cast<int>(Id::SIZE)> name_ = {}; // Nombre de cada jugador
|
||||
std::array<std::string, static_cast<int>(Id::SIZE)> record_name_ = {}; // Nombre introducido para la tabla de records
|
||||
std::array<Panel, static_cast<int>(Id::SIZE)> panel_ = {}; // Lista con todos los paneles del marcador
|
||||
std::vector<Color> name_colors_; // Colores para destacar el nombre una vez introducido
|
||||
std::string hi_score_name_; // Nombre del jugador con la máxima puntuación
|
||||
SDL_FRect rect_ = {0, 0, 320, 40}; // Posición y dimensiones del marcador
|
||||
Color color_; // Color del marcador
|
||||
std::array<size_t, static_cast<int>(Id::SIZE)> selector_pos_ = {}; // Posición del selector de letra para introducir el nombre
|
||||
std::array<int, static_cast<int>(Id::SIZE)> score_ = {}; // Puntuación de los jugadores
|
||||
std::array<int, static_cast<int>(Id::SIZE)> continue_counter_ = {}; // Tiempo para continuar de los jugadores
|
||||
std::array<float, static_cast<int>(Id::SIZE)> mult_ = {}; // Multiplicador de los jugadores
|
||||
Uint64 ticks_ = SDL_GetTicks(); // Variable donde almacenar el valor de SDL_GetTicks()
|
||||
int stage_ = 1; // Número de fase actual
|
||||
int hi_score_ = 0; // Máxima puntuación
|
||||
int time_counter_ = 0; // Contador de segundos
|
||||
int loop_counter_ = 0; // Contador de bucle
|
||||
float power_ = 0; // Poder actual de la fase
|
||||
std::array<std::string, static_cast<int>(Id::SIZE)> name_ = {}; // Nombre de cada jugador
|
||||
std::array<std::string, static_cast<int>(Id::SIZE)> enter_name_ = {}; // Nombre introducido para la tabla de records
|
||||
std::array<std::string, static_cast<int>(Id::SIZE)> character_selected_ = {}; // Caracter seleccionado
|
||||
std::array<EnterName*, static_cast<int>(Id::SIZE)> enter_name_ref_ = {}; // Referencias a EnterName para obtener character_list_
|
||||
std::array<float, static_cast<int>(Id::SIZE)> carousel_position_ = {}; // Posición actual del carrusel (índice en character_list_)
|
||||
std::array<float, static_cast<int>(Id::SIZE)> carousel_target_ = {}; // Posición objetivo del carrusel
|
||||
std::array<int, static_cast<int>(Id::SIZE)> carousel_prev_index_ = {}; // Índice previo para detectar cambios
|
||||
std::array<float, static_cast<int>(Id::SIZE)> text_slide_offset_ = {}; // Progreso de animación de deslizamiento (0.0 a 1.0)
|
||||
std::array<Panel, static_cast<int>(Id::SIZE)> panel_ = {}; // Lista con todos los paneles del marcador
|
||||
Colors::Cycle name_color_cycle_; // Ciclo de colores para destacar el nombre una vez introducido
|
||||
Color animated_color_; // Color actual animado (ciclo automático cada 100ms)
|
||||
std::string hi_score_name_; // Nombre del jugador con la máxima puntuación
|
||||
SDL_FRect rect_ = {0, 0, 320, 40}; // Posición y dimensiones del marcador
|
||||
Color color_; // Color del marcador
|
||||
std::array<size_t, static_cast<int>(Id::SIZE)> selector_pos_ = {}; // Posición del selector de letra para introducir el nombre
|
||||
std::array<int, static_cast<int>(Id::SIZE)> score_ = {}; // Puntuación de los jugadores
|
||||
std::array<int, static_cast<int>(Id::SIZE)> continue_counter_ = {}; // Tiempo para continuar de los jugadores
|
||||
std::array<float, static_cast<int>(Id::SIZE)> mult_ = {}; // Multiplicador de los jugadores
|
||||
Uint64 ticks_ = SDL_GetTicks(); // Variable donde almacenar el valor de SDL_GetTicks()
|
||||
int stage_ = 1; // Número de fase actual
|
||||
int hi_score_ = 0; // Máxima puntuación
|
||||
int time_counter_ = 0; // Contador de segundos
|
||||
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
|
||||
float power_ = 0; // Poder actual de la fase
|
||||
|
||||
// --- Constantes ---
|
||||
static constexpr int CAROUSEL_VISIBLE_LETTERS = 9;
|
||||
static constexpr float TEXT_SLIDE_DURATION = 0.3f; // Duración de la animación de deslizamiento en segundos
|
||||
|
||||
// --- Variables de aspecto ---
|
||||
Color text_color1_, text_color2_; // Colores para los marcadores del texto;
|
||||
@@ -112,8 +130,10 @@ class Scoreboard {
|
||||
void fillPanelTextures(); // Rellena los diferentes paneles del marcador
|
||||
void fillBackgroundTexture(); // Rellena la textura de fondo
|
||||
void updateTimeCounter(); // Actualiza el contador
|
||||
void updateNameColorIndex(); // Actualiza el índice del color animado del nombre
|
||||
void updateCarouselAnimation(float deltaTime); // Actualiza la animación del carrusel
|
||||
void updateTextSlideAnimation(float deltaTime); // Actualiza la animación de deslizamiento de texto
|
||||
void renderSeparator(); // Dibuja la línea que separa la zona de juego del marcador
|
||||
void iniNameColors(); // Inicializa el vector de colores para el nombre
|
||||
void renderPanelContent(size_t panel_index);
|
||||
void renderScoreMode(size_t panel_index);
|
||||
void renderDemoMode();
|
||||
@@ -121,15 +141,18 @@ class Scoreboard {
|
||||
void renderGameOverMode();
|
||||
void renderStageInfoMode();
|
||||
void renderContinueMode(size_t panel_index);
|
||||
void renderScoreToEnterNameMode(size_t panel_index); // Renderiza la transición SCORE → ENTER_NAME
|
||||
void renderEnterNameMode(size_t panel_index);
|
||||
void renderNameInputField(size_t panel_index);
|
||||
void renderEnterToShowNameMode(size_t panel_index); // Renderiza la transición ENTER_NAME → SHOW_NAME
|
||||
void renderShowNameMode(size_t panel_index);
|
||||
void renderGameCompletedMode(size_t panel_index);
|
||||
void renderCarousel(size_t panel_index, int center_x, int y); // Pinta el carrusel de caracteres con colores LERP
|
||||
|
||||
// --- Constructores y destructor privados (singleton) ---
|
||||
Scoreboard(); // Constructor privado
|
||||
~Scoreboard(); // Destructor privado
|
||||
|
||||
// --- Instancia singleton ---
|
||||
static Scoreboard *instance; // Instancia única de Scoreboard
|
||||
static Scoreboard* instance; // Instancia única de Scoreboard
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "balloon.h" // Para Balloon
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "bullet.h" // Para Bullet, Bullet::Type, BulletMoveStatus
|
||||
#include "bullet_manager.h" // Para BulletManager
|
||||
#include "color.h" // Para Color, Colors::FLASH
|
||||
#include "difficulty.h" // Para Code
|
||||
#include "fade.h" // Para Fade, FadeType, FadeMode
|
||||
@@ -57,6 +58,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo_enabled)
|
||||
pause_manager_(std::make_unique<PauseManager>([this](bool is_paused) { onPauseStateChanged(is_paused); })),
|
||||
stage_manager_(std::make_unique<StageManager>()),
|
||||
balloon_manager_(std::make_unique<BalloonManager>(stage_manager_.get())),
|
||||
bullet_manager_(std::make_unique<BulletManager>()),
|
||||
background_(std::make_unique<Background>(stage_manager_->getPowerNeededToReachStage(stage_manager_->getTotalStages() - 1))),
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
@@ -112,6 +114,19 @@ Game::Game(Player::Id player_id, int current_stage, bool demo_enabled)
|
||||
pause_manager_->setServiceMenuPause(is_active);
|
||||
}
|
||||
});
|
||||
|
||||
// Configura callbacks del BulletManager
|
||||
bullet_manager_->setTabeCollisionCallback([this](const std::shared_ptr<Bullet>& bullet) {
|
||||
return checkBulletTabeCollision(bullet);
|
||||
});
|
||||
|
||||
bullet_manager_->setBalloonCollisionCallback([this](const std::shared_ptr<Bullet>& bullet) {
|
||||
return checkBulletBalloonCollision(bullet);
|
||||
});
|
||||
|
||||
bullet_manager_->setOutOfBoundsCallback([this](const std::shared_ptr<Bullet>& bullet) {
|
||||
getPlayer(static_cast<Player::Id>(bullet->getOwner()))->decScoreMultiplier();
|
||||
});
|
||||
#ifdef RECORDING
|
||||
setState(State::PLAYING);
|
||||
#endif
|
||||
@@ -329,16 +344,16 @@ void Game::updateStage() {
|
||||
void Game::updateGameStateGameOver(float deltaTime) {
|
||||
fade_out_->update();
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateScoreboard(deltaTime);
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
bullet_manager_->update(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites(deltaTime);
|
||||
updateTimeStopped(deltaTime);
|
||||
checkBulletCollision();
|
||||
bullet_manager_->checkCollisions();
|
||||
cleanVectors();
|
||||
|
||||
if (game_over_timer_ < GAME_OVER_DURATION_S) {
|
||||
@@ -365,11 +380,11 @@ void Game::updateGameStateGameOver(float deltaTime) {
|
||||
// Gestiona eventos para el estado del final del juego
|
||||
void Game::updateGameStateCompleted(float deltaTime) {
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateScoreboard(deltaTime);
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
bullet_manager_->update(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites(deltaTime);
|
||||
@@ -498,22 +513,6 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player>& player) {
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba y procesa la colisión de las balas
|
||||
void Game::checkBulletCollision() {
|
||||
for (auto& bullet : bullets_) {
|
||||
if (!bullet->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkBulletTabeCollision(bullet)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (checkBulletBalloonCollision(bullet)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja la colisión entre bala y Tabe
|
||||
auto Game::checkBulletTabeCollision(const std::shared_ptr<Bullet>& bullet) -> bool {
|
||||
@@ -601,37 +600,6 @@ void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, const std:
|
||||
updateHiScore();
|
||||
}
|
||||
|
||||
// Mueve las balas activas
|
||||
void Game::updateBullets(float deltaTime) {
|
||||
for (auto& bullet : bullets_) {
|
||||
if (bullet->update(deltaTime) == Bullet::MoveStatus::OUT) {
|
||||
getPlayer(static_cast<Player::Id>(bullet->getOwner()))->decScoreMultiplier();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta las balas activas
|
||||
void Game::renderBullets() {
|
||||
for (auto& bullet : bullets_) {
|
||||
bullet->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Crea un objeto bala
|
||||
void Game::createBullet(int x, int y, Bullet::Type type, Bullet::Color color, int owner) {
|
||||
bullets_.emplace_back(std::make_shared<Bullet>(x, y, type, color, owner));
|
||||
}
|
||||
|
||||
// Vacia el vector de balas
|
||||
void Game::freeBullets() {
|
||||
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(float deltaTime) {
|
||||
@@ -671,7 +639,7 @@ auto Game::dropItem() -> ItemType {
|
||||
break;
|
||||
case 2:
|
||||
if (LUCKY_NUMBER < helper_.item_pacmar_odds) {
|
||||
return ItemType::GAVINA;
|
||||
return ItemType::PACMAR;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
@@ -718,6 +686,9 @@ void Game::freeItems() {
|
||||
if (!items_.empty()) {
|
||||
for (int i = items_.size() - 1; i >= 0; --i) {
|
||||
if (!items_[i]->isEnabled()) {
|
||||
if (items_[i]->getType() == ItemType::COFFEE_MACHINE) {
|
||||
coffee_machine_enabled_ = false;
|
||||
}
|
||||
items_.erase(items_.begin() + i);
|
||||
}
|
||||
}
|
||||
@@ -982,7 +953,7 @@ void Game::fillCanvas() {
|
||||
renderSmartSprites(); // El cafe que sale cuando te golpean
|
||||
renderItems();
|
||||
tabe_->render();
|
||||
renderBullets();
|
||||
bullet_manager_->render();
|
||||
renderPlayers();
|
||||
|
||||
renderPathSprites();
|
||||
@@ -1177,7 +1148,7 @@ void Game::handleEvents() {
|
||||
}
|
||||
|
||||
// Actualiza el marcador
|
||||
void Game::updateScoreboard() {
|
||||
void Game::updateScoreboard(float deltaTime) {
|
||||
for (const auto& player : players_) {
|
||||
scoreboard_->setScore(player->getScoreBoardPanel(), player->getScore());
|
||||
scoreboard_->setMult(player->getScoreBoardPanel(), player->getScoreMultiplier());
|
||||
@@ -1189,7 +1160,7 @@ void Game::updateScoreboard() {
|
||||
scoreboard_->setHiScore(hi_score_.score);
|
||||
scoreboard_->setHiScoreName(hi_score_.name);
|
||||
|
||||
scoreboard_->update();
|
||||
scoreboard_->update(deltaTime);
|
||||
}
|
||||
|
||||
// Pone en el marcador el nombre del primer jugador de la tabla
|
||||
@@ -1343,7 +1314,7 @@ void Game::handleFireInput(const std::shared_ptr<Player>& player, Bullet::Type t
|
||||
default:
|
||||
break;
|
||||
}
|
||||
createBullet(bullet.x, bullet.y, type, player->getNextBulletColor(), static_cast<int>(player->getId()));
|
||||
bullet_manager_->createBullet(bullet.x, bullet.y, type, player->getNextBulletColor(), static_cast<int>(player->getId()));
|
||||
playSound(player->getBulletSoundFile());
|
||||
|
||||
// Establece un tiempo de espera para el próximo disparo.
|
||||
@@ -1467,14 +1438,7 @@ void Game::handleNameInput(const std::shared_ptr<Player>& player) {
|
||||
player->passShowingName();
|
||||
return;
|
||||
}
|
||||
if (player->getEnterNamePositionOverflow()) {
|
||||
player->setInput(Input::Action::START);
|
||||
player->setPlayingState(Player::State::SHOWING_NAME);
|
||||
playSound("service_menu_select.wav");
|
||||
updateHiScoreName();
|
||||
return;
|
||||
}
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
player->setInput(Input::Action::FIRE_LEFT);
|
||||
playSound("service_menu_select.wav");
|
||||
return;
|
||||
}
|
||||
@@ -1485,19 +1449,19 @@ void Game::handleNameInput(const std::shared_ptr<Player>& player) {
|
||||
player->passShowingName();
|
||||
return;
|
||||
}
|
||||
player->setInput(Input::Action::LEFT);
|
||||
player->setInput(Input::Action::FIRE_CENTER);
|
||||
playSound("service_menu_back.wav");
|
||||
return;
|
||||
}
|
||||
|
||||
if (input_->checkAction(Input::Action::UP, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::UP);
|
||||
if (input_->checkAction(Input::Action::LEFT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
playSound("service_menu_move.wav");
|
||||
return;
|
||||
}
|
||||
|
||||
if (input_->checkAction(Input::Action::DOWN, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::DOWN);
|
||||
if (input_->checkAction(Input::Action::RIGHT, Input::DO_NOT_ALLOW_REPEAT, player->getUsesKeyboard(), player->getGamepad())) {
|
||||
player->setInput(Input::Action::RIGHT);
|
||||
playSound("service_menu_move.wav");
|
||||
return;
|
||||
}
|
||||
@@ -1782,7 +1746,7 @@ void Game::updateRecording(float deltaTime) {
|
||||
// Actualiza las variables durante dicho estado
|
||||
void Game::updateGameStateFadeIn(float deltaTime) {
|
||||
fade_in_->update();
|
||||
updateScoreboard();
|
||||
updateScoreboard(deltaTime);
|
||||
updateBackground(deltaTime);
|
||||
if (fade_in_->hasEnded()) {
|
||||
setState(State::ENTERING_PLAYER);
|
||||
@@ -1795,7 +1759,7 @@ void Game::updateGameStateFadeIn(float deltaTime) {
|
||||
void Game::updateGameStateEnteringPlayer(float deltaTime) {
|
||||
balloon_manager_->update(deltaTime);
|
||||
updatePlayers(deltaTime);
|
||||
updateScoreboard();
|
||||
updateScoreboard(deltaTime);
|
||||
updateBackground(deltaTime);
|
||||
for (const auto& player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
@@ -1829,18 +1793,18 @@ void Game::updateGameStatePlaying(float deltaTime) {
|
||||
#endif
|
||||
updatePlayers(deltaTime);
|
||||
checkPlayersStatusPlaying();
|
||||
updateScoreboard();
|
||||
updateScoreboard(deltaTime);
|
||||
updateBackground(deltaTime);
|
||||
balloon_manager_->update(deltaTime);
|
||||
tabe_->update(deltaTime);
|
||||
updateBullets(deltaTime);
|
||||
bullet_manager_->update(deltaTime);
|
||||
updateItems(deltaTime);
|
||||
updateStage();
|
||||
updateSmartSprites(deltaTime);
|
||||
updatePathSprites(deltaTime);
|
||||
updateTimeStopped(deltaTime);
|
||||
updateHelper();
|
||||
checkBulletCollision();
|
||||
bullet_manager_->checkCollisions();
|
||||
updateMenace();
|
||||
checkAndUpdateBalloonSpeed();
|
||||
checkState();
|
||||
@@ -1849,7 +1813,7 @@ void Game::updateGameStatePlaying(float deltaTime) {
|
||||
|
||||
// Vacía los vectores de elementos deshabilitados
|
||||
void Game::cleanVectors() {
|
||||
freeBullets();
|
||||
bullet_manager_->freeBullets();
|
||||
balloon_manager_->freeBalloons();
|
||||
freeItems();
|
||||
freeSmartSprites();
|
||||
@@ -2089,6 +2053,7 @@ void Game::handleDebugEvents(const SDL_Event& event) {
|
||||
for (const auto& player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
createItem(ItemType::COFFEE_MACHINE, player->getPosX(), param.game.game_area.rect.y - Item::COFFEE_MACHINE_HEIGHT);
|
||||
coffee_machine_enabled_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "bullet.h" // Para Bullet
|
||||
#include "bullet_manager.h" // Para BulletManager
|
||||
#include "hit.h" // Para Hit
|
||||
#include "item.h" // Para Item, ItemType
|
||||
#include "manage_hiscore_table.h" // Para HiScoreEntry
|
||||
@@ -21,7 +22,7 @@
|
||||
class Background;
|
||||
class Balloon;
|
||||
class BalloonManager;
|
||||
class Bullet;
|
||||
class BulletManager;
|
||||
class Fade;
|
||||
class Input;
|
||||
class PauseManager;
|
||||
@@ -121,7 +122,6 @@ class Game {
|
||||
SDL_Texture* canvas_; // Textura para dibujar la zona de juego
|
||||
|
||||
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
|
||||
std::vector<std::shared_ptr<Bullet>> bullets_; // Vector con las balas
|
||||
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
|
||||
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
|
||||
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los pathsprites
|
||||
@@ -137,6 +137,7 @@ class Game {
|
||||
std::unique_ptr<PauseManager> pause_manager_; // Objeto para gestionar la pausa
|
||||
std::unique_ptr<StageManager> stage_manager_; // Objeto para gestionar las fases
|
||||
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
|
||||
std::unique_ptr<BulletManager> bullet_manager_; // Objeto para gestionar las balas
|
||||
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
|
||||
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
|
||||
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
|
||||
@@ -260,11 +261,7 @@ class Game {
|
||||
void demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index); // Procesa entrada de jugador en demo
|
||||
|
||||
// --- Sistema de balas y proyectiles ---
|
||||
void updateBullets(float deltaTime); // Actualiza posición y estado de todas las balas (time-based)
|
||||
void renderBullets(); // Renderiza todas las balas activas
|
||||
void createBullet(int x, int y, Bullet::Type kind, Bullet::Color color, int owner); // Crea una nueva bala
|
||||
void checkBulletCollision(); // Verifica colisiones de todas las balas
|
||||
void freeBullets(); // Libera memoria del vector de balas
|
||||
void checkBulletCollision(); // Verifica colisiones de todas las balas (delegado a BulletManager)
|
||||
|
||||
// --- Colisiones específicas de balas ---
|
||||
auto checkBulletTabeCollision(const std::shared_ptr<Bullet>& bullet) -> bool; // Detecta colisión bala-Tabe
|
||||
@@ -319,9 +316,9 @@ class Game {
|
||||
void setMenace(); // Calcula y establece amenaza según globos activos
|
||||
|
||||
// --- Puntuación y marcador ---
|
||||
void updateHiScore(); // Actualiza el récord máximo si es necesario
|
||||
void updateScoreboard(); // Actualiza la visualización del marcador
|
||||
void updateHiScoreName(); // Pone en el marcador el nombre del primer jugador de la tabla
|
||||
void updateHiScore(); // Actualiza el récord máximo si es necesario
|
||||
void updateScoreboard(float deltaTime); // Actualiza la visualización del marcador
|
||||
void updateHiScoreName(); // Pone en el marcador el nombre del primer jugador de la tabla
|
||||
void initScoreboard(); // Inicializa el sistema de puntuación
|
||||
|
||||
// --- Modo demostración ---
|
||||
|
||||
@@ -208,7 +208,7 @@ void Intro::switchText(int from_index, int to_index) {
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void Intro::update(float delta_time) {
|
||||
static auto *const SCREEN = Screen::get();
|
||||
static auto* const SCREEN = Screen::get();
|
||||
SCREEN->update(delta_time); // Actualiza el objeto screen
|
||||
Audio::update(); // Actualiza el objeto Audio
|
||||
|
||||
@@ -229,7 +229,7 @@ void Intro::update(float delta_time) {
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Intro::render() {
|
||||
static auto *const SCREEN = Screen::get();
|
||||
static auto* const SCREEN = Screen::get();
|
||||
|
||||
SCREEN->start(); // Prepara para empezar a dibujar en la textura de juego
|
||||
SCREEN->clean(); // Limpia la pantalla
|
||||
@@ -302,7 +302,7 @@ void Intro::initSprites() {
|
||||
card_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Apuntamos el renderizador a la textura
|
||||
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
auto* temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
card_texture->setAsRenderTarget(Screen::get()->getRenderer());
|
||||
|
||||
// Limpia la textura
|
||||
@@ -343,7 +343,7 @@ void Intro::initSprites() {
|
||||
card_sprites_.at(2)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
|
||||
card_sprites_.at(3)->addPath(param.game.height, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
|
||||
card_sprites_.at(4)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
|
||||
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||
card_sprites_.at(5)->addPath(-CARD_HEIGHT, Y_DEST, PathType::VERTICAL, X_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG_S);
|
||||
card_sprites_.at(5)->addPath(X_DEST, -CARD_WIDTH, PathType::HORIZONTAL, Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
|
||||
|
||||
// Constantes
|
||||
@@ -357,7 +357,7 @@ void Intro::initSprites() {
|
||||
shadow_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Apuntamos el renderizador a la textura
|
||||
auto *temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
auto* temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
shadow_texture->setAsRenderTarget(Screen::get()->getRenderer());
|
||||
|
||||
// Limpia la textura
|
||||
@@ -394,7 +394,7 @@ void Intro::initSprites() {
|
||||
shadow_sprites_.at(2)->addPath(-SHADOW_SPRITE_WIDTH, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_FAST, easeOutQuint, 0.0f);
|
||||
shadow_sprites_.at(3)->addPath(-SHADOW_SPRITE_HEIGHT, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_VERY_SLOW, easeInOutExpo, 0.0f);
|
||||
shadow_sprites_.at(4)->addPath(param.game.height, S_Y_DEST, PathType::VERTICAL, S_X_DEST, CARD_ANIM_DURATION_MEDIUM, easeOutElastic, 0.0f);
|
||||
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG);
|
||||
shadow_sprites_.at(5)->addPath(param.game.width, S_X_DEST, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SLOW, easeOutQuad, CARD_ANIM_DELAY_LONG_S);
|
||||
shadow_sprites_.at(5)->addPath(S_X_DEST, param.game.width, PathType::HORIZONTAL, S_Y_DEST, CARD_ANIM_DURATION_SHORT, easeInElastic, 0.0f);
|
||||
}
|
||||
|
||||
@@ -447,25 +447,25 @@ void Intro::initTexts() {
|
||||
texts_.at(8)->setCaption(Lang::getText("[INTRO] 9"));
|
||||
texts_.at(8)->setSpeedS(TEXT_SPEED_ULTRA_FAST);
|
||||
|
||||
for (auto &text : texts_) {
|
||||
for (auto& text : texts_) {
|
||||
text->center(param.game.game_area.center_x);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los sprites
|
||||
void Intro::updateSprites(float delta_time) {
|
||||
for (auto &sprite : card_sprites_) {
|
||||
for (auto& sprite : card_sprites_) {
|
||||
sprite->update(delta_time);
|
||||
}
|
||||
|
||||
for (auto &sprite : shadow_sprites_) {
|
||||
for (auto& sprite : shadow_sprites_) {
|
||||
sprite->update(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los textos
|
||||
void Intro::updateTexts(float delta_time) {
|
||||
for (auto &text : texts_) {
|
||||
for (auto& text : texts_) {
|
||||
text->updateS(delta_time); // Usar updateS para delta_time en segundos
|
||||
}
|
||||
}
|
||||
@@ -478,7 +478,7 @@ void Intro::renderSprites() {
|
||||
|
||||
// Dibuja los textos
|
||||
void Intro::renderTexts() {
|
||||
for (const auto &text : texts_) {
|
||||
for (const auto& text : texts_) {
|
||||
text->render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ class Intro {
|
||||
static constexpr float CARD_ANIM_DURATION_SLOW = 250.0f / 60.0f; // ≈ 4.1667 s
|
||||
static constexpr float CARD_ANIM_DURATION_VERY_SLOW = 300.0f / 60.0f; // ≈ 5.0000 s
|
||||
|
||||
static constexpr float CARD_ANIM_DELAY_LONG = 0.45f; // Retraso largo antes de animación
|
||||
static constexpr float CARD_OFFSET_MARGIN = 10.0f; // Margen fuera de pantalla
|
||||
static constexpr float CARD_ANIM_DELAY_LONG_S = 7.5F; // Retraso largo antes de animación
|
||||
static constexpr float CARD_OFFSET_MARGIN = 10.0F; // Margen fuera de pantalla
|
||||
|
||||
// --- Estados internos ---
|
||||
enum class State {
|
||||
|
||||
@@ -91,10 +91,7 @@ void Title::update(float deltaTime) {
|
||||
updateFade();
|
||||
updateState(deltaTime);
|
||||
updateStartPrompt(deltaTime);
|
||||
|
||||
for (auto& player : players_) {
|
||||
player->update(deltaTime);
|
||||
}
|
||||
updatePlayers(deltaTime);
|
||||
}
|
||||
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
@@ -569,6 +566,13 @@ void Title::initPlayers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los jugadores
|
||||
void Title::updatePlayers(float deltaTime) {
|
||||
for (auto& player : players_) {
|
||||
player->update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza los jugadores
|
||||
void Title::renderPlayers() {
|
||||
for (auto const& player : players_) {
|
||||
|
||||
@@ -125,7 +125,7 @@ class Title {
|
||||
|
||||
// --- Gestión de jugadores ---
|
||||
void initPlayers(); // Inicializa los jugadores
|
||||
void updatePlayers(); // Actualiza los jugadores
|
||||
void updatePlayers(float deltaTime); // Actualiza los jugadores
|
||||
void renderPlayers(); // Renderiza los jugadores
|
||||
auto getPlayer(Player::Id id) -> std::shared_ptr<Player>; // Obtiene un jugador a partir de su "id"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user