From 7ee359b910930b5fc2e7897b8b6fa72cf9fcabeb Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 19 May 2026 11:44:45 +0200 Subject: [PATCH] Fase 1d: rename del codi restant (effects, stage_system, locals) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sweep final del naming a CamelCase/camelBack/lower_case: Fitxers renombrats: - effects/gestor_puntuacio_flotant.{hpp,cpp} -> floating_score_manager.{hpp,cpp} - effects/puntuacio_flotant.hpp -> floating_score.hpp Tipus (CamelCase): - GestorPuntuacioFlotant -> FloatingScoreManager - PuntuacioFlotant -> FloatingScore - ConfigStage -> StageConfig - ConfigSistemaStages -> StageSystemConfig - NauTitol -> TitleShip - EstatNau -> ShipState Metodes publics (camelBack): - obte_renderer -> getRenderer - get_num_actius -> getActiveCount - calcular_direccio_explosio -> computeExplosionDirection - trobar_slot_lliure -> findFreeSlot - explotar -> explode - reiniciar -> reset - es_valida -> isValid - parsejar_fitxer -> parseFile - carregar -> load - crear_explosio -> createExplosion - registrar_puntuacio -> registerScore - construir_marcador -> buildScoreboard - render_centered -> renderCentered Camps struct publics (snake_case): - actiu/actius -> active - rotacio -> rotation, rotacio_visual -> visual_rotation - acceleracio -> acceleration - velocitat -> velocity - escala/escala_inicial/objectiu/actual -> scale/initial_scale/... - posicio/posicio_inicial/objectiu/actual -> position/initial_position/... - fase_oscilacio -> oscillation_phase - temps_estat -> state_time - jugador_id -> player_id - estat -> state - brillantor -> brightness - tipus -> type Camps privats (sufix _): - naus_ -> ships_, orni_ -> enemies_, bales_ -> bullets_ - gestor_puntuacio_ -> floating_score_manager_ - punt_mort_ -> death_position_, punt_spawn_ -> spawn_position_ - itocado_per_jugador_ -> hit_timer_per_player_ - vides_per_jugador_ -> lives_per_player_ - puntuacio_per_jugador_ -> score_per_player_ - estat_game_over_ -> game_over_state_ - continues_usados_ -> continues_used_ Constants: - MARGE_ESQ/DRET/DALT/BAIX -> MARGIN_LEFT/RIGHT/TOP/BOTTOM Variables locals i parametres comuns (snake_case): - nau -> ship, enemic -> enemy, bala -> bullet - forma -> shape, punt(s) -> point(s) - jugador -> player, partida -> match - temps -> time, missatge -> message Diff: 59 fitxers, +1000/-1000 (simetric). Compila i enllaça. Pendents per a futures fases (no bloquejants): - Comentaris de capçalera en catala -> castella - Variables locals/parametres minoritaris en catala - Include guards (queden alguns #ifndef en lloc de #pragma once) Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/audio/audio_cache.cpp | 4 +- source/core/defaults.hpp | 36 +- source/core/graphics/shape.cpp | 16 +- source/core/graphics/shape.hpp | 24 +- source/core/graphics/shape_loader.cpp | 8 +- source/core/graphics/shape_loader.hpp | 2 +- source/core/graphics/starfield.cpp | 52 +- source/core/graphics/starfield.hpp | 12 +- source/core/graphics/vector_text.cpp | 56 +- source/core/graphics/vector_text.hpp | 22 +- source/core/input/input.cpp | 16 +- source/core/input/input.hpp | 10 +- source/core/input/input_types.hpp | 2 +- source/core/input/mouse.cpp | 6 +- source/core/input/mouse.hpp | 2 +- .../core/rendering/coordinate_transform.cpp | 2 +- .../core/rendering/coordinate_transform.hpp | 4 +- source/core/rendering/line_renderer.hpp | 4 +- source/core/rendering/sdl_manager.cpp | 4 +- source/core/rendering/sdl_manager.hpp | 4 +- source/core/rendering/shape_renderer.cpp | 42 +- source/core/rendering/shape_renderer.hpp | 14 +- source/core/resources/resource_loader.cpp | 6 +- source/core/resources/resource_pack.hpp | 2 +- source/core/system/director.cpp | 2 +- source/core/system/game_config.hpp | 16 +- source/core/system/global_events.hpp | 2 +- source/core/system/scene_context.hpp | 6 +- source/core/utils/path_utils.cpp | 2 +- source/game/constants.hpp | 14 +- source/game/effects/debris.hpp | 14 +- source/game/effects/debris_manager.cpp | 126 ++--- source/game/effects/debris_manager.hpp | 34 +- ...ntuacio_flotant.hpp => floating_score.hpp} | 12 +- ...flotant.cpp => floating_score_manager.cpp} | 52 +- ...flotant.hpp => floating_score_manager.hpp} | 28 +- source/game/entities/bullet.cpp | 28 +- source/game/entities/bullet.hpp | 4 +- source/game/entities/enemy.cpp | 40 +- source/game/entities/enemy.hpp | 6 +- source/game/entities/ship.cpp | 40 +- source/game/entities/ship.hpp | 2 +- source/game/options.cpp | 10 +- source/game/options.hpp | 2 +- source/game/scenes/game_scene.cpp | 516 +++++++++--------- source/game/scenes/game_scene.hpp | 34 +- source/game/scenes/logo_scene.cpp | 68 +-- source/game/scenes/logo_scene.hpp | 8 +- source/game/scenes/title_scene.cpp | 134 ++--- source/game/scenes/title_scene.hpp | 16 +- source/game/stage_system/spawn_controller.cpp | 38 +- source/game/stage_system/spawn_controller.hpp | 10 +- source/game/stage_system/stage_config.hpp | 14 +- source/game/stage_system/stage_loader.cpp | 20 +- source/game/stage_system/stage_loader.hpp | 6 +- source/game/stage_system/stage_manager.cpp | 10 +- source/game/stage_system/stage_manager.hpp | 8 +- source/game/title/ship_animator.cpp | 272 ++++----- source/game/title/ship_animator.hpp | 52 +- 59 files changed, 998 insertions(+), 998 deletions(-) rename source/game/effects/{puntuacio_flotant.hpp => floating_score.hpp} (69%) rename source/game/effects/{gestor_puntuacio_flotant.cpp => floating_score_manager.cpp} (55%) rename source/game/effects/{gestor_puntuacio_flotant.hpp => floating_score_manager.hpp} (55%) diff --git a/source/core/audio/audio_cache.cpp b/source/core/audio/audio_cache.cpp index f3b671e..85d4fa4 100644 --- a/source/core/audio/audio_cache.cpp +++ b/source/core/audio/audio_cache.cpp @@ -30,7 +30,7 @@ JA_Sound_t* AudioCache::getSound(const std::string& name) { // Load from resource system std::vector data = Resource::Helper::loadFile(normalized); if (data.empty()) { - std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl; + std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl; return nullptr; } @@ -64,7 +64,7 @@ JA_Music_t* AudioCache::getMusic(const std::string& name) { // Load from resource system std::vector data = Resource::Helper::loadFile(normalized); if (data.empty()) { - std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl; + std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl; return nullptr; } diff --git a/source/core/defaults.hpp b/source/core/defaults.hpp index 6c39e05..c8d091b 100644 --- a/source/core/defaults.hpp +++ b/source/core/defaults.hpp @@ -107,7 +107,7 @@ constexpr float ENEMY_RADIUS = 20.0F; constexpr float BULLET_RADIUS = 3.0F; } // namespace Entities -// Ship (nave del jugador) +// Ship (nave del player) namespace Ship { // Invulnerabilidad post-respawn constexpr float INVULNERABILITY_DURATION = 3.0F; // Segundos de invulnerabilidad @@ -151,11 +151,11 @@ constexpr float INIT_HUD_RECT_RATIO_END = 0.85F; constexpr float INIT_HUD_SCORE_RATIO_INIT = 0.60F; constexpr float INIT_HUD_SCORE_RATIO_END = 0.90F; -// SHIP1 (nave jugador 1) +// SHIP1 (nave player 1) constexpr float INIT_HUD_SHIP1_RATIO_INIT = 0.0F; constexpr float INIT_HUD_SHIP1_RATIO_END = 1.0F; -// SHIP2 (nave jugador 2) +// SHIP2 (nave player 2) constexpr float INIT_HUD_SHIP2_RATIO_INIT = 0.20F; constexpr float INIT_HUD_SHIP2_RATIO_END = 1.0F; @@ -220,7 +220,7 @@ constexpr float TEMPS_VIDA = 2.0F; // Duració màxima (segons) - enem constexpr float TEMPS_VIDA_NAU = 3.0F; // Ship debris lifetime (matches DEATH_DURATION) constexpr float SHRINK_RATE = 0.5F; // Reducció de mida (factor/s) -// Herència de velocitat angular (trayectorias curvas) +// Herència de velocity angular (trayectorias curvas) constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat constexpr float FRICCIO_ANGULAR = 0.5F; // Desacceleració angular (rad/s²) @@ -261,10 +261,10 @@ constexpr uint8_t BACKGROUND_MAX_G = 15; constexpr uint8_t BACKGROUND_MAX_B = 0; } // namespace Color -// Brillantor (control de intensitat per cada tipus d'entitat) +// Brillantor (control de intensitat per cada type d'entitat) namespace Brightness { // Brillantor estàtica per entitats de joc (0.0-1.0) -constexpr float NAU = 1.0F; // Màxima visibilitat (jugador) +constexpr float NAU = 1.0F; // Màxima visibilitat (player) constexpr float ENEMIC = 0.7F; // 30% més tènue (destaca menys) constexpr float BALA = 1.0F; // Brillo a tope (màxima visibilitat) @@ -306,7 +306,7 @@ constexpr const char* FRIENDLY_FIRE_HIT = "effects/friendly_fire.wav"; // constexpr const char* INIT_HUD = "effects/init_hud.wav"; // Para la animación del HUD constexpr const char* LASER = "effects/laser_shoot.wav"; // Disparo constexpr const char* LOGO = "effects/logo.wav"; // Logo -constexpr const char* START = "effects/start.wav"; // El jugador pulsa START +constexpr const char* START = "effects/start.wav"; // El player pulsa START constexpr const char* GOOD_JOB_COMMANDER = "voices/good_job_commander.wav"; // Voz: "Good job, commander" } // namespace Sound @@ -327,7 +327,7 @@ constexpr SDL_Keycode SHOOT = SDLK_LSHIFT; } // namespace P2 } // namespace Controls -// Enemy type configuration (tipus d'enemics) +// Enemy type configuration (type d'enemics) namespace Enemies { // Pentagon (esquivador - zigzag evasion) namespace Pentagon { @@ -395,7 +395,7 @@ constexpr float INVULNERABILITY_SCALE_START = 0.0F; // Invisible constexpr float INVULNERABILITY_SCALE_END = 1.0F; // Full size } // namespace Spawn -// Scoring system (puntuació per tipus d'enemic) +// Scoring system (puntuació per type d'enemy) namespace Scoring { constexpr int PENTAGON_SCORE = 100; // Pentàgon (esquivador, 35 px/s) constexpr int QUADRAT_SCORE = 150; // Quadrat (perseguidor, 40 px/s) @@ -426,7 +426,7 @@ constexpr float CLOCK_RADIUS = 150.0F; // Distància des del centre constexpr float CLOCK_8_ANGLE = 150.0F * Math::PI / 180.0F; // 8 o'clock (bottom-left) constexpr float CLOCK_4_ANGLE = 30.0F * Math::PI / 180.0F; // 4 o'clock (bottom-right) -// 5. Radio máximo de la forma de la nave (para calcular offset automáticamente) +// 5. Radio máximo de la shape de la nave (para calcular offset automáticamente) constexpr float SHIP_MAX_RADIUS = 30.0F; // Radi del cercle circumscrit a ship_starfield.shp // 6. Margen de seguridad para offset de entrada @@ -436,7 +436,7 @@ constexpr float ENTRY_OFFSET_MARGIN = 227.5F; // Para offset total de ~340px (a // VALORS DERIVATS (calculats automàticament - NO modificar) // ============================================================ -// Centre de la pantalla (punt de referència) +// Centre de la pantalla (point de referència) constexpr float CENTER_X = Game::WIDTH / 2.0F; // 320.0f constexpr float CENTER_Y = Game::HEIGHT / 2.0F; // 240.0f @@ -458,10 +458,10 @@ inline float P2_TARGET_Y() { // Escales d'animació (relatives a SHIP_BASE_SCALE) constexpr float ENTRY_SCALE_START = 1.5F * SHIP_BASE_SCALE; // Entrada: 50% més gran -constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: escala base +constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: scale base -// Offset d'entrada (ajustat automàticament a l'escala) -// Fórmula: (radi màxim de la nau * escala d'entrada) + marge +// Offset d'entrada (ajustat automàticament a l'scale) +// Fórmula: (radi màxim de la ship * scale d'entrada) + marge constexpr float ENTRY_OFFSET = (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN; // Vec2 de fuga (centre per a l'animació de sortida) @@ -476,7 +476,7 @@ constexpr float VANISHING_POINT_Y = CENTER_Y; // 240.0f constexpr float ENTRY_DURATION = 2.0F; // Entrada (segons) constexpr float EXIT_DURATION = 1.0F; // Sortida (segons) -// Flotació (oscil·lació reduïda i diferenciada per nau) +// Flotació (oscil·lació reduïda i diferenciada per ship) constexpr float FLOAT_AMPLITUDE_X = 4.0F; // Amplitud X (píxels) constexpr float FLOAT_AMPLITUDE_Y = 2.5F; // Amplitud Y (píxels) @@ -489,10 +489,10 @@ constexpr float FLOAT_PHASE_OFFSET = 1.57F; // π/2 (90°) constexpr float P1_ENTRY_DELAY = 0.0F; // P1 entra immediatament constexpr float P2_ENTRY_DELAY = 0.5F; // P2 entra 0.5s després -// Delay global abans d'iniciar l'animació d'entrada al estat MAIN +// Delay global abans d'iniciar l'animació d'entrada al state MAIN constexpr float ENTRANCE_DELAY = 5.0F; // Temps d'espera abans que les naus entrin -// Multiplicadors de freqüència per a cada nau (variació sutil ±12%) +// Multiplicadors de freqüència per a cada ship (variació sutil ±12%) constexpr float P1_FREQUENCY_MULTIPLIER = 0.88F; // 12% més lenta constexpr float P2_FREQUENCY_MULTIPLIER = 1.12F; // 12% més ràpida @@ -508,7 +508,7 @@ constexpr float COPYRIGHT1_POS = 0.90F; // Primera línia copyright constexpr float LOGO_LINE_SPACING = 0.02F; // Entre "ORNI" i "ATTACK!" (10px) constexpr float COPYRIGHT_LINE_SPACING = 0.0F; // Entre línies copyright (5px) -// Factors d'escala +// Factors d'scale constexpr float LOGO_SCALE = 0.6F; // Escala "ORNI ATTACK!" constexpr float PRESS_START_SCALE = 1.0F; // Escala "PRESS START TO PLAY" constexpr float COPYRIGHT_SCALE = 0.5F; // Escala copyright diff --git a/source/core/graphics/shape.cpp b/source/core/graphics/shape.cpp index b7f0af9..c165a34 100644 --- a/source/core/graphics/shape.cpp +++ b/source/core/graphics/shape.cpp @@ -14,10 +14,10 @@ Shape::Shape(const std::string& filepath) : center_({.x = 0.0F, .y = 0.0F}), escala_defecte_(1.0F), nom_("unnamed") { - carregar(filepath); + load(filepath); } -bool Shape::carregar(const std::string& filepath) { +bool Shape::load(const std::string& filepath) { // Llegir fitxer std::ifstream file(filepath); if (!file.is_open()) { @@ -32,10 +32,10 @@ bool Shape::carregar(const std::string& filepath) { file.close(); // Parsejar - return parsejar_fitxer(contingut); + return parseFile(contingut); } -bool Shape::parsejar_fitxer(const std::string& contingut) { +bool Shape::parseFile(const std::string& contingut) { std::istringstream iss(contingut); std::string line; @@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) { try { escala_defecte_ = std::stof(extract_value(line)); } catch (...) { - std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n'; + std::cerr << "[Shape] Warning: scale invàlida, usant 1.0" << '\n'; escala_defecte_ = 1.0F; } } else if (starts_with(line, "center:")) { @@ -65,7 +65,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) { if (points.size() >= 2) { primitives_.push_back({PrimitiveType::POLYLINE, points}); } else { - std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada" + std::cerr << "[Shape] Warning: polyline amb menys de 2 points ignorada" << '\n'; } } else if (starts_with(line, "line:")) { @@ -73,7 +73,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) { if (points.size() == 2) { primitives_.push_back({PrimitiveType::LINE, points}); } else { - std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts" + std::cerr << "[Shape] Warning: line ha de tenir exactament 2 points" << '\n'; } } @@ -147,7 +147,7 @@ std::vector Shape::parse_points(const std::string& str) const { float y = std::stof(pair.substr(comma + 1)); points.push_back({x, y}); } catch (...) { - std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair + std::cerr << "[Shape] Warning: point invàlid ignorat: " << pair << '\n'; } } diff --git a/source/core/graphics/shape.hpp b/source/core/graphics/shape.hpp index f20ffdd..c848b19 100644 --- a/source/core/graphics/shape.hpp +++ b/source/core/graphics/shape.hpp @@ -10,30 +10,30 @@ namespace Graphics { -// Tipus de primitiva dins d'una forma +// Tipus de primitiva dins d'una shape enum class PrimitiveType { - POLYLINE, // Seqüència de punts connectats - LINE // Línia individual (2 punts) + POLYLINE, // Seqüència de points connectats + LINE // Línia individual (2 points) }; // Primitiva individual (polyline o line) struct ShapePrimitive { PrimitiveType type; - std::vector points; // 2+ punts per polyline, exactament 2 per line + std::vector points; // 2+ points per polyline, exactament 2 per line }; -// Classe Shape - representa una forma vectorial carregada des de .shp +// Classe Shape - representa una shape vectorial carregada des de .shp class Shape { public: // Constructors Shape() = default; explicit Shape(const std::string& filepath); - // Carregar forma des de fitxer .shp - bool carregar(const std::string& filepath); + // Carregar shape des de fitxer .shp + bool load(const std::string& filepath); - // Parsejar forma des de buffer de memòria (per al sistema de recursos) - bool parsejar_fitxer(const std::string& contingut); + // Parsejar shape des de buffer de memòria (per al sistema de recursos) + bool parseFile(const std::string& contingut); // Getters [[nodiscard]] const std::vector& get_primitives() const { @@ -41,7 +41,7 @@ class Shape { } [[nodiscard]] const Vec2& getCenter() const { return center_; } [[nodiscard]] float get_escala_defecte() const { return escala_defecte_; } - [[nodiscard]] bool es_valida() const { return !primitives_.empty(); } + [[nodiscard]] bool isValid() const { return !primitives_.empty(); } // Info de depuració [[nodiscard]] std::string get_nom() const { return nom_; } @@ -49,9 +49,9 @@ class Shape { private: std::vector primitives_; - Vec2 center_; // Centre/origen de la forma + Vec2 center_; // Centre/origen de la shape float escala_defecte_; // Escala per defecte (normalment 1.0) - std::string nom_; // Nom de la forma (per depuració) + std::string nom_; // Nom de la shape (per depuració) // Helpers privats per parsejar [[nodiscard]] std::string trim(const std::string& str) const; diff --git a/source/core/graphics/shape_loader.cpp b/source/core/graphics/shape_loader.cpp index 99a7f5d..cd68f6a 100644 --- a/source/core/graphics/shape_loader.cpp +++ b/source/core/graphics/shape_loader.cpp @@ -32,7 +32,7 @@ std::shared_ptr ShapeLoader::load(const std::string& filename) { // Load from resource system std::vector data = Resource::Helper::loadFile(normalized); if (data.empty()) { - std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized + std::cerr << "[ShapeLoader] Error: no s'ha pogut load " << normalized << '\n'; return nullptr; } @@ -40,15 +40,15 @@ std::shared_ptr ShapeLoader::load(const std::string& filename) { // Convert bytes to string and parse std::string file_content(data.begin(), data.end()); auto shape = std::make_shared(); - if (!shape->parsejar_fitxer(file_content)) { + if (!shape->parseFile(file_content)) { std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized << '\n'; return nullptr; } // Verify shape is valid - if (!shape->es_valida()) { - std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n'; + if (!shape->isValid()) { + std::cerr << "[ShapeLoader] Error: shape invàlida " << normalized << '\n'; return nullptr; } diff --git a/source/core/graphics/shape_loader.hpp b/source/core/graphics/shape_loader.hpp index d606c0a..5f94d67 100644 --- a/source/core/graphics/shape_loader.hpp +++ b/source/core/graphics/shape_loader.hpp @@ -17,7 +17,7 @@ class ShapeLoader { // No instanciable (tot estàtic) ShapeLoader() = delete; - // Carregar forma des de fitxer (amb caché) + // Carregar shape des de fitxer (amb caché) // Retorna punter compartit (nullptr si error) // Exemple: load("ship.shp") → busca a "data/shapes/ship.shp" static std::shared_ptr load(const std::string& filename); diff --git a/source/core/graphics/starfield.cpp b/source/core/graphics/starfield.cpp index 4f4044a..02fec0e 100644 --- a/source/core/graphics/starfield.cpp +++ b/source/core/graphics/starfield.cpp @@ -22,11 +22,11 @@ Starfield::Starfield(SDL_Renderer* renderer, punt_fuga_(punt_fuga), area_(area), densitat_(densitat) { - // Carregar forma d'estrella amb ShapeLoader + // Carregar shape d'estrella amb ShapeLoader shape_estrella_ = ShapeLoader::load("star.shp"); - if (!shape_estrella_ || !shape_estrella_->es_valida()) { - std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n'; + if (!shape_estrella_ || !shape_estrella_->isValid()) { + std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n'; return; } @@ -60,8 +60,8 @@ Starfield::Starfield(SDL_Renderer* renderer, // Calcular posició des de la distància float radi = estrella.distancia_centre * radi_max_; - estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle)); - estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle)); + estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle)); + estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle)); estrelles_.push_back(estrella); } @@ -70,27 +70,27 @@ Starfield::Starfield(SDL_Renderer* renderer, // Inicialitzar una estrella (nova o regenerada) void Starfield::inicialitzar_estrella(Estrella& estrella) const { - // Angle aleatori des del punt de fuga cap a fora + // Angle aleatori des del point de fuga cap a fora estrella.angle = (static_cast(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI; // Distància inicial petita (5% del radi màxim) - neix prop del centre estrella.distancia_centre = 0.05F; - // Posició inicial: molt prop del punt de fuga + // Posició inicial: molt prop del point de fuga float radi = estrella.distancia_centre * radi_max_; - estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle)); - estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle)); + estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle)); + estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle)); } // Verificar si una estrella està fora de l'àrea bool Starfield::fora_area(const Estrella& estrella) const { - return (estrella.posicio.x < area_.x || - estrella.posicio.x > area_.x + area_.w || - estrella.posicio.y < area_.y || - estrella.posicio.y > area_.y + area_.h); + return (estrella.position.x < area_.x || + estrella.position.x > area_.x + area_.w || + estrella.position.y < area_.y || + estrella.position.y > area_.y + area_.h); } -// Calcular escala dinàmica segons distància del centre +// Calcular scale dinàmica segons distància del centre float Starfield::calcular_escala(const Estrella& estrella) const { const CapaConfig& capa = capes_[estrella.capa]; @@ -119,16 +119,16 @@ void Starfield::update(float delta_time) { const CapaConfig& capa = capes_[estrella.capa]; // Moure cap a fora des del centre - float velocitat = capa.velocitat_base; - float dx = velocitat * std::cos(estrella.angle) * delta_time; - float dy = velocitat * std::sin(estrella.angle) * delta_time; + float velocity = capa.velocitat_base; + float dx = velocity * std::cos(estrella.angle) * delta_time; + float dy = velocity * std::sin(estrella.angle) * delta_time; - estrella.posicio.x += dx; - estrella.posicio.y += dy; + estrella.position.x += dx; + estrella.position.y += dy; // Actualitzar distància del centre - float dx_centre = estrella.posicio.x - punt_fuga_.x; - float dy_centre = estrella.posicio.y - punt_fuga_.y; + float dx_centre = estrella.position.x - punt_fuga_.x; + float dy_centre = estrella.position.y - punt_fuga_.y; float dist_px = std::sqrt((dx_centre * dx_centre) + (dy_centre * dy_centre)); estrella.distancia_centre = dist_px / radi_max_; @@ -146,22 +146,22 @@ void Starfield::set_brightness(float multiplier) { // Dibuixar totes les estrelles void Starfield::draw() { - if (!shape_estrella_->es_valida()) { + if (!shape_estrella_->isValid()) { return; } for (const auto& estrella : estrelles_) { - // Calcular escala i brightness dinàmicament - float escala = calcular_escala(estrella); + // Calcular scale i brightness dinàmicament + float scale = calcular_escala(estrella); float brightness = calcular_brightness(estrella); // Renderitzar estrella sense rotació Rendering::render_shape( renderer_, shape_estrella_, - estrella.posicio, + estrella.position, 0.0F, // angle (les estrelles no giren) - escala, // escala dinàmica + scale, // scale dinàmica 1.0F, // progress (sempre visible) brightness // brightness dinàmica ); diff --git a/source/core/graphics/starfield.hpp b/source/core/graphics/starfield.hpp index 6304154..0c772fe 100644 --- a/source/core/graphics/starfield.hpp +++ b/source/core/graphics/starfield.hpp @@ -26,7 +26,7 @@ class Starfield { public: // Constructor // - renderer: SDL renderer - // - punt_fuga: punt d'origen/fuga des d'on surten les estrelles + // - punt_fuga: point d'origen/fuga des d'on surten les estrelles // - area: rectangle on actuen les estrelles (SDL_FRect) // - densitat: nombre total d'estrelles (es divideix entre capes) Starfield(SDL_Renderer* renderer, @@ -40,14 +40,14 @@ class Starfield { // Dibuixar totes les estrelles void draw(); - // Setters per ajustar paràmetres en temps real - void set_punt_fuga(const Vec2& punt) { punt_fuga_ = punt; } + // Setters per ajustar paràmetres en time real + void set_punt_fuga(const Vec2& point) { punt_fuga_ = point; } void set_brightness(float multiplier); private: // Estructura interna per cada estrella struct Estrella { - Vec2 posicio; // Posició actual + Vec2 position; // Posició actual float angle; // Angle de moviment (radians) float distancia_centre; // Distància normalitzada del centre (0.0-1.0) int capa; // Índex de capa (0=lluny, 1=mitjà, 2=prop) @@ -59,7 +59,7 @@ class Starfield { // Verificar si una estrella està fora de l'àrea [[nodiscard]] bool fora_area(const Estrella& estrella) const; - // Calcular escala dinàmica segons distància del centre + // Calcular scale dinàmica segons distància del centre [[nodiscard]] float calcular_escala(const Estrella& estrella) const; // Calcular brightness dinàmica segons distància del centre @@ -76,7 +76,7 @@ class Starfield { SDL_FRect area_; // Àrea activa float radi_max_; // Distància màxima del centre al límit de pantalla int densitat_; // Nombre total d'estrelles - float multiplicador_brightness_{1.0F}; // Multiplicador de brillantor (1.0 = default) + float multiplicador_brightness_{1.0F}; // Multiplicador de brightness (1.0 = default) }; } // namespace Graphics diff --git a/source/core/graphics/vector_text.cpp b/source/core/graphics/vector_text.cpp index ceae3fe..88e6452 100644 --- a/source/core/graphics/vector_text.cpp +++ b/source/core/graphics/vector_text.cpp @@ -26,10 +26,10 @@ void VectorText::load_charset() { std::string filename = get_shape_filename(c); auto shape = ShapeLoader::load(filename); - if (shape && shape->es_valida()) { + if (shape && shape->isValid()) { chars_[c] = shape; } else { - std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename + std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename << '\n'; } } @@ -39,10 +39,10 @@ void VectorText::load_charset() { std::string filename = get_shape_filename(c); auto shape = ShapeLoader::load(filename); - if (shape && shape->es_valida()) { + if (shape && shape->isValid()) { chars_[c] = shape; } else { - std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename + std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename << '\n'; } } @@ -54,10 +54,10 @@ void VectorText::load_charset() { std::string filename = get_shape_filename(c); auto shape = ShapeLoader::load(filename); - if (shape && shape->es_valida()) { + if (shape && shape->isValid()) { chars_[c] = shape; } else { - std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename + std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename << '\n'; } } @@ -69,10 +69,10 @@ void VectorText::load_charset() { std::string filename = "font/char_copyright.shp"; auto shape = ShapeLoader::load(filename); - if (shape && shape->es_valida()) { + if (shape && shape->isValid()) { chars_[c] = shape; } else { - std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename + std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename << '\n'; } } @@ -168,7 +168,7 @@ std::string VectorText::get_shape_filename(char c) const { case '?': return "font/char_question.shp"; case ' ': - return ""; // Espai es maneja sense carregar shape + return ""; // Espai es maneja sense load shape case '\xA9': // Copyright symbol (©) - UTF-8 U+00A9 return "font/char_copyright.shp"; @@ -182,23 +182,23 @@ bool VectorText::is_supported(char c) const { return chars_.contains(c); } -void VectorText::render(const std::string& text, const Vec2& posicio, float escala, float spacing, float brightness) const { +void VectorText::render(const std::string& text, const Vec2& position, float scale, float spacing, float brightness) const { if (renderer_ == nullptr) { return; } - // Ancho de un carácter base (20 px a escala 1.0) - const float char_width_scaled = char_width * escala; + // Ancho de un carácter base (20 px a scale 1.0) + const float char_width_scaled = char_width * scale; // Spacing escalado - const float spacing_scaled = spacing * escala; + const float spacing_scaled = spacing * scale; // Altura de un carácter escalado (necesario para ajustar Y) - const float char_height_scaled = char_height * escala; + const float char_height_scaled = char_height * scale; // Posición X del borde izquierdo del carácter actual // (se ajustará +char_width/2 para obtener el centro al renderizar) - float current_x = posicio.x; + float current_x = position.x; // Iterar sobre cada byte del string (con detecció UTF-8) for (size_t i = 0; i < text.length(); i++) { @@ -221,10 +221,10 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca auto it = chars_.find(c); if (it != chars_.end()) { // Renderizar carácter - // Ajustar X e Y para que posicio represente esquina superior izquierda + // Ajustar X e Y para que position represente esquina superior izquierda // (render_shape espera el centro, así que sumamos la mitad de ancho y altura) - Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)}; - Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness); + Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)}; + Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness); // Avanzar posición current_x += char_width_scaled + spacing_scaled; @@ -237,28 +237,28 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca } } -void VectorText::render_centered(const std::string& text, const Vec2& centre_punt, float escala, float spacing, float brightness) const { +void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt, float scale, float spacing, float brightness) const { // Calcular dimensions del text - float text_width = get_text_width(text, escala, spacing); - float text_height = get_text_height(escala); + float text_width = get_text_width(text, scale, spacing); + float text_height = get_text_height(scale); // Calcular posició de l'esquina superior esquerra - // restant la meitat de les dimensions del punt central + // restant la meitat de les dimensions del point central Vec2 posicio_esquerra = { .x = centre_punt.x - (text_width / 2.0F), .y = centre_punt.y - (text_height / 2.0F)}; // Delegar al mètode render() existent - render(text, posicio_esquerra, escala, spacing, brightness); + render(text, posicio_esquerra, scale, spacing, brightness); } -float VectorText::get_text_width(const std::string& text, float escala, float spacing) const { +float VectorText::get_text_width(const std::string& text, float scale, float spacing) const { if (text.empty()) { return 0.0F; } - const float char_width_scaled = char_width * escala; - const float spacing_scaled = spacing * escala; + const float char_width_scaled = char_width * scale; + const float spacing_scaled = spacing * scale; // Contar caracteres visuals (no bytes) - manejar UTF-8 size_t visual_chars = 0; @@ -279,8 +279,8 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled); } -float VectorText::get_text_height(float escala) const { - return char_height * escala; +float VectorText::get_text_height(float scale) const { + return char_height * scale; } } // namespace Graphics diff --git a/source/core/graphics/vector_text.hpp b/source/core/graphics/vector_text.hpp index a88d9c0..aeb30f0 100644 --- a/source/core/graphics/vector_text.hpp +++ b/source/core/graphics/vector_text.hpp @@ -21,25 +21,25 @@ class VectorText { // Renderizar string completo // - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':', // '!', '?', ' ') - // - posicio: posición inicial (esquina superior izquierda) - // - escala: factor de escala (1.0 = 20×40 px por carácter) - // - spacing: espacio entre caracteres en píxeles (a escala 1.0) - // - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor) - void render(const std::string& text, const Vec2& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const; + // - position: posición inicial (esquina superior izquierda) + // - scale: factor de scale (1.0 = 20×40 px por carácter) + // - spacing: espacio entre caracteres en píxeles (a scale 1.0) + // - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness) + void render(const std::string& text, const Vec2& position, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const; // Renderizar string centrado en un punto // - text: cadena a renderizar // - centre_punt: punto central del texto (no esquina superior izquierda) - // - escala: factor de escala (1.0 = 20×40 px por carácter) - // - spacing: espacio entre caracteres en píxeles (a escala 1.0) - // - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor) - void render_centered(const std::string& text, const Vec2& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const; + // - scale: factor de scale (1.0 = 20×40 px por carácter) + // - spacing: espacio entre caracteres en píxeles (a scale 1.0) + // - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness) + void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const; // Calcular ancho total de un string (útil para centrado) - [[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const; + [[nodiscard]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const; // Calcular altura del texto (útil para centrado vertical) - [[nodiscard]] float get_text_height(float escala = 1.0F) const; + [[nodiscard]] float get_text_height(float scale = 1.0F) const; // Verificar si un carácter está soportado [[nodiscard]] bool is_supported(char c) const; diff --git a/source/core/input/input.cpp b/source/core/input/input.cpp index f89f3f7..7ed92f1 100644 --- a/source/core/input/input.cpp +++ b/source/core/input/input.cpp @@ -30,7 +30,7 @@ Input::Input(std::string game_controller_db_path) // Inicializar bindings del teclado (valores por defecto) // Estos serán sobrescritos por applyPlayer1BindingsFromOptions() keyboard_.bindings = { - // Movimiento del jugador + // Movimiento del player {Action::LEFT, KeyState{.scancode = SDL_SCANCODE_LEFT}}, {Action::RIGHT, KeyState{.scancode = SDL_SCANCODE_RIGHT}}, {Action::THRUST, KeyState{.scancode = SDL_SCANCODE_UP}}, @@ -188,7 +188,7 @@ auto Input::checkAnyButton(bool repeat) -> bool { return false; } -// Comprueba si algún jugador (P1 o P2) presionó alguna acción de una lista +// Comprueba si algún player (P1 o P2) presionó alguna acción de una lista auto Input::checkAnyPlayerAction(const std::span& actions, bool repeat) -> bool { for (const auto& action : actions) { if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) { @@ -388,14 +388,14 @@ void Input::update() { binding.second.is_held = key_is_down_now; } - // Actualizar bindings de jugador 1 + // Actualizar bindings de player 1 for (auto& binding : player1_keyboard_bindings_) { bool key_is_down_now = key_states[binding.second.scancode]; binding.second.just_pressed = key_is_down_now && !binding.second.is_held; binding.second.is_held = key_is_down_now; } - // Actualizar bindings de jugador 2 + // Actualizar bindings de player 2 for (auto& binding : player2_keyboard_bindings_) { bool key_is_down_now = key_states[binding.second.scancode]; binding.second.just_pressed = key_is_down_now && !binding.second.is_held; @@ -493,7 +493,7 @@ auto Input::findAvailableGamepadByName(const std::string& gamepad_name) -> std:: // ========== MÉTODOS ESPECÍFICOS POR JUGADOR (ORNI) ========== -// Aplica configuración de controles del jugador 1 +// Aplica configuración de controles del player 1 void Input::applyPlayer1BindingsFromOptions() { // 1. Aplicar bindings de teclado (NO usar bindKey, llenar mapa específico) player1_keyboard_bindings_[Action::LEFT].scancode = Options::player1.keyboard.key_left; @@ -527,7 +527,7 @@ void Input::applyPlayer1BindingsFromOptions() { player1_gamepad_ = gamepad; } -// Aplica configuración de controles del jugador 2 +// Aplica configuración de controles del player 2 void Input::applyPlayer2BindingsFromOptions() { // 1. Aplicar bindings de teclado (mapa específico de P2, no sobrescribe P1) player2_keyboard_bindings_[Action::LEFT].scancode = Options::player2.keyboard.key_left; @@ -561,7 +561,7 @@ void Input::applyPlayer2BindingsFromOptions() { player2_gamepad_ = gamepad; } -// Consulta de input para jugador 1 +// Consulta de input para player 1 auto Input::checkActionPlayer1(Action action, bool repeat) -> bool { // Comprobar teclado con el mapa específico de P1 bool keyboard_active = false; @@ -583,7 +583,7 @@ auto Input::checkActionPlayer1(Action action, bool repeat) -> bool { return keyboard_active || gamepad_active; } -// Consulta de input para jugador 2 +// Consulta de input para player 2 auto Input::checkActionPlayer2(Action action, bool repeat) -> bool { // Comprobar teclado con el mapa específico de P2 bool keyboard_active = false; diff --git a/source/core/input/input.hpp b/source/core/input/input.hpp index 9e70746..d6b8384 100644 --- a/source/core/input/input.hpp +++ b/source/core/input/input.hpp @@ -58,7 +58,7 @@ class Input { name(std::string(SDL_GetGamepadName(gamepad))), path(std::string(SDL_GetGamepadPath(pad))), bindings{ - // Movimiento y acciones del jugador + // Movimiento y acciones del player {Action::LEFT, ButtonState{.button = static_cast(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}}, {Action::RIGHT, ButtonState{.button = static_cast(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}}, {Action::THRUST, ButtonState{.button = static_cast(SDL_GAMEPAD_BUTTON_WEST)}}, @@ -92,7 +92,7 @@ class Input { void applyKeyboardBindingsFromOptions(); void applyGamepadBindingsFromOptions(); - // Configuración por jugador (Orni - dos jugadores) + // Configuración por player (Orni - dos jugadores) void applyPlayer1BindingsFromOptions(); void applyPlayer2BindingsFromOptions(); @@ -105,7 +105,7 @@ class Input { auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool; void resetInputStates(); - // Consulta por jugador (Orni - dos jugadores) + // Consulta por player (Orni - dos jugadores) auto checkActionPlayer1(Action action, bool repeat = true) -> bool; auto checkActionPlayer2(Action action, bool repeat = true) -> bool; @@ -152,11 +152,11 @@ class Input { Keyboard keyboard_{}; // Estado del teclado (solo acciones globales) std::string gamepad_mappings_file_; // Ruta al archivo de mappings - // Referencias cacheadas a gamepads por jugador (Orni) + // Referencias cacheadas a gamepads por player (Orni) std::shared_ptr player1_gamepad_; std::shared_ptr player2_gamepad_; - // Mapas de bindings separados por jugador (Orni - dos jugadores) + // Mapas de bindings separados por player (Orni - dos jugadores) std::unordered_map player1_keyboard_bindings_; std::unordered_map player2_keyboard_bindings_; }; \ No newline at end of file diff --git a/source/core/input/input_types.hpp b/source/core/input/input_types.hpp index 603de00..c032638 100644 --- a/source/core/input/input_types.hpp +++ b/source/core/input/input_types.hpp @@ -13,7 +13,7 @@ enum class InputAction : int { // Acciones de entrada posibles en el juego RIGHT, // Rotar derecha THRUST, // Acelerar SHOOT, // Disparar - START, // Empezar partida + START, // Empezar match // Inputs de sistema (globales) WINDOW_INC_ZOOM, // F2 diff --git a/source/core/input/mouse.cpp b/source/core/input/mouse.cpp index d47740c..2338f95 100644 --- a/source/core/input/mouse.cpp +++ b/source/core/input/mouse.cpp @@ -17,13 +17,13 @@ Uint32 initialization_time = 0; constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms void forceHide() { - // Forçar ocultació sincronitzant estat SDL i estat intern - std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible + // Forçar ocultació sincronitzant state SDL i state intern + std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant state. cursor_visible=" << cursor_visible << " -> false" << '\n'; SDL_HideCursor(); cursor_visible = false; last_mouse_move_time = 0; - initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials + initialization_time = SDL_GetTicks(); // Marcar time per ignorar esdeveniments inicials std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << '\n'; } diff --git a/source/core/input/mouse.hpp b/source/core/input/mouse.hpp index d3bad75..7233c47 100644 --- a/source/core/input/mouse.hpp +++ b/source/core/input/mouse.hpp @@ -7,7 +7,7 @@ extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el c extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió extern bool cursor_visible; // Estado del cursor -void forceHide(); // Forçar ocultació del cursor (sincronitza estat intern) +void forceHide(); // Forçar ocultació del cursor (sincronitza state intern) void handleEvent(const SDL_Event& event); void updateCursorVisibility(); diff --git a/source/core/rendering/coordinate_transform.cpp b/source/core/rendering/coordinate_transform.cpp index 4ed2314..b3e04b0 100644 --- a/source/core/rendering/coordinate_transform.cpp +++ b/source/core/rendering/coordinate_transform.cpp @@ -5,7 +5,7 @@ namespace Rendering { -// Factor d'escala global (inicialitzat a 1.0 per defecte) +// Factor d'scale global (inicialitzat a 1.0 per defecte) float g_current_scale_factor = 1.0F; } // namespace Rendering diff --git a/source/core/rendering/coordinate_transform.hpp b/source/core/rendering/coordinate_transform.hpp index 7bd859f..0d06597 100644 --- a/source/core/rendering/coordinate_transform.hpp +++ b/source/core/rendering/coordinate_transform.hpp @@ -7,7 +7,7 @@ namespace Rendering { -// Factor d'escala global (actualitzat cada frame per SDLManager) +// Factor d'scale global (actualitzat cada frame per SDLManager) extern float g_current_scale_factor; // Transforma coordenada lògica a física amb arrodoniment @@ -19,7 +19,7 @@ inline int transform_y(int logical_y, float scale) { return static_cast(std::round(logical_y * scale)); } -// Variant que usa el factor d'escala global +// Variant que usa el factor d'scale global inline int transform_x(int logical_x) { return transform_x(logical_x, g_current_scale_factor); } diff --git a/source/core/rendering/line_renderer.hpp b/source/core/rendering/line_renderer.hpp index 5fba73c..904a1e2 100644 --- a/source/core/rendering/line_renderer.hpp +++ b/source/core/rendering/line_renderer.hpp @@ -7,8 +7,8 @@ namespace Rendering { -// Dibuixa una línia entre dos punts en coordenades lògiques (640x480). -// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor). +// Dibuixa una línia entre dos points en coordenades lògiques (640x480). +// brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness). void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness = 1.0F); // Estableix el color global de les línies (utilitzat per ColorOscillator). diff --git a/source/core/rendering/sdl_manager.cpp b/source/core/rendering/sdl_manager.cpp index 091405d..12614d5 100644 --- a/source/core/rendering/sdl_manager.cpp +++ b/source/core/rendering/sdl_manager.cpp @@ -283,7 +283,7 @@ void SDLManager::updateViewport() { } void SDLManager::updateRenderingContext() const { - // Actualitzar el factor d'escala global per a totes les funcions de renderitzat + // Actualitzar el factor d'scale global per a totes les funcions de renderitzat Rendering::g_current_scale_factor = zoom_factor_; } @@ -430,7 +430,7 @@ void SDLManager::updateColors(float delta_time) { // [NUEVO] Actualitzar comptador de FPS void SDLManager::updateFPS(float delta_time) { - // Acumular temps i frames + // Acumular time i frames fps_accumulator_ += delta_time; fps_frame_count_++; diff --git a/source/core/rendering/sdl_manager.hpp b/source/core/rendering/sdl_manager.hpp index de775fe..fffcd73 100644 --- a/source/core/rendering/sdl_manager.hpp +++ b/source/core/rendering/sdl_manager.hpp @@ -39,13 +39,13 @@ class SDLManager { void updateFPS(float delta_time); // Getters - SDL_Renderer* obte_renderer() { return renderer_; } + SDL_Renderer* getRenderer() { return renderer_; } [[nodiscard]] float getScaleFactor() const { return zoom_factor_; } // [NUEVO] Actualitzar títol de la finestra void setWindowTitle(const std::string& title); - // [NUEVO] Actualitzar context de renderitzat (factor d'escala global) + // [NUEVO] Actualitzar context de renderitzat (factor d'scale global) void updateRenderingContext() const; private: diff --git a/source/core/rendering/shape_renderer.cpp b/source/core/rendering/shape_renderer.cpp index 5873bfb..f83c208 100644 --- a/source/core/rendering/shape_renderer.cpp +++ b/source/core/rendering/shape_renderer.cpp @@ -10,9 +10,9 @@ namespace Rendering { -// Helper: aplicar rotació 3D a un punt 2D (assumeix Z=0) +// Helper: aplicar rotació 3D a un point 2D (assumeix Z=0) static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) { - float z = 0.0F; // Tots els punts 2D comencen a Z=0 + float z = 0.0F; // Tots els points 2D comencen a Z=0 // Pitch (rotació eix X): cabeceo arriba/baix float cos_pitch = std::cos(rot.pitch); @@ -33,7 +33,7 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) { float y3 = (x2 * sin_roll) + (y1 * cos_roll); // Proyecció perspectiva (Z-divide simple) - // Naus volen cap al punt de fuga (320, 240) a "infinit" (Z → +∞) + // Naus volen cap al point de fuga (320, 240) a "infinit" (Z → +∞) // Z més gran = més lluny = més petit a pantalla constexpr float perspective_factor = 500.0F; float scale_factor = perspective_factor / (perspective_factor + z2); @@ -41,9 +41,9 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) { return {.x = x3 * scale_factor, .y = y3 * scale_factor}; } -// Helper: transformar un punt amb rotació, escala i trasllació -static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala, const Rotation3D* rotation_3d) { - // 1. Centrar el punt respecte al centre de la forma +// Helper: transformar un point amb rotació, scale i trasllació +static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale, const Rotation3D* rotation_3d) { + // 1. Centrar el point respecte al centre de la shape float centered_x = point.x - shape_centre.x; float centered_y = point.y - shape_centre.y; @@ -54,9 +54,9 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V centered_y = rotated_3d.y; } - // 3. Aplicar escala al punt (després de rotació 3D) - float scaled_x = centered_x * escala; - float scaled_y = centered_y * escala; + // 3. Aplicar scale al point (després de rotació 3D) + float scaled_x = centered_x * scale; + float scaled_y = centered_y * scale; // 4. Aplicar rotació 2D (Z-axis, tradicional) // IMPORTANT: En el sistema original, angle=0 apunta AMUNT (no dreta) @@ -69,19 +69,19 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a); // 5. Aplicar trasllació a posició mundial - return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y}; + return {.x = rotated_x + position.x, .y = rotated_y + position.y}; } void render_shape(SDL_Renderer* renderer, const std::shared_ptr& shape, - const Vec2& posicio, + const Vec2& position, float angle, - float escala, + float scale, float progress, float brightness, const Rotation3D* rotation_3d) { - // Verificar que la forma és vàlida - if (!shape || !shape->es_valida()) { + // Verificar que la shape és vàlida + if (!shape || !shape->isValid()) { return; } @@ -90,25 +90,25 @@ void render_shape(SDL_Renderer* renderer, return; } - // Obtenir el centre de la forma per a transformacions + // Obtenir el centre de la shape per a transformacions const Vec2& shape_centre = shape->getCenter(); // Iterar sobre totes les primitives for (const auto& primitive : shape->get_primitives()) { if (primitive.type == Graphics::PrimitiveType::POLYLINE) { - // POLYLINE: connectar punts consecutius + // POLYLINE: connectar points consecutius for (size_t i = 0; i < primitive.points.size() - 1; i++) { - Vec2 p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d); - Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d); + Vec2 p1 = transform_point(primitive.points[i], shape_centre, position, angle, scale, rotation_3d); + Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d); linea(renderer, static_cast(p1.x), static_cast(p1.y), static_cast(p2.x), static_cast(p2.y), brightness); } } else { // PrimitiveType::LINE - // LINE: exactament 2 punts + // LINE: exactament 2 points if (primitive.points.size() >= 2) { - Vec2 p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d); - Vec2 p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d); + Vec2 p1 = transform_point(primitive.points[0], shape_centre, position, angle, scale, rotation_3d); + Vec2 p2 = transform_point(primitive.points[1], shape_centre, position, angle, scale, rotation_3d); linea(renderer, static_cast(p1.x), static_cast(p1.y), static_cast(p2.x), static_cast(p2.y), brightness); diff --git a/source/core/rendering/shape_renderer.hpp b/source/core/rendering/shape_renderer.hpp index 64e838b..c15fe91 100644 --- a/source/core/rendering/shape_renderer.hpp +++ b/source/core/rendering/shape_renderer.hpp @@ -32,19 +32,19 @@ struct Rotation3D { } }; -// Renderitzar forma amb transformacions +// Renderitzar shape amb transformacions // - renderer: SDL renderer -// - shape: forma vectorial a draw -// - posicio: posició del centre en coordenades mundials +// - shape: shape vectorial a draw +// - position: posició del centre en coordenades mundials // - angle: rotació en radians (0 = amunt, sentit horari) -// - escala: factor d'escala (1.0 = mida original) +// - scale: factor d'scale (1.0 = mida original) // - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible) -// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor) +// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness) void render_shape(SDL_Renderer* renderer, const std::shared_ptr& shape, - const Vec2& posicio, + const Vec2& position, float angle, - float escala = 1.0F, + float scale = 1.0F, float progress = 1.0F, float brightness = 1.0F, const Rotation3D* rotation_3d = nullptr); diff --git a/source/core/resources/resource_loader.cpp b/source/core/resources/resource_loader.cpp index 4426f55..ffcb8f1 100644 --- a/source/core/resources/resource_loader.cpp +++ b/source/core/resources/resource_loader.cpp @@ -19,12 +19,12 @@ Loader& Loader::get() { bool Loader::initialize(const std::string& pack_file, bool enable_fallback) { fallback_enabled_ = enable_fallback; - // Intentar carregar el paquet + // Intentar load el paquet pack_ = std::make_unique(); if (!pack_->loadPack(pack_file)) { if (!fallback_enabled_) { - std::cerr << "[ResourceLoader] ERROR FATAL: No es pot carregar " << pack_file + std::cerr << "[ResourceLoader] ERROR FATAL: No es pot load " << pack_file << " i el fallback està desactivat\n"; return false; } @@ -40,7 +40,7 @@ bool Loader::initialize(const std::string& pack_file, bool enable_fallback) { // Carregar un recurs std::vector Loader::loadResource(const std::string& filename) { - // Intentar carregar del paquet primer + // Intentar load del paquet primer if (pack_) { if (pack_->hasResource(filename)) { auto data = pack_->getResource(filename); diff --git a/source/core/resources/resource_pack.hpp b/source/core/resources/resource_pack.hpp index 4629305..63869e7 100644 --- a/source/core/resources/resource_pack.hpp +++ b/source/core/resources/resource_pack.hpp @@ -35,7 +35,7 @@ class Pack { bool addFile(const std::string& filepath, const std::string& pack_name); bool addDirectory(const std::string& dir_path, const std::string& base_path = ""); - // Guardar i carregar paquets + // Guardar i load paquets bool savePack(const std::string& pack_file); bool loadPack(const std::string& pack_file); diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index e1603be..b4879ad 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -53,7 +53,7 @@ Director::Director(std::vector const& args) { // Mode release: paquet obligatori, sense fallback std::string pack_path = resource_base + "/resources.pack"; if (!Resource::Helper::initializeResourceSystem(pack_path, false)) { - std::cerr << "ERROR FATAL: No es pot carregar " << pack_path << "\n"; + std::cerr << "ERROR FATAL: No es pot load " << pack_path << "\n"; std::cerr << "El joc no pot continuar sense els recursos.\n"; std::exit(1); } diff --git a/source/core/system/game_config.hpp b/source/core/system/game_config.hpp index e0707f1..59ccf8c 100644 --- a/source/core/system/game_config.hpp +++ b/source/core/system/game_config.hpp @@ -10,36 +10,36 @@ enum class Mode { DEMO // Mode demostració (futur) }; -// Configuració d'una partida +// Configuració d'una match struct MatchConfig { - bool jugador1_actiu{false}; // És actiu el jugador 1? - bool jugador2_actiu{false}; // És actiu el jugador 2? + bool jugador1_actiu{false}; // És active el player 1? + bool jugador2_actiu{false}; // És active el player 2? Mode mode{Mode::NORMAL}; // Mode de joc // Mètodes auxiliars - // Retorna true si només hi ha un jugador actiu + // Retorna true si només hi ha un player active [[nodiscard]] bool es_un_jugador() const { return (jugador1_actiu && !jugador2_actiu) || (!jugador1_actiu && jugador2_actiu); } - // Retorna true si hi ha dos jugadors actius + // Retorna true si hi ha dos jugadors active [[nodiscard]] bool son_dos_jugadors() const { return jugador1_actiu && jugador2_actiu; } - // Retorna true si no hi ha cap jugador actiu + // Retorna true si no hi ha cap player active [[nodiscard]] bool cap_jugador() const { return !jugador1_actiu && !jugador2_actiu; } - // Compte de jugadors actius (0, 1 o 2) + // Compte de jugadors active (0, 1 o 2) [[nodiscard]] uint8_t compte_jugadors() const { return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0); } - // Retorna l'ID de l'únic jugador actiu (0 o 1) + // Retorna l'ID de l'únic player active (0 o 1) // Només vàlid si es_un_jugador() retorna true [[nodiscard]] uint8_t id_unic_jugador() const { if (jugador1_actiu && !jugador2_actiu) { diff --git a/source/core/system/global_events.hpp b/source/core/system/global_events.hpp index b1edd60..c52b014 100644 --- a/source/core/system/global_events.hpp +++ b/source/core/system/global_events.hpp @@ -14,6 +14,6 @@ class SceneContext; namespace GlobalEvents { // Processa events globals (F1/F2/F3/ESC/QUIT) -// Retorna true si l'event ha estat processat i no cal seguir processant-lo +// Retorna true si l'event ha state processat i no cal seguir processant-lo bool handle(const SDL_Event& event, SDLManager& sdl, SceneManager::SceneContext& context); } // namespace GlobalEvents diff --git a/source/core/system/scene_context.hpp b/source/core/system/scene_context.hpp index 83de5fe..3163f65 100644 --- a/source/core/system/scene_context.hpp +++ b/source/core/system/scene_context.hpp @@ -58,12 +58,12 @@ class SceneContext { option_ = Option::NONE; } - // Configurar partida abans de transicionar a GAME + // Configurar match abans de transicionar a GAME void setMatchConfig(const GameConfig::MatchConfig& config) { match_config_ = config; } - // Obtenir configuració de partida (consumit per GameScene) + // Obtenir configuració de match (consumit per GameScene) [[nodiscard]] const GameConfig::MatchConfig& getMatchConfig() const { return match_config_; } @@ -71,7 +71,7 @@ class SceneContext { private: SceneType next_scene_{SceneType::LOGO}; // SceneType a la qual transicionar Option option_{Option::NONE}; // Opció específica per l'escena - GameConfig::MatchConfig match_config_; // Configuració de partida (jugadors actius, mode) + GameConfig::MatchConfig match_config_; // Configuració de match (jugadors active, mode) }; // Variable global inline per gestionar l'escena actual (backward compatibility) diff --git a/source/core/utils/path_utils.cpp b/source/core/utils/path_utils.cpp index e7d9214..b74a7b7 100644 --- a/source/core/utils/path_utils.cpp +++ b/source/core/utils/path_utils.cpp @@ -50,7 +50,7 @@ bool isMacOSBundle() { #ifdef MACOS_BUNDLE return true; #else - // Detecció en temps d'execució + // Detecció en time d'execució // Cercar ".app/Contents/MacOS" a la ruta de l'executable std::string exe_dir = getExecutableDirectory(); return exe_dir.find(".app/Contents/MacOS") != std::string::npos; diff --git a/source/game/constants.hpp b/source/game/constants.hpp index c0d8c65..5fd2b31 100644 --- a/source/game/constants.hpp +++ b/source/game/constants.hpp @@ -3,15 +3,15 @@ #include "core/defaults.hpp" // Aliases per a backward compatibility amb codi existent -// Permet usar Constants::MARGE_ESQ en lloc de Defaults::Game::MARGIN_LEFT +// Permet usar Constants::MARGIN_LEFT en lloc de Defaults::Game::MARGIN_LEFT namespace Constants { // Marges de l'àrea de joc (derivats de Defaults::Zones::GAME) -constexpr int MARGE_ESQ = static_cast(Defaults::Zones::PLAYAREA.x); -constexpr int MARGE_DRET = +constexpr int MARGIN_LEFT = static_cast(Defaults::Zones::PLAYAREA.x); +constexpr int MARGIN_RIGHT = static_cast(Defaults::Zones::PLAYAREA.x + Defaults::Zones::PLAYAREA.w); -constexpr int MARGE_DALT = static_cast(Defaults::Zones::PLAYAREA.y); -constexpr int MARGE_BAIX = +constexpr int MARGIN_TOP = static_cast(Defaults::Zones::PLAYAREA.y); +constexpr int MARGIN_BOTTOM = static_cast(Defaults::Zones::PLAYAREA.y + Defaults::Zones::PLAYAREA.h); // Límits d'objectes @@ -27,8 +27,8 @@ constexpr float PI = Defaults::Math::PI; // Helpers per comprovar límits de zona inline bool dins_zona_joc(float x, float y) { - const SDL_FPoint punt = {x, y}; - return SDL_PointInRectFloat(&punt, &Defaults::Zones::PLAYAREA); + const SDL_FPoint point = {x, y}; + return SDL_PointInRectFloat(&point, &Defaults::Zones::PLAYAREA); } inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float& max_y) { diff --git a/source/game/effects/debris.hpp b/source/game/effects/debris.hpp index f56fff5..fa70fcb 100644 --- a/source/game/effects/debris.hpp +++ b/source/game/effects/debris.hpp @@ -7,15 +7,15 @@ namespace Effects { // Debris: un segment de línia que vola perpendicular a sí mateix -// Representa un fragment d'una forma destruïda (nau, enemic, bala) +// Representa un fragment d'una shape destruïda (ship, enemy, bullet) struct Debris { - // Geometria del segment (2 punts en coordenades mundials) + // Geometria del segment (2 points en coordenades mundials) Vec2 p1; // Vec2 inicial del segment Vec2 p2; // Vec2 final del segment // Física - Vec2 velocitat; // Velocitat en px/s (components x, y) - float acceleracio; // Acceleració negativa (fricció) en px/s² + Vec2 velocity; // Velocitat en px/s (components x, y) + float acceleration; // Acceleració negativa (fricció) en px/s² // Rotació float angle_rotacio; // Angle de rotació acumulat (radians) @@ -25,13 +25,13 @@ struct Debris { // Estat de vida float temps_vida; // Temps transcorregut (segons) float temps_max; // Temps de vida màxim (segons) - bool actiu; // Està actiu? + bool active; // Està active? - // Shrinking (reducció de distància entre punts) + // Shrinking (reducció de distància entre points) float factor_shrink; // Factor de reducció per segon (0.0-1.0) // Rendering - float brightness; // Factor de brillantor (0.0-1.0, heretat de l'objecte original) + float brightness; // Factor de brightness (0.0-1.0, heretat de l'objecte original) }; } // namespace Effects diff --git a/source/game/effects/debris_manager.cpp b/source/game/effects/debris_manager.cpp index da3977f..4906a2e 100644 --- a/source/game/effects/debris_manager.cpp +++ b/source/game/effects/debris_manager.cpp @@ -14,16 +14,16 @@ namespace Effects { -// Helper: transformar punt amb rotació, escala i trasllació +// Helper: transformar point amb rotació, scale i trasllació // (Copiat de shape_renderer.cpp:12-34) -static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala) { - // 1. Centrar el punt respecte al centre de la forma +static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale) { + // 1. Centrar el point respecte al centre de la shape float centered_x = point.x - shape_centre.x; float centered_y = point.y - shape_centre.y; - // 2. Aplicar escala al punt centrat - float scaled_x = centered_x * escala; - float scaled_y = centered_y * escala; + // 2. Aplicar scale al point centrat + float scaled_x = centered_x * scale; + float scaled_y = centered_y * scale; // 3. Aplicar rotació float cos_a = std::cos(angle); @@ -33,38 +33,38 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a); // 4. Aplicar trasllació a posició mundial - return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y}; + return {.x = rotated_x + position.x, .y = rotated_y + position.y}; } DebrisManager::DebrisManager(SDL_Renderer* renderer) : renderer_(renderer) { // Inicialitzar tots els debris com inactius for (auto& debris : debris_pool_) { - debris.actiu = false; + debris.active = false; } } -void DebrisManager::explotar(const std::shared_ptr& shape, +void DebrisManager::explode(const std::shared_ptr& shape, const Vec2& centre, float angle, - float escala, + float scale, float velocitat_base, float brightness, const Vec2& velocitat_objecte, float velocitat_angular, float factor_herencia_visual, const std::string& sound) { - if (!shape || !shape->es_valida()) { + if (!shape || !shape->isValid()) { return; } // Reproducir sonido de explosión Audio::get()->playSound(sound, Audio::Group::GAME); - // Obtenir centre de la forma per a transformacions + // Obtenir centre de la shape per a transformacions const Vec2& shape_centre = shape->getCenter(); - // Iterar sobre totes les primitives de la forma + // Iterar sobre totes les primitives de la shape for (const auto& primitive : shape->get_primitives()) { // Processar cada segment de línia std::vector> segments; @@ -83,14 +83,14 @@ void DebrisManager::explotar(const std::shared_ptr& shape, // Crear debris per a cada segment for (const auto& [local_p1, local_p2] : segments) { - // 1. Transformar punts locals → coordenades mundials + // 1. Transformar points locals → coordenades mundials Vec2 world_p1 = - transform_point(local_p1, shape_centre, centre, angle, escala); + transform_point(local_p1, shape_centre, centre, angle, scale); Vec2 world_p2 = - transform_point(local_p2, shape_centre, centre, angle, escala); + transform_point(local_p2, shape_centre, centre, angle, scale); // 2. Trobar slot lliure - Debris* debris = trobar_slot_lliure(); + Debris* debris = findFreeSlot(); if (debris == nullptr) { std::cerr << "[DebrisManager] Warning: no debris slots disponibles\n"; return; // Pool ple @@ -101,20 +101,20 @@ void DebrisManager::explotar(const std::shared_ptr& shape, debris->p2 = world_p2; // 4. Calcular direcció d'explosió (radial, des del centre cap a fora) - Vec2 direccio = calcular_direccio_explosio(world_p1, world_p2, centre); + Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centre); - // 5. Velocitat inicial (base ± variació aleatòria + velocitat heretada) + // 5. Velocitat inicial (base ± variació aleatòria + velocity heretada) float speed = velocitat_base + (((std::rand() / static_cast(RAND_MAX)) * 2.0F - 1.0F) * Defaults::Physics::Debris::VARIACIO_VELOCITAT); - // Heredar velocitat de l'objecte original (suma vectorial) - debris->velocitat.x = (direccio.x * speed) + velocitat_objecte.x; - debris->velocitat.y = (direccio.y * speed) + velocitat_objecte.y; - debris->acceleracio = Defaults::Physics::Debris::ACCELERACIO; + // Heredar velocity de l'objecte original (suma vectorial) + debris->velocity.x = (direccio.x * speed) + velocitat_objecte.x; + debris->velocity.y = (direccio.y * speed) + velocitat_objecte.y; + debris->acceleration = Defaults::Physics::Debris::ACCELERACIO; - // 6. Herència de velocitat angular amb cap + conversió d'excés + // 6. Herència de velocity angular amb cap + conversió d'excés // 6a. Rotació de TRAYECTORIA amb cap + conversió tangencial if (std::abs(velocitat_angular) > 0.01F) { @@ -137,10 +137,10 @@ void DebrisManager::explotar(const std::shared_ptr& shape, float sign_ang = (velocitat_ang_heretada >= 0.0F) ? 1.0F : -1.0F; if (abs_ang > CAP) { - // Excés: convertir a velocitat tangencial + // Excés: convertir a velocity tangencial float excess = abs_ang - CAP; - // Radi de la forma (enemics = 20 px) + // Radi de la shape (enemics = 20 px) float radius = 20.0F; // Velocitat tangencial = ω_excés × radi @@ -151,11 +151,11 @@ void DebrisManager::explotar(const std::shared_ptr& shape, float tangent_x = -direccio.y; float tangent_y = direccio.x; - // Afegir velocitat tangencial (suma vectorial) - debris->velocitat.x += tangent_x * v_tangential; - debris->velocitat.y += tangent_y * v_tangential; + // Afegir velocity tangencial (suma vectorial) + debris->velocity.x += tangent_x * v_tangential; + debris->velocity.y += tangent_y * v_tangential; - // Aplicar cap a velocitat angular (preservar signe) + // Aplicar cap a velocity angular (preservar signe) debris->velocitat_rot = sign_ang * CAP; } else { // Per sota del cap: comportament normal @@ -199,62 +199,62 @@ void DebrisManager::explotar(const std::shared_ptr& shape, debris->brightness = brightness; // 9. Activar - debris->actiu = true; + debris->active = true; } } } void DebrisManager::update(float delta_time) { for (auto& debris : debris_pool_) { - if (!debris.actiu) { + if (!debris.active) { continue; } - // 1. Actualitzar temps de vida + // 1. Actualitzar time de vida debris.temps_vida += delta_time; - // Desactivar si ha superat temps màxim + // Desactivar si ha superat time màxim if (debris.temps_vida >= debris.temps_max) { - debris.actiu = false; + debris.active = false; continue; } - // 2. Actualitzar velocitat (desacceleració) + // 2. Actualitzar velocity (desacceleració) // Aplicar fricció en la direcció del moviment - float speed = std::sqrt((debris.velocitat.x * debris.velocitat.x) + - (debris.velocitat.y * debris.velocitat.y)); + float speed = std::sqrt((debris.velocity.x * debris.velocity.x) + + (debris.velocity.y * debris.velocity.y)); if (speed > 1.0F) { // Calcular direcció normalitzada - float dir_x = debris.velocitat.x / speed; - float dir_y = debris.velocitat.y / speed; + float dir_x = debris.velocity.x / speed; + float dir_y = debris.velocity.y / speed; // Aplicar acceleració negativa (fricció) - float nova_speed = speed + (debris.acceleracio * delta_time); + float nova_speed = speed + (debris.acceleration * delta_time); nova_speed = std::max(nova_speed, 0.0F); - debris.velocitat.x = dir_x * nova_speed; - debris.velocitat.y = dir_y * nova_speed; + debris.velocity.x = dir_x * nova_speed; + debris.velocity.y = dir_y * nova_speed; } else { // Velocitat molt baixa, aturar - debris.velocitat.x = 0.0F; - debris.velocitat.y = 0.0F; + debris.velocity.x = 0.0F; + debris.velocity.y = 0.0F; } - // 2b. Rotar vector de velocitat (trayectoria curva) + // 2b. Rotar vector de velocity (trayectoria curva) if (std::abs(debris.velocitat_rot) > 0.01F) { // Calcular angle de rotació aquest frame float dangle = debris.velocitat_rot * delta_time; - // Rotar vector de velocitat usant matriu de rotació 2D - float vel_x_old = debris.velocitat.x; - float vel_y_old = debris.velocitat.y; + // Rotar vector de velocity usant matriu de rotació 2D + float vel_x_old = debris.velocity.x; + float vel_y_old = debris.velocity.y; float cos_a = std::cos(dangle); float sin_a = std::sin(dangle); - debris.velocitat.x = (vel_x_old * cos_a) - (vel_y_old * sin_a); - debris.velocitat.y = (vel_x_old * sin_a) + (vel_y_old * cos_a); + debris.velocity.x = (vel_x_old * cos_a) - (vel_y_old * sin_a); + debris.velocity.y = (vel_x_old * sin_a) + (vel_y_old * cos_a); } // 2c. Aplicar fricció angular (desacceleració gradual) @@ -275,18 +275,18 @@ void DebrisManager::update(float delta_time) { .y = (debris.p1.y + debris.p2.y) / 2.0F}; // 4. Actualitzar posició del centre - centre.x += debris.velocitat.x * delta_time; - centre.y += debris.velocitat.y * delta_time; + centre.x += debris.velocity.x * delta_time; + centre.y += debris.velocity.y * delta_time; // 5. Actualitzar rotació VISUAL debris.angle_rotacio += debris.velocitat_rot_visual * delta_time; - // 6. Aplicar shrinking (reducció de distància entre punts) + // 6. Aplicar shrinking (reducció de distància entre points) float shrink_factor = 1.0F - (debris.factor_shrink * debris.temps_vida / debris.temps_max); shrink_factor = std::max(0.0F, shrink_factor); // No negatiu - // Calcular distància original entre punts + // Calcular distància original entre points float dx = debris.p2.x - debris.p1.x; float dy = debris.p2.y - debris.p1.y; @@ -304,7 +304,7 @@ void DebrisManager::update(float delta_time) { void DebrisManager::draw() const { for (const auto& debris : debris_pool_) { - if (!debris.actiu) { + if (!debris.active) { continue; } @@ -318,16 +318,16 @@ void DebrisManager::draw() const { } } -Debris* DebrisManager::trobar_slot_lliure() { +Debris* DebrisManager::findFreeSlot() { for (auto& debris : debris_pool_) { - if (!debris.actiu) { + if (!debris.active) { return &debris; } } return nullptr; // Pool ple } -Vec2 DebrisManager::calcular_direccio_explosio(const Vec2& p1, +Vec2 DebrisManager::computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const { // 1. Calcular centre del segment @@ -364,16 +364,16 @@ Vec2 DebrisManager::calcular_direccio_explosio(const Vec2& p1, return {.x = final_x, .y = final_y}; } -void DebrisManager::reiniciar() { +void DebrisManager::reset() { for (auto& debris : debris_pool_) { - debris.actiu = false; + debris.active = false; } } -int DebrisManager::get_num_actius() const { +int DebrisManager::getActiveCount() const { int count = 0; for (const auto& debris : debris_pool_) { - if (debris.actiu) { + if (debris.active) { count++; } } diff --git a/source/game/effects/debris_manager.hpp b/source/game/effects/debris_manager.hpp index 93fe099..4fde843 100644 --- a/source/game/effects/debris_manager.hpp +++ b/source/game/effects/debris_manager.hpp @@ -20,20 +20,20 @@ class DebrisManager { public: explicit DebrisManager(SDL_Renderer* renderer); - // Crear explosió a partir d'una forma - // - shape: forma vectorial a explotar + // Crear explosió a partir d'una shape + // - shape: shape vectorial a explode // - centre: posició del centre de l'objecte // - angle: orientació de l'objecte (radians) - // - escala: escala de l'objecte (1.0 = normal) - // - velocitat_base: velocitat inicial dels fragments (px/s) - // - brightness: factor de brillantor heretat (0.0-1.0, per defecte 1.0) - // - velocitat_objecte: velocitat de l'objecte que explota (px/s, per defecte 0) - // - velocitat_angular: velocitat angular heretada (rad/s, per defecte 0) + // - scale: scale de l'objecte (1.0 = normal) + // - velocitat_base: velocity inicial dels fragments (px/s) + // - brightness: factor de brightness heretat (0.0-1.0, per defecte 1.0) + // - velocitat_objecte: velocity de l'objecte que explota (px/s, per defecte 0) + // - velocitat_angular: velocity angular heretada (rad/s, per defecte 0) // - factor_herencia_visual: factor de herència rotació visual (0.0-1.0, per defecte 0.0) - void explotar(const std::shared_ptr& shape, + void explode(const std::shared_ptr& shape, const Vec2& centre, float angle, - float escala, + float scale, float velocitat_base, float brightness = 1.0F, const Vec2& velocitat_objecte = {.x = 0.0F, .y = 0.0F}, @@ -41,33 +41,33 @@ class DebrisManager { float factor_herencia_visual = 0.0F, const std::string& sound = Defaults::Sound::EXPLOSION); - // Actualitzar tots els fragments actius + // Actualitzar tots els fragments active void update(float delta_time); - // Dibuixar tots els fragments actius + // Dibuixar tots els fragments active void draw() const; // Reiniciar tots els fragments (neteja) - void reiniciar(); + void reset(); - // Obtenir número de fragments actius - [[nodiscard]] int get_num_actius() const; + // Obtenir número de fragments active + [[nodiscard]] int getActiveCount() const; private: SDL_Renderer* renderer_; // Pool de fragments (màxim concurrent) // Un pentàgon té 5 línies, 15 enemics = 75 línies - // + nau (3 línies) + bales (5 línies * 3) = 93 línies màxim + // + ship (3 línies) + bales (5 línies * 3) = 93 línies màxim // Arrodonit a 100 per seguretat static constexpr int MAX_DEBRIS = 150; std::array debris_pool_; // Trobar primer slot inactiu - Debris* trobar_slot_lliure(); + Debris* findFreeSlot(); // Calcular direcció d'explosió (radial, des del centre cap al segment) - [[nodiscard]] Vec2 calcular_direccio_explosio(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const; + [[nodiscard]] Vec2 computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const; }; } // namespace Effects diff --git a/source/game/effects/puntuacio_flotant.hpp b/source/game/effects/floating_score.hpp similarity index 69% rename from source/game/effects/puntuacio_flotant.hpp rename to source/game/effects/floating_score.hpp index cd9daa0..61f7334 100644 --- a/source/game/effects/puntuacio_flotant.hpp +++ b/source/game/effects/floating_score.hpp @@ -9,17 +9,17 @@ namespace Effects { -// PuntuacioFlotant: text animat que mostra punts guanyats -// S'activa quan es destrueix un enemic i s'esvaeix després d'un temps -struct PuntuacioFlotant { +// FloatingScore: text animat que mostra points guanyats +// S'activa quan es destrueix un enemy i s'esvaeix després d'un time +struct FloatingScore { // Text a mostrar (e.g., "100", "150", "200") std::string text; // Posició actual (coordenades mundials) - Vec2 posicio; + Vec2 position; // Animació de moviment - Vec2 velocitat; // px/s (normalment cap amunt: {0.0f, -30.0f}) + Vec2 velocity; // px/s (normalment cap amunt: {0.0f, -30.0f}) // Animació de fade float temps_vida; // Temps transcorregut (segons) @@ -27,7 +27,7 @@ struct PuntuacioFlotant { float brightness; // Brillantor calculada (0.0-1.0) // Estat - bool actiu; + bool active; }; } // namespace Effects diff --git a/source/game/effects/gestor_puntuacio_flotant.cpp b/source/game/effects/floating_score_manager.cpp similarity index 55% rename from source/game/effects/gestor_puntuacio_flotant.cpp rename to source/game/effects/floating_score_manager.cpp index 2f0156e..d8a500c 100644 --- a/source/game/effects/gestor_puntuacio_flotant.cpp +++ b/source/game/effects/floating_score_manager.cpp @@ -1,95 +1,95 @@ // gestor_puntuacio_flotant.cpp - Implementació del gestor de números flotants // © 2025 Port a C++20 amb SDL3 -#include "gestor_puntuacio_flotant.hpp" +#include "floating_score_manager.hpp" #include namespace Effects { -GestorPuntuacioFlotant::GestorPuntuacioFlotant(SDL_Renderer* renderer) +FloatingScoreManager::FloatingScoreManager(SDL_Renderer* renderer) : text_(renderer) { // Inicialitzar tots els slots com inactius for (auto& pf : pool_) { - pf.actiu = false; + pf.active = false; } } -void GestorPuntuacioFlotant::crear(int punts, const Vec2& posicio) { +void FloatingScoreManager::crear(int points, const Vec2& position) { // 1. Trobar slot lliure - PuntuacioFlotant* pf = trobar_slot_lliure(); + FloatingScore* pf = findFreeSlot(); if (pf == nullptr) { return; // Pool ple (improbable) } // 2. Inicialitzar puntuació flotant - pf->text = std::to_string(punts); - pf->posicio = posicio; - pf->velocitat = {.x = Defaults::FloatingScore::VELOCITY_X, + pf->text = std::to_string(points); + pf->position = position; + pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X, .y = Defaults::FloatingScore::VELOCITY_Y}; pf->temps_vida = 0.0F; pf->temps_max = Defaults::FloatingScore::LIFETIME; pf->brightness = 1.0F; - pf->actiu = true; + pf->active = true; } -void GestorPuntuacioFlotant::update(float delta_time) { +void FloatingScoreManager::update(float delta_time) { for (auto& pf : pool_) { - if (!pf.actiu) { + if (!pf.active) { continue; } // 1. Actualitzar posició (deriva cap amunt) - pf.posicio.x += pf.velocitat.x * delta_time; - pf.posicio.y += pf.velocitat.y * delta_time; + pf.position.x += pf.velocity.x * delta_time; + pf.position.y += pf.velocity.y * delta_time; - // 2. Actualitzar temps de vida + // 2. Actualitzar time de vida pf.temps_vida += delta_time; // 3. Calcular brightness (fade lineal) float progress = pf.temps_vida / pf.temps_max; // 0.0 → 1.0 pf.brightness = 1.0F - progress; // 1.0 → 0.0 - // 4. Desactivar quan acaba el temps + // 4. Desactivar quan acaba el time if (pf.temps_vida >= pf.temps_max) { - pf.actiu = false; + pf.active = false; } } } -void GestorPuntuacioFlotant::draw() { +void FloatingScoreManager::draw() { for (const auto& pf : pool_) { - if (!pf.actiu) { + if (!pf.active) { continue; } // Renderitzar centrat amb brightness (fade) - constexpr float escala = Defaults::FloatingScore::SCALE; + constexpr float scale = Defaults::FloatingScore::SCALE; constexpr float spacing = Defaults::FloatingScore::SPACING; - text_.render_centered(pf.text, pf.posicio, escala, spacing, pf.brightness); + text_.renderCentered(pf.text, pf.position, scale, spacing, pf.brightness); } } -void GestorPuntuacioFlotant::reiniciar() { +void FloatingScoreManager::reset() { for (auto& pf : pool_) { - pf.actiu = false; + pf.active = false; } } -int GestorPuntuacioFlotant::get_num_actius() const { +int FloatingScoreManager::getActiveCount() const { int count = 0; for (const auto& pf : pool_) { - if (pf.actiu) { + if (pf.active) { count++; } } return count; } -PuntuacioFlotant* GestorPuntuacioFlotant::trobar_slot_lliure() { +FloatingScore* FloatingScoreManager::findFreeSlot() { for (auto& pf : pool_) { - if (!pf.actiu) { + if (!pf.active) { return &pf; } } diff --git a/source/game/effects/gestor_puntuacio_flotant.hpp b/source/game/effects/floating_score_manager.hpp similarity index 55% rename from source/game/effects/gestor_puntuacio_flotant.hpp rename to source/game/effects/floating_score_manager.hpp index f276bb4..b5cdfdc 100644 --- a/source/game/effects/gestor_puntuacio_flotant.hpp +++ b/source/game/effects/floating_score_manager.hpp @@ -10,32 +10,32 @@ #include "core/defaults.hpp" #include "core/graphics/vector_text.hpp" #include "core/types.hpp" -#include "puntuacio_flotant.hpp" +#include "floating_score.hpp" namespace Effects { // Gestor de números de puntuació flotants -// Manté un pool de PuntuacioFlotant i gestiona el seu cicle de vida -class GestorPuntuacioFlotant { +// Manté un pool de FloatingScore i gestiona el seu cicle de vida +class FloatingScoreManager { public: - explicit GestorPuntuacioFlotant(SDL_Renderer* renderer); + explicit FloatingScoreManager(SDL_Renderer* renderer); // Crear número flotant - // - punts: valor numèric (100, 150, 200) - // - posicio: on apareix (normalment centre d'enemic destruït) - void crear(int punts, const Vec2& posicio); + // - points: valor numèric (100, 150, 200) + // - position: on apareix (normalment centre d'enemy destruït) + void crear(int points, const Vec2& position); - // Actualitzar tots els números actius + // Actualitzar tots els números active void update(float delta_time); - // Dibuixar tots els números actius + // Dibuixar tots els números active void draw(); // Reiniciar tots (neteja) - void reiniciar(); + void reset(); - // Obtenir número actius (debug) - [[nodiscard]] int get_num_actius() const; + // Obtenir número active (debug) + [[nodiscard]] int getActiveCount() const; private: Graphics::VectorText text_; // Sistema de text vectorial @@ -44,10 +44,10 @@ class GestorPuntuacioFlotant { // Màxim 15 enemics simultanis = màxim 15 números static constexpr int MAX_PUNTUACIONS = Defaults::FloatingScore::MAX_CONCURRENT; - std::array pool_; + std::array pool_; // Trobar primer slot inactiu - PuntuacioFlotant* trobar_slot_lliure(); + FloatingScore* findFreeSlot(); }; } // namespace Effects diff --git a/source/game/entities/bullet.cpp b/source/game/entities/bullet.cpp index c195b93..09b9beb 100644 --- a/source/game/entities/bullet.cpp +++ b/source/game/entities/bullet.cpp @@ -1,4 +1,4 @@ -// bala.cpp - Implementació de projectils de la nau +// bullet.cpp - Implementació de projectils de la ship // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 @@ -26,11 +26,11 @@ Bullet::Bullet(SDL_Renderer* renderer) // [NUEVO] Brightness específic per bales brightness_ = Defaults::Brightness::BALA; - // [NUEVO] Carregar forma compartida des de fitxer + // [NUEVO] Carregar shape compartida des de fitxer shape_ = Graphics::ShapeLoader::load("bullet.shp"); - if (!shape_ || !shape_->es_valida()) { - std::cerr << "[Bullet] Error: no s'ha pogut carregar bullet.shp" << '\n'; + if (!shape_ || !shape_->isValid()) { + std::cerr << "[Bullet] Error: no s'ha pogut load bullet.shp" << '\n'; } } @@ -43,18 +43,18 @@ void Bullet::init() { grace_timer_ = 0.0F; } -void Bullet::disparar(const Vec2& posicio, float angle, uint8_t owner_id) { - // Activar bala i posicionar-la a la nau +void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) { + // Activar bullet i posicionar-la a la ship // Basat en joc_asteroides.cpp línies 188-200 - // Activar bala + // Activar bullet esta_ = true; - // Posició inicial = centre de la nau - center_.x = posicio.x; - center_.y = posicio.y; + // Posició inicial = centre de la ship + center_.x = position.x; + center_.y = position.y; - // Angle = angle de la nau (dispara en la direcció que apunta) + // Angle = angle de la ship (dispara en la direcció que apunta) angle_ = angle; // Almacenar propietario (0=P1, 1=P2) @@ -92,12 +92,12 @@ void Bullet::draw() const { } void Bullet::mou(float delta_time) { - // Moviment rectilini de la bala + // Moviment rectilini de la bullet // Basat en el codi Pascal original: procedure mou_bales // Copiat EXACTAMENT de joc_asteroides.cpp línies 396-419 // Calcular nova posició (moviment polar time-based) - // velocitat ja està en px/s (140 px/s), només cal multiplicar per delta_time + // velocity ja està en px/s (140 px/s), només cal multiplicar per delta_time float velocitat_efectiva = velocity_ * delta_time; // Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt) @@ -109,7 +109,7 @@ void Bullet::mou(float delta_time) { center_.x += dx; // Desactivar si surt de la zona de joc (no rebota com els ORNIs) - // CORRECCIÓ: Usar límits segurs amb radi de la bala + // CORRECCIÓ: Usar límits segurs amb radi de la bullet float min_x; float max_x; float min_y; diff --git a/source/game/entities/bullet.hpp b/source/game/entities/bullet.hpp index 0448a16..a5160de 100644 --- a/source/game/entities/bullet.hpp +++ b/source/game/entities/bullet.hpp @@ -1,4 +1,4 @@ -// bala.hpp - Classe per a projectils de la nau +// bullet.hpp - Classe per a projectils de la ship // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 @@ -18,7 +18,7 @@ class Bullet : public Entities::Entity { Bullet(SDL_Renderer* renderer); void init() override; - void disparar(const Vec2& posicio, float angle, uint8_t owner_id); + void disparar(const Vec2& position, float angle, uint8_t owner_id); void update(float delta_time) override; void draw() const override; diff --git a/source/game/entities/enemy.cpp b/source/game/entities/enemy.cpp index e77eb70..253ffe2 100644 --- a/source/game/entities/enemy.cpp +++ b/source/game/entities/enemy.cpp @@ -1,4 +1,4 @@ -// enemic.cpp - Implementació d'enemics (ORNIs) +// enemy.cpp - Implementació d'enemics (ORNIs) // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 @@ -30,15 +30,15 @@ Enemy::Enemy(SDL_Renderer* renderer) // [NUEVO] Brightness específic per enemics brightness_ = Defaults::Brightness::ENEMIC; - // [NUEVO] Forma es carrega a init() segons el tipus - // Constructor no carrega forma per permetre tipus diferents + // [NUEVO] Forma es carrega a init() segons el type + // Constructor no carrega shape per permetre type diferents } -void Enemy::init(EnemyType tipus, const Vec2* ship_pos) { - // Guardar tipus - type_ = tipus; +void Enemy::init(EnemyType type, const Vec2* ship_pos) { + // Guardar type + type_ = type; - // Carregar forma segons el tipus + // Carregar shape segons el type const char* shape_file; float drotacio_min; float drotacio_max; @@ -68,7 +68,7 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) { default: // Fallback segur: usar valors de PENTAGON - std::cerr << "[Enemy] Error: tipus desconegut (" + std::cerr << "[Enemy] Error: type desconegut (" << static_cast(type_) << "), utilitzant PENTAGON\n"; shape_file = Defaults::Enemies::Pentagon::SHAPE_FILE; velocity_ = Defaults::Enemies::Pentagon::VELOCITAT; @@ -77,10 +77,10 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) { break; } - // Carregar forma + // Carregar shape shape_ = Graphics::ShapeLoader::load(shape_file); - if (!shape_ || !shape_->es_valida()) { - std::cerr << "[Enemy] Error: no s'ha pogut carregar " << shape_file << '\n'; + if (!shape_ || !shape_->isValid()) { + std::cerr << "[Enemy] Error: no s'ha pogut load " << shape_file << '\n'; } // [MODIFIED] Posició aleatòria amb comprovació de seguretat @@ -131,12 +131,12 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) { // Angle aleatori de moviment angle_ = (std::rand() % 360) * Constants::PI / 180.0F; - // Rotació visual aleatòria (rad/s) dins del rang del tipus + // Rotació visual aleatòria (rad/s) dins del rang del type float drotacio_range = drotacio_max - drotacio_min; drotacio_ = drotacio_min + ((static_cast(std::rand()) / RAND_MAX) * drotacio_range); rotacio_ = 0.0F; - // Inicialitzar estat d'animació + // Inicialitzar state d'animació animacio_ = EnemyAnimation(); // Reset to defaults animacio_.drotacio_base = drotacio_; animacio_.drotacio_objetivo = drotacio_; @@ -182,15 +182,15 @@ void Enemy::update(float delta_time) { void Enemy::draw() const { if (esta_ && shape_) { // Calculate animated scale (includes invulnerability LERP) - float escala = calcular_escala_actual(); + float scale = calcular_escala_actual(); // brightness_ is already updated in update() - Rendering::render_shape(renderer_, shape_, center_, rotacio_, escala, 1.0F, brightness_); + Rendering::render_shape(renderer_, shape_, center_, rotacio_, scale, 1.0F, brightness_); } } void Enemy::mou(float delta_time) { - // Dispatcher: crida el comportament específic segons el tipus + // Dispatcher: crida el comportament específic segons el type switch (type_) { case EnemyType::PENTAGON: comportament_pentagon(delta_time); @@ -472,7 +472,7 @@ void Enemy::actualitzar_rotacio_accelerada(float delta_time) { } float Enemy::calcular_escala_actual() const { - float escala = 1.0F; + float scale = 1.0F; // [NEW] Invulnerability LERP prioritza sobre palpitació if (timer_invulnerabilitat_ > 0.0F) { @@ -486,13 +486,13 @@ float Enemy::calcular_escala_actual() const { // LERP scale from 0.0 to 1.0 constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_START; constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_END; - escala = START + ((END - START) * smooth_t); + scale = START + ((END - START) * smooth_t); } else if (animacio_.palpitacio_activa) { // [EXISTING] Palpitació només quan no invulnerable - escala += animacio_.palpitacio_amplitud * std::sin(animacio_.palpitacio_fase); + scale += animacio_.palpitacio_amplitud * std::sin(animacio_.palpitacio_fase); } - return escala; + return scale; } // [NEW] Stage system API implementations diff --git a/source/game/entities/enemy.hpp b/source/game/entities/enemy.hpp index 9669e3d..ef126e7 100644 --- a/source/game/entities/enemy.hpp +++ b/source/game/entities/enemy.hpp @@ -1,4 +1,4 @@ -// enemic.hpp - Classe per a enemics (ORNIs pentàgons) +// enemy.hpp - Classe per a enemics (ORNIs pentàgons) // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 @@ -13,7 +13,7 @@ #include "core/types.hpp" #include "game/constants.hpp" -// Tipus d'enemic +// Tipus d'enemy enum class EnemyType : uint8_t { PENTAGON = 0, // Pentàgon esquivador (zigzag) QUADRAT = 1, // Quadrat perseguidor (tracks ship) @@ -43,7 +43,7 @@ class Enemy : public Entities::Entity { Enemy(SDL_Renderer* renderer); void init() override { init(EnemyType::PENTAGON, nullptr); } - void init(EnemyType tipus, const Vec2* ship_pos = nullptr); + void init(EnemyType type, const Vec2* ship_pos = nullptr); void update(float delta_time) override; void draw() const override; diff --git a/source/game/entities/ship.cpp b/source/game/entities/ship.cpp index 28eb4ca..0a5a650 100644 --- a/source/game/entities/ship.cpp +++ b/source/game/entities/ship.cpp @@ -1,4 +1,4 @@ -// nau.cpp - Implementació de la nave del jugador +// ship.cpp - Implementació de la nave del player // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 @@ -28,21 +28,21 @@ Ship::Ship(SDL_Renderer* renderer, const char* shape_file) // [NUEVO] Brightness específic per naus brightness_ = Defaults::Brightness::NAU; - // [NUEVO] Carregar forma compartida des de fitxer + // [NUEVO] Carregar shape compartida des de fitxer shape_ = Graphics::ShapeLoader::load(shape_file); - if (!shape_ || !shape_->es_valida()) { - std::cerr << "[Ship] Error: no s'ha pogut carregar " << shape_file << '\n'; + if (!shape_ || !shape_->isValid()) { + std::cerr << "[Ship] Error: no s'ha pogut load " << shape_file << '\n'; } } void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) { - // Inicialització de la nau (triangle) + // Inicialització de la ship (triangle) // Basat en el codi Pascal original: lines 380-384 // Copiat de joc_asteroides.cpp línies 30-44 - // [NUEVO] Ja no cal configurar punts polars - la geometria es carrega del - // fitxer Només inicialitzem l'estat de la instància + // [NUEVO] Ja no cal configurar points polars - la geometria es carrega del + // fitxer Només inicialitzem l'state de la instància // Use custom spawn point if provided, otherwise use center if (spawn_point != nullptr) { @@ -74,14 +74,14 @@ void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) { void Ship::processInput(float delta_time, uint8_t player_id) { // Processar input continu (com teclapuls() del Pascal original) // Basat en joc_asteroides.cpp línies 66-85 - // Només processa input si la nau està viva + // Només processa input si la ship està viva if (is_hit_) { return; } auto* input = Input::get(); - // Processar input segons el jugador + // Processar input segons el player if (player_id == 0) { // Jugador 1 if (input->checkActionPlayer1(InputAction::RIGHT, Input::ALLOW_REPEAT)) { @@ -118,7 +118,7 @@ void Ship::processInput(float delta_time, uint8_t player_id) { } void Ship::update(float delta_time) { - // Només update si la nau està viva + // Només update si la ship està viva if (is_hit_) { return; } @@ -134,7 +134,7 @@ void Ship::update(float delta_time) { } void Ship::draw() const { - // Només draw si la nau està viva + // Només draw si la ship està viva if (is_hit_) { return; } @@ -156,25 +156,25 @@ void Ship::draw() const { return; } - // Escalar velocitat per l'efecte visual (200 px/s → ~6 px d'efecte) - // El codi Pascal original sumava velocitat (0-6) al radi per donar - // sensació de "empenta". Ara velocitat està en px/s (0-200). + // Escalar velocity per l'efecte visual (200 px/s → ~6 px d'efecte) + // El codi Pascal original sumava velocity (0-6) al radi per donar + // sensació de "empenta". Ara velocity està en px/s (0-200). // Basat en joc_asteroides.cpp línies 127-134 // - // [NUEVO] Convertir suma de velocitat_visual a escala multiplicativa + // [NUEVO] Convertir suma de velocitat_visual a scale multiplicativa // Radio base del ship = 12 px - // velocitat_visual = 0-6 → r = 12-18 → escala = 1.0-1.5 + // velocitat_visual = 0-6 → r = 12-18 → scale = 1.0-1.5 float velocitat_visual = velocity_ / 33.33F; - float escala = 1.0F + (velocitat_visual / 12.0F); + float scale = 1.0F + (velocitat_visual / 12.0F); - Rendering::render_shape(renderer_, shape_, center_, angle_, escala, 1.0F, brightness_); + Rendering::render_shape(renderer_, shape_, center_, angle_, scale, 1.0F, brightness_); } void Ship::applyPhysics(float delta_time) { // Aplicar física de moviment // Basat en joc_asteroides.cpp línies 87-113 - // Calcular nova posició basada en velocitat i angle + // Calcular nova posició basada en velocity i angle // S'usa (angle - PI/2) perquè angle=0 apunta cap amunt, no cap a la dreta // velocity_ està en px/s, així que multipliquem per delta_time float dy = @@ -184,7 +184,7 @@ void Ship::applyPhysics(float delta_time) { ((velocity_ * delta_time) * std::cos(angle_ - (Constants::PI / 2.0F))) + center_.x; - // Boundary checking amb radi de la nau + // Boundary checking amb radi de la ship // CORRECCIÓ: Usar límits segurs i inequalitats inclusives float min_x; float max_x; diff --git a/source/game/entities/ship.hpp b/source/game/entities/ship.hpp index a94caaa..eb1574e 100644 --- a/source/game/entities/ship.hpp +++ b/source/game/entities/ship.hpp @@ -1,4 +1,4 @@ -// nau.hpp - Classe per a la nave del jugador +// ship.hpp - Classe per a la nave del player // © 1999 Visente i Sergi (versió Pascal) // © 2025 Port a C++20 amb SDL3 diff --git a/source/game/options.cpp b/source/game/options.cpp index 963835a..f3aaec6 100644 --- a/source/game/options.cpp +++ b/source/game/options.cpp @@ -222,7 +222,7 @@ void init() { // Establir la ruta del fitxer de configuració void setConfigFile(const std::string& path) { config_file_path = path; } -// Funcions auxiliars per carregar seccions del YAML +// Funcions auxiliars per load seccions del YAML static void loadWindowConfigFromYaml(const fkyaml::node& yaml) { if (yaml.contains("window")) { @@ -446,7 +446,7 @@ static void loadAudioConfigFromYaml(const fkyaml::node& yaml) { } } -// Carregar controls del jugador 1 des de YAML +// Carregar controls del player 1 des de YAML static void loadPlayer1ControlsFromYaml(const fkyaml::node& yaml) { if (!yaml.contains("player1")) { return; @@ -494,7 +494,7 @@ static void loadPlayer1ControlsFromYaml(const fkyaml::node& yaml) { } } -// Carregar controls del jugador 2 des de YAML +// Carregar controls del player 2 des de YAML static void loadPlayer2ControlsFromYaml(const fkyaml::node& yaml) { if (!yaml.contains("player2")) { return; @@ -611,7 +611,7 @@ auto loadFromFile() -> bool { } } -// Guardar controls del jugador 1 a YAML +// Guardar controls del player 1 a YAML static void savePlayer1ControlsToYaml(std::ofstream& file) { file << "# CONTROLS JUGADOR 1\n"; file << "player1:\n"; @@ -628,7 +628,7 @@ static void savePlayer1ControlsToYaml(std::ofstream& file) { file << " gamepad_name: \"" << player1.gamepad_name << "\" # Buit = primer disponible\n\n"; } -// Guardar controls del jugador 2 a YAML +// Guardar controls del player 2 a YAML static void savePlayer2ControlsToYaml(std::ofstream& file) { file << "# CONTROLS JUGADOR 2\n"; file << "player2:\n"; diff --git a/source/game/options.hpp b/source/game/options.hpp index 3d019d6..c226ee9 100644 --- a/source/game/options.hpp +++ b/source/game/options.hpp @@ -83,7 +83,7 @@ inline Gameplay gameplay{}; inline Rendering rendering{}; inline Audio audio{}; -// Controles per jugador +// Controles per player inline PlayerControls player1{ .keyboard = {.key_left = SDL_SCANCODE_LEFT, diff --git a/source/game/scenes/game_scene.cpp b/source/game/scenes/game_scene.cpp index 2f54778..439a6b3 100644 --- a/source/game/scenes/game_scene.cpp +++ b/source/game/scenes/game_scene.cpp @@ -30,15 +30,15 @@ using Option = SceneContext::Option; GameScene::GameScene(SDLManager& sdl, SceneContext& context) : sdl_(sdl), context_(context), - debris_manager_(sdl.obte_renderer()), - gestor_puntuacio_(sdl.obte_renderer()), - text_(sdl.obte_renderer()), + debris_manager_(sdl.getRenderer()), + floating_score_manager_(sdl.getRenderer()), + text_(sdl.getRenderer()), init_hud_rect_sound_played_(false) { - // Recuperar configuració de partida des del context + // Recuperar configuració de match des del context match_config_ = context_.getMatchConfig(); // Debug output de la configuració - std::cout << "[GameScene] Configuració de partida - P1: " + std::cout << "[GameScene] Configuració de match - P1: " << (match_config_.jugador1_actiu ? "ACTIU" : "INACTIU") << ", P2: " << (match_config_.jugador2_actiu ? "ACTIU" : "INACTIU") @@ -49,24 +49,24 @@ GameScene::GameScene(SDLManager& sdl, SceneContext& context) (void)option; // Suprimir warning de variable no usada // Inicialitzar naus amb renderer (P1=ship.shp, P2=ship2.shp) - naus_[0] = Ship(sdl.obte_renderer(), "ship.shp"); // Jugador 1: nave estàndar - naus_[1] = Ship(sdl.obte_renderer(), "ship2.shp"); // Jugador 2: interceptor amb ales + ships_[0] = Ship(sdl.getRenderer(), "ship.shp"); // Jugador 1: nave estàndar + ships_[1] = Ship(sdl.getRenderer(), "ship2.shp"); // Jugador 2: interceptor amb ales // Inicialitzar bales amb renderer - for (auto& bala : bales_) { - bala = Bullet(sdl.obte_renderer()); + for (auto& bullet : bullets_) { + bullet = Bullet(sdl.getRenderer()); } // Inicialitzar enemics amb renderer - for (auto& enemy : orni_) { - enemy = Enemy(sdl.obte_renderer()); + for (auto& enemy : enemies_) { + enemy = Enemy(sdl.getRenderer()); } } void GameScene::run() { std::cout << "SceneType Joc: Inicialitzant...\n"; - // Inicialitzar estat del joc + // Inicialitzar state del joc init(); SDL_Event event; @@ -113,7 +113,7 @@ void GameScene::run() { // Netejar pantalla (usa color oscil·lat) sdl_.neteja(0, 0, 0); - // Actualitzar context de renderitzat (factor d'escala global) + // Actualitzar context de renderitzat (factor d'scale global) sdl_.updateRenderingContext(); // Dibuixar joc @@ -133,9 +133,9 @@ void GameScene::init() { // [NEW] Load stage configuration (only once) if (!stage_config_) { - stage_config_ = StageSystem::StageLoader::carregar("data/stages/stages.yaml"); + stage_config_ = StageSystem::StageLoader::load("data/stages/stages.yaml"); if (!stage_config_) { - std::cerr << "[GameScene] Error: no s'ha pogut carregar stages.yaml" << '\n'; + std::cerr << "[GameScene] Error: no s'ha pogut load stages.yaml" << '\n'; // Continue without stage system (will crash, but helps debugging) } } @@ -145,59 +145,59 @@ void GameScene::init() { stage_manager_->init(); // [NEW] Set ship position reference for safe spawn (P1 for now, TODO: dual tracking) - stage_manager_->get_spawn_controller().set_ship_position(&naus_[0].getCenter()); + stage_manager_->get_spawn_controller().set_ship_position(&ships_[0].getCenter()); - // Inicialitzar timers de muerte per jugador - itocado_per_jugador_[0] = 0.0F; - itocado_per_jugador_[1] = 0.0F; + // Inicialitzar timers de muerte per player + hit_timer_per_player_[0] = 0.0F; + hit_timer_per_player_[1] = 0.0F; // Initialize lives and game over state (independent lives per player) - vides_per_jugador_[0] = Defaults::Game::STARTING_LIVES; - vides_per_jugador_[1] = Defaults::Game::STARTING_LIVES; - estat_game_over_ = GameOverState::NONE; + lives_per_player_[0] = Defaults::Game::STARTING_LIVES; + lives_per_player_[1] = Defaults::Game::STARTING_LIVES; + game_over_state_ = GameOverState::NONE; continue_counter_ = 0; continue_tick_timer_ = 0.0F; - continues_usados_ = 0; + continues_used_ = 0; game_over_timer_ = 0.0F; // Initialize scores (separate per player) - puntuacio_per_jugador_[0] = 0; - puntuacio_per_jugador_[1] = 0; - gestor_puntuacio_.reiniciar(); + score_per_player_[0] = 0; + score_per_player_[1] = 0; + floating_score_manager_.reset(); - // DEPRECATED: punt_spawn_ ja no s'usa, es calcula dinàmicament amb obtenir_punt_spawn(player_id) + // DEPRECATED: spawn_position_ ja no s'usa, es calcula dinàmicament amb obtenir_punt_spawn(player_id) // const SDL_FRect& zona = Defaults::Zones::PLAYAREA; - // punt_spawn_.x = zona.x + zona.w * 0.5f; - // punt_spawn_.y = zona.y + zona.h * Defaults::Game::INIT_HUD_SHIP_START_Y_RATIO; + // spawn_position_.x = zona.x + zona.w * 0.5f; + // spawn_position_.y = zona.y + zona.h * Defaults::Game::INIT_HUD_SHIP_START_Y_RATIO; - // Inicialitzar naus segons configuració (només jugadors actius) + // Inicialitzar naus segons configuració (només jugadors active) for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; if (jugador_actiu) { - // Jugador actiu: init normalment + // Jugador active: init normalment Vec2 spawn_pos = obtenir_punt_spawn(i); - naus_[i].init(&spawn_pos, false); // No invulnerability at start + ships_[i].init(&spawn_pos, false); // No invulnerability at start std::cout << "[GameScene] Jugador " << (i + 1) << " inicialitzat\n"; } else { // Jugador inactiu: marcar com a mort permanent - naus_[i].markHit(); - itocado_per_jugador_[i] = 999.0F; // Valor sentinella (permanent inactiu) - vides_per_jugador_[i] = 0; // Sense vides + ships_[i].markHit(); + hit_timer_per_player_[i] = 999.0F; // Valor sentinella (permanent inactiu) + lives_per_player_[i] = 0; // Sense vides std::cout << "[GameScene] Jugador " << (i + 1) << " inactiu\n"; } } // [MODIFIED] Initialize enemies as inactive (stage system will spawn them) - for (auto& enemy : orni_) { - enemy = Enemy(sdl_.obte_renderer()); - enemy.set_ship_position(&naus_[0].getCenter()); // Set ship reference (P1 for now) + for (auto& enemy : enemies_) { + enemy = Enemy(sdl_.getRenderer()); + enemy.set_ship_position(&ships_[0].getCenter()); // Set ship reference (P1 for now) // DON'T call enemy.init() here - stage system handles spawning } // Inicialitzar bales (now 6 instead of 3) - for (auto& bala : bales_) { - bala.init(); + for (auto& bullet : bullets_) { + bullet.init(); } // [ELIMINAT] Iniciar música de joc (ara es gestiona en stage_manager) @@ -210,17 +210,17 @@ void GameScene::init() { void GameScene::update(float delta_time) { // Processar disparos (state-based, no event-based) - if (estat_game_over_ == GameOverState::NONE) { + if (game_over_state_ == GameOverState::NONE) { auto* input = Input::get(); - // Jugador 1 dispara (només si està actiu) + // Jugador 1 dispara (només si està active) if (match_config_.jugador1_actiu) { if (input->checkActionPlayer1(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) { disparar_bala(0); } } - // Jugador 2 dispara (només si està actiu) + // Jugador 2 dispara (només si està active) if (match_config_.jugador2_actiu) { if (input->checkActionPlayer2(InputAction::SHOOT, Input::DO_NOT_ALLOW_REPEAT)) { disparar_bala(1); @@ -232,10 +232,10 @@ void GameScene::update(float delta_time) { if (stage_manager_->get_estat() == StageSystem::EstatStage::PLAYING) { // Check if at least one player is alive and playing (game in progress) bool algun_jugador_viu = false; - if (match_config_.jugador1_actiu && itocado_per_jugador_[0] != 999.0F) { + if (match_config_.jugador1_actiu && hit_timer_per_player_[0] != 999.0F) { algun_jugador_viu = true; } - if (match_config_.jugador2_actiu && itocado_per_jugador_[1] != 999.0F) { + if (match_config_.jugador2_actiu && hit_timer_per_player_[1] != 999.0F) { algun_jugador_viu = true; } @@ -243,7 +243,7 @@ void GameScene::update(float delta_time) { if (algun_jugador_viu) { // P2 can join if not currently playing (never joined OR dead without lives) bool p2_no_juga = !match_config_.jugador2_actiu || // Never joined - itocado_per_jugador_[1] == 999.0F; // Dead without lives + hit_timer_per_player_[1] == 999.0F; // Dead without lives if (p2_no_juga) { if (input->checkActionPlayer2(InputAction::START, Input::DO_NOT_ALLOW_REPEAT)) { @@ -253,7 +253,7 @@ void GameScene::update(float delta_time) { // P1 can join if not currently playing (never joined OR dead without lives) bool p1_no_juga = !match_config_.jugador1_actiu || // Never joined - itocado_per_jugador_[0] == 999.0F; // Dead without lives + hit_timer_per_player_[0] == 999.0F; // Dead without lives if (p1_no_juga) { if (input->checkActionPlayer1(InputAction::START, Input::DO_NOT_ALLOW_REPEAT)) { @@ -265,24 +265,24 @@ void GameScene::update(float delta_time) { } // Handle CONTINUE screen - if (estat_game_over_ == GameOverState::CONTINUE) { + if (game_over_state_ == GameOverState::CONTINUE) { actualitzar_continue(delta_time); processar_input_continue(); // Still update enemies, bullets, and effects during continue screen - for (auto& enemy : orni_) { + for (auto& enemy : enemies_) { enemy.update(delta_time); } - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } debris_manager_.update(delta_time); - gestor_puntuacio_.update(delta_time); + floating_score_manager_.update(delta_time); return; } // Handle final GAME OVER state - if (estat_game_over_ == GameOverState::GAME_OVER) { + if (game_over_state_ == GameOverState::GAME_OVER) { // Game over: only update timer, enemies, bullets, and debris game_over_timer_ -= delta_time; @@ -296,50 +296,50 @@ void GameScene::update(float delta_time) { } // Enemies and bullets continue moving during game over - for (auto& enemy : orni_) { + for (auto& enemy : enemies_) { enemy.update(delta_time); } - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } debris_manager_.update(delta_time); - gestor_puntuacio_.update(delta_time); + floating_score_manager_.update(delta_time); return; } // Check death sequence state for BOTH players bool algun_jugador_mort = false; for (uint8_t i = 0; i < 2; i++) { - if (itocado_per_jugador_[i] > 0.0F && itocado_per_jugador_[i] < 999.0F) { + if (hit_timer_per_player_[i] > 0.0F && hit_timer_per_player_[i] < 999.0F) { algun_jugador_mort = true; // Death sequence active: update timer - itocado_per_jugador_[i] += delta_time; + hit_timer_per_player_[i] += delta_time; // Check if death duration completed (only trigger ONCE using sentinel value) - if (itocado_per_jugador_[i] >= Defaults::Game::DEATH_DURATION) { + if (hit_timer_per_player_[i] >= Defaults::Game::DEATH_DURATION) { // *** PHASE 3: RESPAWN OR GAME OVER *** // Decrement lives for this player (only once) - vides_per_jugador_[i]--; + lives_per_player_[i]--; - if (vides_per_jugador_[i] > 0) { + if (lives_per_player_[i] > 0) { // Respawn ship en spawn position con invulnerabilidad Vec2 spawn_pos = obtenir_punt_spawn(i); - naus_[i].init(&spawn_pos, true); - itocado_per_jugador_[i] = 0.0F; + ships_[i].init(&spawn_pos, true); + hit_timer_per_player_[i] = 0.0F; } else { // Player is permanently dead (out of lives) // Set sentinel value to prevent re-entering this block - itocado_per_jugador_[i] = 999.0F; + hit_timer_per_player_[i] = 999.0F; // Check if ALL ACTIVE players are dead (trigger continue screen) - bool p1_dead = !match_config_.jugador1_actiu || vides_per_jugador_[0] <= 0; - bool p2_dead = !match_config_.jugador2_actiu || vides_per_jugador_[1] <= 0; + bool p1_dead = !match_config_.jugador1_actiu || lives_per_player_[0] <= 0; + bool p2_dead = !match_config_.jugador2_actiu || lives_per_player_[1] <= 0; if (p1_dead && p2_dead) { - estat_game_over_ = GameOverState::CONTINUE; + game_over_state_ = GameOverState::CONTINUE; continue_counter_ = Defaults::Game::CONTINUE_COUNT_START; continue_tick_timer_ = Defaults::Game::CONTINUE_TICK_DURATION; } @@ -351,31 +351,31 @@ void GameScene::update(float delta_time) { // If any player is dead, still update enemies/bullets/effects if (algun_jugador_mort) { // Enemies and bullets continue moving during death sequence - for (auto& enemy : orni_) { + for (auto& enemy : enemies_) { enemy.update(delta_time); } - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } debris_manager_.update(delta_time); - gestor_puntuacio_.update(delta_time); + floating_score_manager_.update(delta_time); // Don't return - allow alive players to continue playing } // *** STAGE SYSTEM STATE MACHINE *** - StageSystem::EstatStage estat = stage_manager_->get_estat(); + StageSystem::EstatStage state = stage_manager_->get_estat(); - switch (estat) { + switch (state) { case StageSystem::EstatStage::INIT_HUD: { - // Update stage manager timer (pot canviar l'estat!) + // Update stage manager timer (pot canviar l'state!) stage_manager_->update(delta_time); - // [FIX] Si l'estat ha canviat durant update(), sortir immediatament - // per evitar recalcular la posició de la nau amb el nou timer + // [FIX] Si l'state ha canviat durant update(), sortir immediatament + // per evitar recalcular la posició de la ship amb el nou timer if (stage_manager_->get_estat() != StageSystem::EstatStage::INIT_HUD) { break; } @@ -398,12 +398,12 @@ void GameScene::update(float delta_time) { // [MODIFICAT] Animar AMBAS naus con sus progress respectivos if (match_config_.jugador1_actiu && ship1_progress < 1.0F) { Vec2 pos_p1 = calcular_posicio_nau_init_hud(ship1_progress, 0); - naus_[0].setCenter(pos_p1); + ships_[0].setCenter(pos_p1); } if (match_config_.jugador2_actiu && ship2_progress < 1.0F) { Vec2 pos_p2 = calcular_posicio_nau_init_hud(ship2_progress, 1); - naus_[1].setCenter(pos_p2); + ships_[1].setCenter(pos_p2); } // Una vegada l'animació acaba, permetre control normal @@ -416,7 +416,7 @@ void GameScene::update(float delta_time) { // [DEBUG] Log entrada a LEVEL_START static bool first_entry = true; if (first_entry) { - std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << naus_[0].getCenter().y << '\n'; + std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << ships_[0].getCenter().y << '\n'; first_entry = false; } @@ -426,15 +426,15 @@ void GameScene::update(float delta_time) { // [NEW] Allow both ships movement and shooting during intro for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players - naus_[i].processInput(delta_time, i); - naus_[i].update(delta_time); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { // Only active, alive players + ships_[i].processInput(delta_time, i); + ships_[i].update(delta_time); } } // [NEW] Update bullets - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } // [NEW] Update debris @@ -444,14 +444,14 @@ void GameScene::update(float delta_time) { case StageSystem::EstatStage::PLAYING: { // [NEW] Update stage manager (spawns enemies, pause if BOTH dead) - bool pausar_spawn = (itocado_per_jugador_[0] > 0.0F && itocado_per_jugador_[1] > 0.0F); - stage_manager_->get_spawn_controller().update(delta_time, orni_, pausar_spawn); + bool pausar_spawn = (hit_timer_per_player_[0] > 0.0F && hit_timer_per_player_[1] > 0.0F); + stage_manager_->get_spawn_controller().update(delta_time, enemies_, pausar_spawn); // [NEW] Check stage completion (only when at least one player alive) - bool algun_jugador_viu = (itocado_per_jugador_[0] == 0.0F || itocado_per_jugador_[1] == 0.0F); + bool algun_jugador_viu = (hit_timer_per_player_[0] == 0.0F || hit_timer_per_player_[1] == 0.0F); if (algun_jugador_viu) { auto& spawn_ctrl = stage_manager_->get_spawn_controller(); - if (spawn_ctrl.tots_enemics_destruits(orni_)) { + if (spawn_ctrl.tots_enemics_destruits(enemies_)) { stage_manager_->stage_completat(); Audio::get()->playSound(Defaults::Sound::GOOD_JOB_COMMANDER, Audio::Group::GAME); break; @@ -461,25 +461,25 @@ void GameScene::update(float delta_time) { // [EXISTING] Normal gameplay - update active players for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players - naus_[i].processInput(delta_time, i); - naus_[i].update(delta_time); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { // Only active, alive players + ships_[i].processInput(delta_time, i); + ships_[i].update(delta_time); } } - for (auto& enemy : orni_) { + for (auto& enemy : enemies_) { enemy.update(delta_time); } - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } detectar_col·lisions_bales_enemics(); detectar_col·lisio_naus_enemics(); detectar_col·lisions_bales_jugadors(); debris_manager_.update(delta_time); - gestor_puntuacio_.update(delta_time); + floating_score_manager_.update(delta_time); break; } @@ -490,40 +490,40 @@ void GameScene::update(float delta_time) { // [NEW] Allow both ships movement and shooting during outro for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players - naus_[i].processInput(delta_time, i); - naus_[i].update(delta_time); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { // Only active, alive players + ships_[i].processInput(delta_time, i); + ships_[i].update(delta_time); } } // [NEW] Update bullets (allow last shots to continue) - for (auto& bala : bales_) { - bala.update(delta_time); + for (auto& bullet : bullets_) { + bullet.update(delta_time); } // [NEW] Update debris (from last destroyed enemies) debris_manager_.update(delta_time); - gestor_puntuacio_.update(delta_time); + floating_score_manager_.update(delta_time); break; } } void GameScene::draw() { // Handle CONTINUE screen - if (estat_game_over_ == GameOverState::CONTINUE) { + if (game_over_state_ == GameOverState::CONTINUE) { // Draw game background elements first dibuixar_marges(); - for (const auto& enemy : orni_) { + for (const auto& enemy : enemies_) { enemy.draw(); } - for (const auto& bala : bales_) { - bala.draw(); + for (const auto& bullet : bullets_) { + bullet.draw(); } debris_manager_.draw(); - gestor_puntuacio_.draw(); + floating_score_manager_.draw(); dibuixar_marcador(); // Draw CONTINUE screen overlay @@ -532,24 +532,24 @@ void GameScene::draw() { } // Handle final GAME OVER state - if (estat_game_over_ == GameOverState::GAME_OVER) { + if (game_over_state_ == GameOverState::GAME_OVER) { // Game over: draw enemies, bullets, debris, and "GAME OVER" text dibuixar_marges(); - for (const auto& enemy : orni_) { + for (const auto& enemy : enemies_) { enemy.draw(); } - for (const auto& bala : bales_) { - bala.draw(); + for (const auto& bullet : bullets_) { + bullet.draw(); } debris_manager_.draw(); - gestor_puntuacio_.draw(); + floating_score_manager_.draw(); // Draw centered "GAME OVER" text const std::string game_over_text = "GAME OVER"; - constexpr float escala = Defaults::Game::GameOverScreen::TEXT_SCALE; + constexpr float scale = Defaults::Game::GameOverScreen::TEXT_SCALE; constexpr float spacing = Defaults::Game::GameOverScreen::TEXT_SPACING; // Calcular centre de l'àrea de joc usant constants @@ -557,16 +557,16 @@ void GameScene::draw() { float centre_x = play_area.x + (play_area.w / 2.0F); float centre_y = play_area.y + (play_area.h / 2.0F); - text_.render_centered(game_over_text, {.x = centre_x, .y = centre_y}, escala, spacing); + text_.renderCentered(game_over_text, {.x = centre_x, .y = centre_y}, scale, spacing); dibuixar_marcador(); return; } // [NEW] Stage state rendering - StageSystem::EstatStage estat = stage_manager_->get_estat(); + StageSystem::EstatStage state = stage_manager_->get_estat(); - switch (estat) { + switch (state) { case StageSystem::EstatStage::INIT_HUD: { // Calcular progrés de cada animació independent float timer = stage_manager_->get_timer_transicio(); @@ -610,12 +610,12 @@ void GameScene::draw() { } // [MODIFICAT] Dibuixar naus amb progress independent - if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !naus_[0].isHit()) { - naus_[0].draw(); + if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) { + ships_[0].draw(); } - if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !naus_[1].isHit()) { - naus_[1].draw(); + if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) { + ships_[1].draw(); } break; @@ -626,19 +626,19 @@ void GameScene::draw() { // [NEW] Draw both ships if active and alive for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { - naus_[i].draw(); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { + ships_[i].draw(); } } // [NEW] Draw bullets - for (const auto& bala : bales_) { - bala.draw(); + for (const auto& bullet : bullets_) { + bullet.draw(); } // [NEW] Draw debris debris_manager_.draw(); - gestor_puntuacio_.draw(); + floating_score_manager_.draw(); // [EXISTING] Draw intro message and score dibuixar_missatge_stage(stage_manager_->get_missatge_level_start()); @@ -651,21 +651,21 @@ void GameScene::draw() { // [EXISTING] Normal rendering - active ships for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { - naus_[i].draw(); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { + ships_[i].draw(); } } - for (const auto& enemy : orni_) { + for (const auto& enemy : enemies_) { enemy.draw(); } - for (const auto& bala : bales_) { - bala.draw(); + for (const auto& bullet : bullets_) { + bullet.draw(); } debris_manager_.draw(); - gestor_puntuacio_.draw(); + floating_score_manager_.draw(); dibuixar_marcador(); break; @@ -674,19 +674,19 @@ void GameScene::draw() { // [NEW] Draw both ships if active and alive for (uint8_t i = 0; i < 2; i++) { bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu; - if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { - naus_[i].draw(); + if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) { + ships_[i].draw(); } } // [NEW] Draw bullets (allow last shots to be visible) - for (const auto& bala : bales_) { - bala.draw(); + for (const auto& bullet : bullets_) { + bullet.draw(); } // [NEW] Draw debris (from last destroyed enemies) debris_manager_.draw(); - gestor_puntuacio_.draw(); + floating_score_manager_.draw(); // [EXISTING] Draw completion message and score dibuixar_missatge_stage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED); @@ -697,41 +697,41 @@ void GameScene::draw() { void GameScene::tocado(uint8_t player_id) { // Death sequence: 3 phases - // Phase 1: First call (itocado_per_jugador_[player_id] == 0) - trigger explosion + // Phase 1: First call (hit_timer_per_player_[player_id] == 0) - trigger explosion // Phase 2: Animation (0 < itocado_ < 3.0s) - debris animation // Phase 3: Respawn or game over (itocado_ >= 3.0s) - handled in update() - if (itocado_per_jugador_[player_id] == 0.0F) { + if (hit_timer_per_player_[player_id] == 0.0F) { // *** PHASE 1: TRIGGER DEATH *** // Mark ship as dead (stops rendering and input) - naus_[player_id].markHit(); + ships_[player_id].markHit(); // Create ship explosion - const Vec2& ship_pos = naus_[player_id].getCenter(); - float ship_angle = naus_[player_id].getAngle(); - Vec2 vel_nau = naus_[player_id].getVelocityVector(); - // Reduir a 80% la velocitat heretada per la nau (més realista) + const Vec2& ship_pos = ships_[player_id].getCenter(); + float ship_angle = ships_[player_id].getAngle(); + Vec2 vel_nau = ships_[player_id].getVelocityVector(); + // Reduir a 80% la velocity heretada per la ship (més realista) Vec2 vel_nau_80 = {.x = vel_nau.x * 0.8F, .y = vel_nau.y * 0.8F}; - debris_manager_.explotar( - naus_[player_id].getShape(), // Ship shape (3 lines) + debris_manager_.explode( + ships_[player_id].getShape(), // Ship shape (3 lines) ship_pos, // Center position ship_angle, // Ship orientation 1.0F, // Normal scale Defaults::Physics::Debris::VELOCITAT_BASE, // 80 px/s - naus_[player_id].getBrightness(), // Heredar brightness - vel_nau_80, // Heredar 80% velocitat + ships_[player_id].getBrightness(), // Heredar brightness + vel_nau_80, // Heredar 80% velocity 0.0F, // Nave: trayectorias rectas (sin drotacio) 0.0F, // Sin herencia visual (rotación aleatoria) Defaults::Sound::EXPLOSION2 // Sonido alternativo para la explosión ); // Start death timer (non-zero to avoid re-triggering) - itocado_per_jugador_[player_id] = 0.001F; + hit_timer_per_player_[player_id] = 0.001F; } // Phase 2 is automatic (debris updates in update()) - // Phase 3 is handled in update() when itocado_per_jugador_ >= DEATH_DURATION + // Phase 3 is handled in update() when hit_timer_per_player_ >= DEATH_DURATION } void GameScene::dibuixar_marges() const { @@ -745,18 +745,18 @@ void GameScene::dibuixar_marges() const { int y2 = static_cast(zona.y + zona.h); // 4 línies per formar el rectangle - Rendering::linea(sdl_.obte_renderer(), x1, y1, x2, y1); // Top - Rendering::linea(sdl_.obte_renderer(), x1, y2, x2, y2); // Bottom - Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2); // Left - Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2); // Right + Rendering::linea(sdl_.getRenderer(), x1, y1, x2, y1); // Top + Rendering::linea(sdl_.getRenderer(), x1, y2, x2, y2); // Bottom + Rendering::linea(sdl_.getRenderer(), x1, y1, x1, y2); // Left + Rendering::linea(sdl_.getRenderer(), x2, y1, x2, y2); // Right } void GameScene::dibuixar_marcador() { // Construir text del marcador - std::string text = construir_marcador(); + std::string text = buildScoreboard(); // Paràmetres de renderització - const float escala = 0.85F; + const float scale = 0.85F; const float spacing = 0.0F; // Calcular centre de la zona del marcador @@ -765,7 +765,7 @@ void GameScene::dibuixar_marcador() { float centre_y = scoreboard.y + (scoreboard.h / 2.0F); // Renderitzar centrat - text_.render_centered(text, {.x = centre_x, .y = centre_y}, escala, spacing); + text_.renderCentered(text, {.x = centre_x, .y = centre_y}, scale, spacing); } void GameScene::dibuixar_marges_animat(float progress) const { @@ -794,11 +794,11 @@ void GameScene::dibuixar_marges_animat(float progress) const { // Línia esquerra: creix des del centre cap a l'esquerra int x1_phase1 = static_cast(cx - ((cx - x1) * phase1_progress)); - Rendering::linea(sdl_.obte_renderer(), cx, y1, x1_phase1, y1); + Rendering::linea(sdl_.getRenderer(), cx, y1, x1_phase1, y1); // Línia dreta: creix des del centre cap a la dreta int x2_phase1 = static_cast(cx + ((x2 - cx) * phase1_progress)); - Rendering::linea(sdl_.obte_renderer(), cx, y1, x2_phase1, y1); + Rendering::linea(sdl_.getRenderer(), cx, y1, x2_phase1, y1); } // --- FASE 2: Línies verticals laterals (33-66%) --- @@ -807,10 +807,10 @@ void GameScene::dibuixar_marges_animat(float progress) const { // Línia esquerra: creix des de dalt cap a baix int y2_phase2 = static_cast(y1 + ((y2 - y1) * phase2_progress)); - Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2_phase2); + Rendering::linea(sdl_.getRenderer(), x1, y1, x1, y2_phase2); // Línia dreta: creix des de dalt cap a baix - Rendering::linea(sdl_.obte_renderer(), x2, y1, x2, y2_phase2); + Rendering::linea(sdl_.getRenderer(), x2, y1, x2, y2_phase2); } // --- FASE 3: Línies horitzontals inferiors (66-100%) --- @@ -819,11 +819,11 @@ void GameScene::dibuixar_marges_animat(float progress) const { // Línia esquerra: creix des de l'esquerra cap al centre int x_left_phase3 = static_cast(x1 + ((cx - x1) * phase3_progress)); - Rendering::linea(sdl_.obte_renderer(), x1, y2, x_left_phase3, y2); + Rendering::linea(sdl_.getRenderer(), x1, y2, x_left_phase3, y2); // Línia dreta: creix des de la dreta cap al centre int x_right_phase3 = static_cast(x2 - ((x2 - cx) * phase3_progress)); - Rendering::linea(sdl_.obte_renderer(), x2, y2, x_right_phase3, y2); + Rendering::linea(sdl_.getRenderer(), x2, y2, x_right_phase3, y2); } } @@ -834,10 +834,10 @@ void GameScene::dibuixar_marcador_animat(float progress) { float eased_progress = Easing::ease_out_quad(progress); // Construir text - std::string text = construir_marcador(); + std::string text = buildScoreboard(); // Paràmetres - const float escala = 0.85F; + const float scale = 0.85F; const float spacing = 0.0F; // Calcular centre de la zona del marcador @@ -852,11 +852,11 @@ void GameScene::dibuixar_marcador_animat(float progress) { float centre_y_animada = centre_y_inicial + ((centre_y_final - centre_y_inicial) * eased_progress); // Renderitzar centrat en posició animada - text_.render_centered(text, {.x = centre_x, .y = centre_y_animada}, escala, spacing); + text_.renderCentered(text, {.x = centre_x, .y = centre_y_animada}, scale, spacing); } Vec2 GameScene::calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const { - // Animació de la nau pujant des de baix amb easing + // Animació de la ship pujant des de baix amb easing // [MODIFICAT] Ambas naves usan ease_out_quad (desfase temporal via INIT/END) // Aplicar easing (uniforme para ambas naves) @@ -864,7 +864,7 @@ Vec2 GameScene::calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const SDL_FRect& zona = Defaults::Zones::PLAYAREA; - // Calcular posició final segons jugador (reutilitza obtenir_punt_spawn) + // Calcular posició final segons player (reutilitza obtenir_punt_spawn) Vec2 spawn_final = obtenir_punt_spawn(player_id); float x_final = spawn_final.x; float y_final = spawn_final.y; @@ -904,16 +904,16 @@ float GameScene::calcular_progress_rango(float global_progress, float ratio_init return (global_progress - ratio_init) / (ratio_end - ratio_init); } -std::string GameScene::construir_marcador() const { +std::string GameScene::buildScoreboard() const { // Puntuació P1 (6 dígits) - mostrar zeros si inactiu std::string score_p1; std::string vides_p1; if (match_config_.jugador1_actiu) { - score_p1 = std::to_string(puntuacio_per_jugador_[0]); + score_p1 = std::to_string(score_per_player_[0]); score_p1 = std::string(6 - std::min(6, static_cast(score_p1.length())), '0') + score_p1; - vides_p1 = (vides_per_jugador_[0] < 10) - ? "0" + std::to_string(vides_per_jugador_[0]) - : std::to_string(vides_per_jugador_[0]); + vides_p1 = (lives_per_player_[0] < 10) + ? "0" + std::to_string(lives_per_player_[0]) + : std::to_string(lives_per_player_[0]); } else { score_p1 = "000000"; vides_p1 = "00"; @@ -928,11 +928,11 @@ std::string GameScene::construir_marcador() const { std::string score_p2; std::string vides_p2; if (match_config_.jugador2_actiu) { - score_p2 = std::to_string(puntuacio_per_jugador_[1]); + score_p2 = std::to_string(score_per_player_[1]); score_p2 = std::string(6 - std::min(6, static_cast(score_p2.length())), '0') + score_p2; - vides_p2 = (vides_per_jugador_[1] < 10) - ? "0" + std::to_string(vides_per_jugador_[1]) - : std::to_string(vides_per_jugador_[1]); + vides_p2 = (lives_per_player_[1] < 10) + ? "0" + std::to_string(lives_per_player_[1]) + : std::to_string(lives_per_player_[1]); } else { score_p2 = "000000"; vides_p2 = "00"; @@ -951,56 +951,56 @@ void GameScene::detectar_col·lisions_bales_enemics() { constexpr float VELOCITAT_EXPLOSIO = 80.0F; // px/s (en lloc de 80.0f per defecte) // Iterar per totes les bales i enemics - for (auto& bala : bales_) { - for (auto& enemic : orni_) { + for (auto& bullet : bullets_) { + for (auto& enemy : enemies_) { // Comprovar col·lisió utilitzant la interfície genèrica - if (Physics::check_collision(bala, enemic, AMPLIFIER)) { + if (Physics::check_collision(bullet, enemy, AMPLIFIER)) { // *** COL·LISIÓ DETECTADA *** - const Vec2& pos_enemic = enemic.getCenter(); + const Vec2& pos_enemic = enemy.getCenter(); // 1. Calculate score for enemy type - int punts = 0; - switch (enemic.getType()) { + int points = 0; + switch (enemy.getType()) { case EnemyType::PENTAGON: - punts = Defaults::Enemies::Scoring::PENTAGON_SCORE; + points = Defaults::Enemies::Scoring::PENTAGON_SCORE; break; case EnemyType::QUADRAT: - punts = Defaults::Enemies::Scoring::QUADRAT_SCORE; + points = Defaults::Enemies::Scoring::QUADRAT_SCORE; break; case EnemyType::MOLINILLO: - punts = Defaults::Enemies::Scoring::MOLINILLO_SCORE; + points = Defaults::Enemies::Scoring::MOLINILLO_SCORE; break; } // 2. Add score to the player who shot it - uint8_t owner_id = bala.get_owner_id(); - puntuacio_per_jugador_[owner_id] += punts; + uint8_t owner_id = bullet.get_owner_id(); + score_per_player_[owner_id] += points; // 3. Create floating score number - gestor_puntuacio_.crear(punts, pos_enemic); + floating_score_manager_.crear(points, pos_enemic); - // 4. Destruir enemic (marca com inactiu) - enemic.destruir(); + // 4. Destruir enemy (marca com inactiu) + enemy.destruir(); // 2. Crear explosió de fragments - Vec2 vel_enemic = enemic.getVelocityVector(); - debris_manager_.explotar( - enemic.getShape(), // Forma vectorial del pentàgon + Vec2 vel_enemic = enemy.getVelocityVector(); + debris_manager_.explode( + enemy.getShape(), // Forma vectorial del pentàgon pos_enemic, // Posició central - 0.0F, // Angle (enemic té rotació interna) + 0.0F, // Angle (enemy té rotació interna) 1.0F, // Escala normal VELOCITAT_EXPLOSIO, // 50 px/s (explosió suau) - enemic.getBrightness(), // Heredar brightness - vel_enemic, // Heredar velocitat - enemic.get_drotacio(), // Heredar velocitat angular (trayectorias curvas) + enemy.getBrightness(), // Heredar brightness + vel_enemic, // Heredar velocity + enemy.get_drotacio(), // Heredar velocity angular (trayectorias curvas) 0.0F // Sin herencia visual (rotación aleatoria) ); - // 3. Desactivar bala - bala.desactivar(); + // 3. Desactivar bullet + bullet.desactivar(); - // 4. Eixir del bucle intern (bala només destrueix 1 enemic) + // 4. Eixir del bucle intern (bullet només destrueix 1 enemy) break; } } @@ -1014,25 +1014,25 @@ void GameScene::detectar_col·lisio_naus_enemics() { // Check collision for BOTH players for (uint8_t i = 0; i < 2; i++) { // Skip collisions if player is dead or invulnerable - if (itocado_per_jugador_[i] > 0.0F) { + if (hit_timer_per_player_[i] > 0.0F) { continue; } - if (!naus_[i].isAlive()) { + if (!ships_[i].isAlive()) { continue; } - if (naus_[i].isInvulnerable()) { + if (ships_[i].isInvulnerable()) { continue; } // Check collision with all active enemies - for (const auto& enemic : orni_) { + for (const auto& enemy : enemies_) { // Skip collision if enemy is invulnerable - if (enemic.isInvulnerable()) { + if (enemy.isInvulnerable()) { continue; } // Comprovar col·lisió utilitzant la interfície genèrica - if (Physics::check_collision(naus_[i], enemic, AMPLIFIER)) { + if (Physics::check_collision(ships_[i], enemy, AMPLIFIER)) { tocado(i); // Trigger death sequence for player i break; // Only one collision per player per frame } @@ -1050,28 +1050,28 @@ void GameScene::detectar_col·lisions_bales_jugadors() { constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_PLAYER_AMPLIFIER; // Check all active bullets - for (auto& bala : bales_) { - if (!bala.esta_activa()) { + for (auto& bullet : bullets_) { + if (!bullet.esta_activa()) { continue; } // Skip bullets in grace period (prevents instant self-collision) - if (bala.get_grace_timer() > 0.0F) { + if (bullet.get_grace_timer() > 0.0F) { continue; } - uint8_t bullet_owner = bala.get_owner_id(); + uint8_t bullet_owner = bullet.get_owner_id(); // Check collision with BOTH players for (uint8_t player_id = 0; player_id < 2; player_id++) { // Skip if player is dead, invulnerable, or inactive - if (itocado_per_jugador_[player_id] > 0.0F) { + if (hit_timer_per_player_[player_id] > 0.0F) { continue; } - if (!naus_[player_id].isAlive()) { + if (!ships_[player_id].isAlive()) { continue; } - if (naus_[player_id].isInvulnerable()) { + if (ships_[player_id].isInvulnerable()) { continue; } @@ -1083,7 +1083,7 @@ void GameScene::detectar_col·lisions_bales_jugadors() { } // Comprovar col·lisió utilitzant la interfície genèrica - if (Physics::check_collision(bala, naus_[player_id], AMPLIFIER)) { + if (Physics::check_collision(bullet, ships_[player_id], AMPLIFIER)) { // *** FRIENDLY FIRE HIT *** if (bullet_owner == player_id) { @@ -1096,14 +1096,14 @@ void GameScene::detectar_col·lisions_bales_jugadors() { tocado(player_id); // Attacker gains 1 life (no cap) - vides_per_jugador_[bullet_owner]++; + lives_per_player_[bullet_owner]++; } // Play distinct sound Audio::get()->playSound(Defaults::Sound::FRIENDLY_FIRE_HIT, Audio::Group::GAME); // Deactivate bullet - bala.desactivar(); + bullet.desactivar(); break; // Bullet only hits once per frame } @@ -1113,7 +1113,7 @@ void GameScene::detectar_col·lisions_bales_jugadors() { // [NEW] Stage system helper methods -void GameScene::dibuixar_missatge_stage(const std::string& missatge) { +void GameScene::dibuixar_missatge_stage(const std::string& message) { constexpr float escala_base = 1.0F; constexpr float spacing = 2.0F; @@ -1143,31 +1143,31 @@ void GameScene::dibuixar_missatge_stage(const std::string& missatge) { if (typing_ratio > 0.0F && progress < typing_ratio) { // Typewriter phase: show partial text float typing_progress = progress / typing_ratio; // Normalize to 0.0-1.0 - visible_chars = static_cast(missatge.length() * typing_progress); + visible_chars = static_cast(message.length() * typing_progress); if (visible_chars == 0 && progress > 0.0F) { visible_chars = 1; // Show at least 1 character after first frame } } else { // Display phase: show complete text // (Either after typing phase, or immediately if typing_ratio == 0.0) - visible_chars = missatge.length(); + visible_chars = message.length(); } // Create partial message (substring for typewriter) - std::string partial_message = missatge.substr(0, visible_chars); + std::string partial_message = message.substr(0, visible_chars); // =================================================== // Calculate text width at base scale (using FULL message for position calculation) - float text_width_at_base = text_.get_text_width(missatge, escala_base, spacing); + float text_width_at_base = text_.get_text_width(message, escala_base, spacing); // Auto-scale if text exceeds max width - float escala = (text_width_at_base <= max_width) + float scale = (text_width_at_base <= max_width) ? escala_base : max_width / text_width_at_base; // Recalculate dimensions with final scale (using FULL message for centering) - float full_text_width = text_.get_text_width(missatge, escala, spacing); - float text_height = text_.get_text_height(escala); + float full_text_width = text_.get_text_width(message, scale, spacing); + float text_height = text_.get_text_height(scale); // Calculate position as if FULL text was there (for fixed position typewriter) float x = play_area.x + ((play_area.w - full_text_width) / 2.0F); @@ -1175,7 +1175,7 @@ void GameScene::dibuixar_missatge_stage(const std::string& missatge) { // Render only the partial message (typewriter effect) Vec2 pos = {.x = x, .y = y}; - text_.render(partial_message, pos, escala, spacing); + text_.render(partial_message, pos, scale, spacing); } // ======================================== @@ -1187,7 +1187,7 @@ Vec2 GameScene::obtenir_punt_spawn(uint8_t player_id) const { float x_ratio; if (match_config_.es_un_jugador()) { - // Un sol jugador: spawn al centre (50%) + // Un sol player: spawn al centre (50%) x_ratio = 0.5F; } else { // Dos jugadors: spawn a posicions separades @@ -1202,17 +1202,17 @@ Vec2 GameScene::obtenir_punt_spawn(uint8_t player_id) const { } void GameScene::disparar_bala(uint8_t player_id) { - // Verificar que el jugador está vivo - if (itocado_per_jugador_[player_id] > 0.0F) { + // Verificar que el player está vivo + if (hit_timer_per_player_[player_id] > 0.0F) { return; } - if (!naus_[player_id].isAlive()) { + if (!ships_[player_id].isAlive()) { return; } // Calcular posición en la punta de la nave - const Vec2& ship_centre = naus_[player_id].getCenter(); - float ship_angle = naus_[player_id].getAngle(); + const Vec2& ship_centre = ships_[player_id].getCenter(); + float ship_angle = ships_[player_id].getAngle(); constexpr float LOCAL_TIP_X = 0.0F; constexpr float LOCAL_TIP_Y = -12.0F; @@ -1222,11 +1222,11 @@ void GameScene::disparar_bala(uint8_t player_id) { float tip_y = (LOCAL_TIP_X * sin_a) + (LOCAL_TIP_Y * cos_a) + ship_centre.y; Vec2 posicio_dispar = {.x = tip_x, .y = tip_y}; - // Buscar primera bala inactiva en el pool del jugador + // Buscar primera bullet inactiva en el pool del player int start_idx = player_id * 3; // P1=[0,1,2], P2=[3,4,5] for (int i = start_idx; i < start_idx + 3; i++) { - if (!bales_[i].esta_activa()) { - bales_[i].disparar(posicio_dispar, ship_angle, player_id); + if (!bullets_[i].esta_activa()) { + bullets_[i].disparar(posicio_dispar, ship_angle, player_id); break; } } @@ -1236,7 +1236,7 @@ void GameScene::disparar_bala(uint8_t player_id) { void GameScene::check_and_apply_continue_timeout() { if (continue_counter_ < 0) { - estat_game_over_ = GameOverState::GAME_OVER; + game_over_state_ = GameOverState::GAME_OVER; game_over_timer_ = Defaults::Game::GAME_OVER_DURATION; } } @@ -1252,7 +1252,7 @@ void GameScene::actualitzar_continue(float delta_time) { check_and_apply_continue_timeout(); // Play sound only if still in CONTINUE state (not transitioned to GAME_OVER) - if (estat_game_over_ == GameOverState::CONTINUE) { + if (game_over_state_ == GameOverState::CONTINUE) { Audio::get()->playSound(Defaults::Sound::CONTINUE, Audio::Group::GAME); } } @@ -1267,25 +1267,25 @@ void GameScene::processar_input_continue() { if (p1_start || p2_start) { // Check continue limit (skip if infinite continues) - if (!Defaults::Game::INFINITE_CONTINUES && continues_usados_ >= Defaults::Game::MAX_CONTINUES) { + if (!Defaults::Game::INFINITE_CONTINUES && continues_used_ >= Defaults::Game::MAX_CONTINUES) { // Max continues reached → final game over - estat_game_over_ = GameOverState::GAME_OVER; + game_over_state_ = GameOverState::GAME_OVER; game_over_timer_ = Defaults::Game::GAME_OVER_DURATION; return; } // Only increment if not infinite if (!Defaults::Game::INFINITE_CONTINUES) { - continues_usados_++; + continues_used_++; } // Determine which player(s) to revive uint8_t player_to_revive = p1_start ? 0 : 1; // Reset score and lives (KEEP level and enemies!) - puntuacio_per_jugador_[player_to_revive] = 0; - vides_per_jugador_[player_to_revive] = Defaults::Game::STARTING_LIVES; - itocado_per_jugador_[player_to_revive] = 0.0F; + score_per_player_[player_to_revive] = 0; + lives_per_player_[player_to_revive] = Defaults::Game::STARTING_LIVES; + hit_timer_per_player_[player_to_revive] = 0.0F; // Activate player if not already if (player_to_revive == 0) { @@ -1296,21 +1296,21 @@ void GameScene::processar_input_continue() { // Spawn with invulnerability Vec2 spawn_pos = obtenir_punt_spawn(player_to_revive); - naus_[player_to_revive].init(&spawn_pos, true); + ships_[player_to_revive].init(&spawn_pos, true); // Check if other player wants to continue too if (p1_start && p2_start) { uint8_t other_player = 1; - puntuacio_per_jugador_[other_player] = 0; - vides_per_jugador_[other_player] = Defaults::Game::STARTING_LIVES; - itocado_per_jugador_[other_player] = 0.0F; + score_per_player_[other_player] = 0; + lives_per_player_[other_player] = Defaults::Game::STARTING_LIVES; + hit_timer_per_player_[other_player] = 0.0F; match_config_.jugador2_actiu = true; Vec2 spawn_pos2 = obtenir_punt_spawn(other_player); - naus_[other_player].init(&spawn_pos2, true); + ships_[other_player].init(&spawn_pos2, true); } // Resume game - estat_game_over_ = GameOverState::NONE; + game_over_state_ = GameOverState::NONE; continue_counter_ = 0; continue_tick_timer_ = 0.0F; @@ -1333,7 +1333,7 @@ void GameScene::processar_input_continue() { check_and_apply_continue_timeout(); // Play sound only if still in CONTINUE state - if (estat_game_over_ == GameOverState::CONTINUE) { + if (game_over_state_ == GameOverState::CONTINUE) { Audio::get()->playSound(Defaults::Sound::CONTINUE, Audio::Group::GAME); } @@ -1354,7 +1354,7 @@ void GameScene::dibuixar_continue() { float centre_x = play_area.x + (play_area.w / 2.0F); float centre_y_continue = play_area.y + (play_area.h * y_ratio_continue); - text_.render_centered(continue_text, {.x = centre_x, .y = centre_y_continue}, escala_continue, spacing); + text_.renderCentered(continue_text, {.x = centre_x, .y = centre_y_continue}, escala_continue, spacing); // Countdown number (using constants) const std::string counter_str = std::to_string(continue_counter_); @@ -1363,17 +1363,17 @@ void GameScene::dibuixar_continue() { float centre_y_counter = play_area.y + (play_area.h * y_ratio_counter); - text_.render_centered(counter_str, {.x = centre_x, .y = centre_y_counter}, escala_counter, spacing); + text_.renderCentered(counter_str, {.x = centre_x, .y = centre_y_counter}, escala_counter, spacing); // "CONTINUES LEFT" (conditional + using constants) if (!Defaults::Game::INFINITE_CONTINUES) { - const std::string continues_text = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_usados_); + const std::string continues_text = "CONTINUES LEFT: " + std::to_string(Defaults::Game::MAX_CONTINUES - continues_used_); float escala_info = Defaults::Game::ContinueScreen::INFO_TEXT_SCALE; float y_ratio_info = Defaults::Game::ContinueScreen::INFO_TEXT_Y_RATIO; float centre_y_info = play_area.y + (play_area.h * y_ratio_info); - text_.render_centered(continues_text, {.x = centre_x, .y = centre_y_info}, escala_info, spacing); + text_.renderCentered(continues_text, {.x = centre_x, .y = centre_y_info}, escala_info, spacing); } } @@ -1386,15 +1386,15 @@ void GameScene::unir_jugador(uint8_t player_id) { } // Reset stats - vides_per_jugador_[player_id] = Defaults::Game::STARTING_LIVES; - puntuacio_per_jugador_[player_id] = 0; - itocado_per_jugador_[player_id] = 0.0F; + lives_per_player_[player_id] = Defaults::Game::STARTING_LIVES; + score_per_player_[player_id] = 0; + hit_timer_per_player_[player_id] = 0.0F; // Spawn with invulnerability Vec2 spawn_pos = obtenir_punt_spawn(player_id); - naus_[player_id].init(&spawn_pos, true); + ships_[player_id].init(&spawn_pos, true); // No visual message, just spawn (per user requirement) - std::cout << "[GameScene] Jugador " << (int)(player_id + 1) << " s'ha unit a la partida!" << '\n'; + std::cout << "[GameScene] Jugador " << (int)(player_id + 1) << " s'ha unit a la match!" << '\n'; } diff --git a/source/game/scenes/game_scene.hpp b/source/game/scenes/game_scene.hpp index b50e3f4..0c87642 100644 --- a/source/game/scenes/game_scene.hpp +++ b/source/game/scenes/game_scene.hpp @@ -17,7 +17,7 @@ #include "core/types.hpp" #include "game/constants.hpp" #include "game/effects/debris_manager.hpp" -#include "game/effects/gestor_puntuacio_flotant.hpp" +#include "game/effects/floating_score_manager.hpp" #include "game/entities/bullet.hpp" #include "game/entities/enemy.hpp" #include "game/entities/ship.hpp" @@ -45,33 +45,33 @@ class GameScene { private: SDLManager& sdl_; SceneManager::SceneContext& context_; - GameConfig::MatchConfig match_config_; // Configuració de jugadors actius + GameConfig::MatchConfig match_config_; // Configuració de jugadors active // Efectes visuals Effects::DebrisManager debris_manager_; - Effects::GestorPuntuacioFlotant gestor_puntuacio_; + Effects::FloatingScoreManager floating_score_manager_; // Estat del joc - std::array naus_; // [0]=P1, [1]=P2 - std::array orni_; - std::array bales_; // 6 balas: P1=[0,1,2], P2=[3,4,5] - std::array itocado_per_jugador_; // Death timers per player (seconds) + std::array ships_; // [0]=P1, [1]=P2 + std::array enemies_; + std::array bullets_; // 6 balas: P1=[0,1,2], P2=[3,4,5] + std::array hit_timer_per_player_; // Death timers per player (seconds) // Lives and game over system - std::array vides_per_jugador_; // [0]=P1, [1]=P2 - GameOverState estat_game_over_; // Game over state machine (NONE, CONTINUE, GAME_OVER) + std::array lives_per_player_; // [0]=P1, [1]=P2 + GameOverState game_over_state_; // Game over state machine (NONE, CONTINUE, GAME_OVER) int continue_counter_; // Continue countdown (9→0) float continue_tick_timer_; // Timer for countdown tick (1.0s) - int continues_usados_; // Continues used this game (0-3 max) + int continues_used_; // Continues used this game (0-3 max) float game_over_timer_; // Final GAME OVER timer before title screen - Vec2 punt_mort_; // Death position (for respawn) - std::array puntuacio_per_jugador_; // [0]=P1, [1]=P2 + Vec2 death_position_; // Death position (for respawn) + std::array score_per_player_; // [0]=P1, [1]=P2 // Text vectorial Graphics::VectorText text_; // [NEW] Stage system - std::unique_ptr stage_config_; + std::unique_ptr stage_config_; std::unique_ptr stage_manager_; // Control de sons d'animació INIT_HUD @@ -79,7 +79,7 @@ class GameScene { // Funcions privades void tocado(uint8_t player_id); - void detectar_col·lisions_bales_enemics(); // Col·lisions bala-enemic + void detectar_col·lisions_bales_enemics(); // Col·lisions bullet-enemy void detectar_col·lisio_naus_enemics(); // Ship-enemy collision detection (plural) void detectar_col·lisions_bales_jugadors(); // Bullet-player collision detection (friendly fire) void dibuixar_marges() const; // Dibuixar vores de la zona de joc @@ -95,18 +95,18 @@ class GameScene { void dibuixar_continue(); // Draw continue screen // [NEW] Stage system helpers - void dibuixar_missatge_stage(const std::string& missatge); + void dibuixar_missatge_stage(const std::string& message); // [NEW] Funcions d'animació per INIT_HUD void dibuixar_marges_animat(float progress) const; // Rectangle amb creixement uniforme void dibuixar_marcador_animat(float progress); // Marcador que puja des de baix - [[nodiscard]] Vec2 calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const; // Posició animada de la nau + [[nodiscard]] Vec2 calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const; // Posició animada de la ship // [NEW] Función helper del sistema de animación INIT_HUD [[nodiscard]] float calcular_progress_rango(float global_progress, float ratio_init, float ratio_end) const; // [NEW] Funció helper del marcador - [[nodiscard]] std::string construir_marcador() const; + [[nodiscard]] std::string buildScoreboard() const; }; #endif // ESCENA_JOC_HPP diff --git a/source/game/scenes/logo_scene.cpp b/source/game/scenes/logo_scene.cpp index 9b97979..a91098e 100644 --- a/source/game/scenes/logo_scene.cpp +++ b/source/game/scenes/logo_scene.cpp @@ -29,7 +29,7 @@ static float calcular_progress_letra(size_t letra_index, size_t num_letras, floa return 1.0F; } - // Calcular temps per lletra + // Calcular time per lletra float duration_per_letra = 1.0F / static_cast(num_letras); float step = threshold * duration_per_letra; float start = static_cast(letra_index) * step; @@ -50,7 +50,7 @@ LogoScene::LogoScene(SDLManager& sdl, SceneContext& context) context_(context), estat_actual_(AnimationState::PRE_ANIMATION), temps_estat_actual_(0.0F), - debris_manager_(std::make_unique(sdl.obte_renderer())), + debris_manager_(std::make_unique(sdl.getRenderer())), lletra_explosio_index_(0), temps_des_ultima_explosio_(0.0F) { std::cout << "SceneType Logo: Inicialitzant...\n"; @@ -113,7 +113,7 @@ void LogoScene::run() { // Actualitzar colors oscil·lats (efecte verd global) sdl_.updateColors(delta_time); - // Actualitzar context de renderitzat (factor d'escala global) + // Actualitzar context de renderitzat (factor d'scale global) sdl_.updateRenderingContext(); // Dibuixar @@ -142,20 +142,20 @@ void LogoScene::inicialitzar_lletres() { float ancho_total = 0.0F; for (const auto& fitxer : fitxers) { - auto forma = ShapeLoader::load(fitxer); - if (!forma || !forma->es_valida()) { + auto shape = ShapeLoader::load(fitxer); + if (!shape || !shape->isValid()) { std::cerr << "[LogoScene] Error carregant " << fitxer << '\n'; continue; } - // Calcular bounding box de la forma (trobar ancho) + // Calcular bounding box de la shape (trobar ancho) float min_x = FLT_MAX; float max_x = -FLT_MAX; - for (const auto& prim : forma->get_primitives()) { - for (const auto& punt : prim.points) { - min_x = std::min(min_x, punt.x); - max_x = std::max(max_x, punt.x); + for (const auto& prim : shape->get_primitives()) { + for (const auto& point : prim.points) { + min_x = std::min(min_x, point.x); + max_x = std::max(max_x, point.x); } } @@ -164,9 +164,9 @@ void LogoScene::inicialitzar_lletres() { // IMPORTANT: Escalar ancho i offset amb ESCALA_FINAL // per que les posicions finals coincideixin amb la mida real de les lletres float ancho = ancho_sin_escalar * ESCALA_FINAL; - float offset_centre = (forma->getCenter().x - min_x) * ESCALA_FINAL; + float offset_centre = (shape->getCenter().x - min_x) * ESCALA_FINAL; - lletres_.push_back({forma, + lletres_.push_back({shape, {.x = 0.0F, .y = 0.0F}, // Posició es calcularà després ancho, offset_centre}); @@ -188,11 +188,11 @@ void LogoScene::inicialitzar_lletres() { float x_actual = x_inicial; for (auto& lletra : lletres_) { - // Posicionar el centre de la forma (shape_centre) en pantalla + // Posicionar el centre de la shape (shape_centre) en pantalla // Usar offset_centre en lloc de ancho/2 perquè shape_centre // pot no estar exactament al mig del bounding box - lletra.posicio.x = x_actual + lletra.offset_centre; - lletra.posicio.y = y_centre; + lletra.position.x = x_actual + lletra.offset_centre; + lletra.position.y = y_centre; // Avançar per a següent lletra x_actual += lletra.ancho + ESPAI_ENTRE_LLETRES; @@ -204,9 +204,9 @@ void LogoScene::inicialitzar_lletres() { void LogoScene::canviar_estat(AnimationState nou_estat) { estat_actual_ = nou_estat; - temps_estat_actual_ = 0.0F; // Reset temps + temps_estat_actual_ = 0.0F; // Reset time - // Inicialitzar estat d'explosió + // Inicialitzar state d'explosió if (nou_estat == AnimationState::EXPLOSION) { lletra_explosio_index_ = 0; temps_des_ultima_explosio_ = 0.0F; @@ -223,7 +223,7 @@ void LogoScene::canviar_estat(AnimationState nou_estat) { Audio::get()->playMusic("title.ogg"); } - std::cout << "[LogoScene] Canvi a estat: " << static_cast(nou_estat) + std::cout << "[LogoScene] Canvi a state: " << static_cast(nou_estat) << "\n"; } @@ -235,21 +235,21 @@ bool LogoScene::totes_lletres_completes() const { void LogoScene::actualitzar_explosions(float delta_time) { temps_des_ultima_explosio_ += delta_time; - // Comprovar si és el moment d'explotar la següent lletra + // Comprovar si és el moment d'explode la següent lletra if (temps_des_ultima_explosio_ >= DELAY_ENTRE_EXPLOSIONS) { if (lletra_explosio_index_ < lletres_.size()) { // Explotar lletra actual (en ordre aleatori) size_t index_actual = ordre_explosio_[lletra_explosio_index_]; const auto& lletra = lletres_[index_actual]; - debris_manager_->explotar( - lletra.forma, // Forma a explotar - lletra.posicio, // Posició + debris_manager_->explode( + lletra.shape, // Forma a explode + lletra.position, // Posició 0.0F, // Angle (sense rotació) - ESCALA_FINAL, // Escala (lletres a escala final) + ESCALA_FINAL, // Escala (lletres a scale final) VELOCITAT_EXPLOSIO, // Velocitat base 1.0F, // Brightness màxim (per defecte) - {.x = 0.0F, .y = 0.0F} // Sense velocitat (per defecte) + {.x = 0.0F, .y = 0.0F} // Sense velocity (per defecte) ); std::cout << "[LogoScene] Explota lletra " << lletra_explosio_index_ << "\n"; @@ -364,21 +364,21 @@ void LogoScene::draw() { Vec2 pos_actual; pos_actual.x = - ORIGEN_ZOOM.x + ((lletra.posicio.x - ORIGEN_ZOOM.x) * letra_progress); + ORIGEN_ZOOM.x + ((lletra.position.x - ORIGEN_ZOOM.x) * letra_progress); pos_actual.y = - ORIGEN_ZOOM.y + ((lletra.posicio.y - ORIGEN_ZOOM.y) * letra_progress); + ORIGEN_ZOOM.y + ((lletra.position.y - ORIGEN_ZOOM.y) * letra_progress); float t = letra_progress; float ease_factor = 1.0F - ((1.0F - t) * (1.0F - t)); - float escala_actual = + float current_scale = ESCALA_INICIAL + ((ESCALA_FINAL - ESCALA_INICIAL) * ease_factor); Rendering::render_shape( - sdl_.obte_renderer(), - lletra.forma, + sdl_.getRenderer(), + lletra.shape, pos_actual, 0.0F, - escala_actual, + current_scale, 1.0F); } } @@ -397,9 +397,9 @@ void LogoScene::draw() { const auto& lletra = lletres_[i]; Rendering::render_shape( - sdl_.obte_renderer(), - lletra.forma, - lletra.posicio, + sdl_.getRenderer(), + lletra.shape, + lletra.position, 0.0F, ESCALA_FINAL, 1.0F); @@ -409,7 +409,7 @@ void LogoScene::draw() { // POST_EXPLOSION: No draw lletres, només debris (a baix) - // Sempre draw debris (si n'hi ha d'actius) + // Sempre draw debris (si n'hi ha d'active) debris_manager_->draw(); sdl_.presenta(); diff --git a/source/game/scenes/logo_scene.hpp b/source/game/scenes/logo_scene.hpp index 9195753..addbf76 100644 --- a/source/game/scenes/logo_scene.hpp +++ b/source/game/scenes/logo_scene.hpp @@ -38,20 +38,20 @@ class LogoScene { SceneManager::SceneContext& context_; AnimationState estat_actual_; // Estat actual de la màquina float - temps_estat_actual_; // Temps en l'estat actual (reset en cada transició) + temps_estat_actual_; // Temps en l'state actual (reset en cada transició) // Gestor de fragments d'explosions std::unique_ptr debris_manager_; // Seguiment d'explosions seqüencials - size_t lletra_explosio_index_; // Índex de la següent lletra a explotar + size_t lletra_explosio_index_; // Índex de la següent lletra a explode float temps_des_ultima_explosio_; // Temps des de l'última explosió std::vector ordre_explosio_; // Ordre aleatori d'índexs de lletres // Estructura per a cada lletra del logo struct LetraLogo { - std::shared_ptr forma; - Vec2 posicio; // Posició final en pantalla + std::shared_ptr shape; + Vec2 position; // Posició final en pantalla float ancho; // Ancho del bounding box float offset_centre; // Distància de min_x a shape_centre.x }; diff --git a/source/game/scenes/title_scene.cpp b/source/game/scenes/title_scene.cpp index 77b315f..c1594eb 100644 --- a/source/game/scenes/title_scene.cpp +++ b/source/game/scenes/title_scene.cpp @@ -27,7 +27,7 @@ using Option = SceneContext::Option; TitleScene::TitleScene(SDLManager& sdl, SceneContext& context) : sdl_(sdl), context_(context), - text_(sdl.obte_renderer()), + text_(sdl.getRenderer()), estat_actual_(TitleState::STARFIELD_FADE_IN), temps_acumulat_(0.0F), temps_animacio_(0.0F), @@ -36,7 +36,7 @@ TitleScene::TitleScene(SDLManager& sdl, SceneContext& context) factor_lerp_(0.0F) { std::cout << "SceneType Titol: Inicialitzant...\n"; - // Inicialitzar configuració de partida (cap jugador actiu per defecte) + // Inicialitzar configuració de match (cap player active per defecte) match_config_.jugador1_actiu = false; match_config_.jugador2_actiu = false; match_config_.mode = GameConfig::Mode::NORMAL; @@ -62,7 +62,7 @@ TitleScene::TitleScene(SDLManager& sdl, SceneContext& context) static_cast(Defaults::Game::HEIGHT)}; starfield_ = std::make_unique( - sdl_.obte_renderer(), + sdl_.getRenderer(), centre_pantalla, area_completa, 150 // densitat: 150 estrelles (50 per capa) @@ -78,7 +78,7 @@ TitleScene::TitleScene(SDLManager& sdl, SceneContext& context) } // Inicialitzar animador de naus 3D - ship_animator_ = std::make_unique(sdl_.obte_renderer()); + ship_animator_ = std::make_unique(sdl_.getRenderer()); ship_animator_->init(); if (estat_actual_ == TitleState::MAIN) { @@ -118,24 +118,24 @@ void TitleScene::inicialitzar_titol() { float ancho_total_orni = 0.0F; for (const auto& fitxer : fitxers_orni) { - auto forma = ShapeLoader::load(fitxer); - if (!forma || !forma->es_valida()) { + auto shape = ShapeLoader::load(fitxer); + if (!shape || !shape->isValid()) { std::cerr << "[TitleScene] Error carregant " << fitxer << '\n'; continue; } - // Calcular bounding box de la forma (trobar ancho i altura) + // Calcular bounding box de la shape (trobar ancho i altura) float min_x = FLT_MAX; float max_x = -FLT_MAX; float min_y = FLT_MAX; float max_y = -FLT_MAX; - for (const auto& prim : forma->get_primitives()) { - for (const auto& punt : prim.points) { - min_x = std::min(min_x, punt.x); - max_x = std::max(max_x, punt.x); - min_y = std::min(min_y, punt.y); - max_y = std::max(max_y, punt.y); + for (const auto& prim : shape->get_primitives()) { + for (const auto& point : prim.points) { + min_x = std::min(min_x, point.x); + max_x = std::max(max_x, point.x); + min_y = std::min(min_y, point.y); + max_y = std::max(max_y, point.y); } } @@ -145,9 +145,9 @@ void TitleScene::inicialitzar_titol() { // Escalar ancho, altura i offset amb LOGO_SCALE float ancho = ancho_sin_escalar * Defaults::Title::Layout::LOGO_SCALE; float altura = altura_sin_escalar * Defaults::Title::Layout::LOGO_SCALE; - float offset_centre = (forma->getCenter().x - min_x) * Defaults::Title::Layout::LOGO_SCALE; + float offset_centre = (shape->getCenter().x - min_x) * Defaults::Title::Layout::LOGO_SCALE; - lletres_orni_.push_back({forma, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre}); + lletres_orni_.push_back({shape, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre}); ancho_total_orni += ancho; } @@ -160,8 +160,8 @@ void TitleScene::inicialitzar_titol() { float x_actual = x_inicial_orni; for (auto& lletra : lletres_orni_) { - lletra.posicio.x = x_actual + lletra.offset_centre; - lletra.posicio.y = Defaults::Game::HEIGHT * Defaults::Title::Layout::LOGO_POS; + lletra.position.x = x_actual + lletra.offset_centre; + lletra.position.y = Defaults::Game::HEIGHT * Defaults::Title::Layout::LOGO_POS; x_actual += lletra.ancho + ESPAI_ENTRE_LLETRES; } @@ -192,24 +192,24 @@ void TitleScene::inicialitzar_titol() { float ancho_total_attack = 0.0F; for (const auto& fitxer : fitxers_attack) { - auto forma = ShapeLoader::load(fitxer); - if (!forma || !forma->es_valida()) { + auto shape = ShapeLoader::load(fitxer); + if (!shape || !shape->isValid()) { std::cerr << "[TitleScene] Error carregant " << fitxer << '\n'; continue; } - // Calcular bounding box de la forma (trobar ancho i altura) + // Calcular bounding box de la shape (trobar ancho i altura) float min_x = FLT_MAX; float max_x = -FLT_MAX; float min_y = FLT_MAX; float max_y = -FLT_MAX; - for (const auto& prim : forma->get_primitives()) { - for (const auto& punt : prim.points) { - min_x = std::min(min_x, punt.x); - max_x = std::max(max_x, punt.x); - min_y = std::min(min_y, punt.y); - max_y = std::max(max_y, punt.y); + for (const auto& prim : shape->get_primitives()) { + for (const auto& point : prim.points) { + min_x = std::min(min_x, point.x); + max_x = std::max(max_x, point.x); + min_y = std::min(min_y, point.y); + max_y = std::max(max_y, point.y); } } @@ -219,9 +219,9 @@ void TitleScene::inicialitzar_titol() { // Escalar ancho, altura i offset amb LOGO_SCALE float ancho = ancho_sin_escalar * Defaults::Title::Layout::LOGO_SCALE; float altura = altura_sin_escalar * Defaults::Title::Layout::LOGO_SCALE; - float offset_centre = (forma->getCenter().x - min_x) * Defaults::Title::Layout::LOGO_SCALE; + float offset_centre = (shape->getCenter().x - min_x) * Defaults::Title::Layout::LOGO_SCALE; - lletres_attack_.push_back({forma, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre}); + lletres_attack_.push_back({shape, {.x = 0.0F, .y = 0.0F}, ancho, altura, offset_centre}); ancho_total_attack += ancho; } @@ -234,8 +234,8 @@ void TitleScene::inicialitzar_titol() { x_actual = x_inicial_attack; for (auto& lletra : lletres_attack_) { - lletra.posicio.x = x_actual + lletra.offset_centre; - lletra.posicio.y = y_attack_dinamica_; // Usar posició dinàmica + lletra.position.x = x_actual + lletra.offset_centre; + lletra.position.y = y_attack_dinamica_; // Usar posició dinàmica x_actual += lletra.ancho + ESPAI_ENTRE_LLETRES; } @@ -245,12 +245,12 @@ void TitleScene::inicialitzar_titol() { // Guardar posicions originals per l'animació orbital posicions_originals_orni_.clear(); for (const auto& lletra : lletres_orni_) { - posicions_originals_orni_.push_back(lletra.posicio); + posicions_originals_orni_.push_back(lletra.position); } posicions_originals_attack_.clear(); for (const auto& lletra : lletres_attack_) { - posicions_originals_attack_.push_back(lletra.posicio); + posicions_originals_attack_.push_back(lletra.position); } std::cout << "[TitleScene] Animació: Posicions originals guardades\n"; @@ -306,7 +306,7 @@ void TitleScene::run() { // Netejar pantalla sdl_.neteja(0, 0, 0); - // Actualitzar context de renderitzat (factor d'escala global) + // Actualitzar context de renderitzat (factor d'scale global) sdl_.updateRenderingContext(); // Dibuixar @@ -320,7 +320,7 @@ void TitleScene::run() { } void TitleScene::update(float delta_time) { - // Actualitzar starfield (sempre actiu) + // Actualitzar starfield (sempre active) if (starfield_) { starfield_->update(delta_time); } @@ -348,7 +348,7 @@ void TitleScene::update(float delta_time) { // Transició a STARFIELD quan el fade es completa if (temps_acumulat_ >= DURACIO_FADE_IN) { estat_actual_ = TitleState::STARFIELD; - temps_acumulat_ = 0.0F; // Reset timer per al següent estat + temps_acumulat_ = 0.0F; // Reset timer per al següent state starfield_->set_brightness(BRIGHTNESS_STARFIELD); // Assegurar valor final } break; @@ -405,7 +405,7 @@ void TitleScene::update(float delta_time) { // Continuar animació orbital durant la transició actualitzar_animacio_logo(delta_time); - // [NOU] Continuar comprovant si l'altre jugador vol unir-se durant la transició ("late join") + // [NOU] Continuar comprovant si l'altre player vol unir-se durant la transició ("late join") { bool p1_actiu_abans = match_config_.jugador1_actiu; bool p2_actiu_abans = match_config_.jugador2_actiu; @@ -414,7 +414,7 @@ void TitleScene::update(float delta_time) { // Updates match_config_ if pressed, logs are in the method context_.setMatchConfig(match_config_); - // Trigger animació de sortida per la nau que acaba d'unir-se + // Trigger animació de sortida per la ship que acaba d'unir-se if (ship_animator_) { if (match_config_.jugador1_actiu && !p1_actiu_abans) { ship_animator_->trigger_exit_animation_for_player(1); @@ -426,13 +426,13 @@ void TitleScene::update(float delta_time) { } } - // Reproducir so de START quan el segon jugador s'uneix + // Reproducir so de START quan el segon player s'uneix Audio::get()->playSound(Defaults::Sound::START, Audio::Group::GAME); - // Reiniciar el timer per allargar el temps de transició + // Reiniciar el timer per allargar el time de transició temps_acumulat_ = 0.0F; - std::cout << "[TitleScene] Segon jugador s'ha unit - so i timer reiniciats\n"; + std::cout << "[TitleScene] Segon player s'ha unit - so i timer reiniciats\n"; } } @@ -468,9 +468,9 @@ void TitleScene::update(float delta_time) { } } - // Verificar boton START para iniciar partida desde MAIN + // Verificar boton START para iniciar match desde MAIN if (estat_actual_ == TitleState::MAIN) { - // Guardar estat anterior per detectar qui ha premut START AQUEST frame + // Guardar state anterior per detectar qui ha premut START AQUEST frame bool p1_actiu_abans = match_config_.jugador1_actiu; bool p2_actiu_abans = match_config_.jugador2_actiu; @@ -481,9 +481,9 @@ void TitleScene::update(float delta_time) { ship_animator_->skip_to_floating_state(); } - // Configurar partida abans de canviar d'escena + // Configurar match abans de canviar d'escena context_.setMatchConfig(match_config_); - std::cout << "[TitleScene] Configuració de partida - P1: " + std::cout << "[TitleScene] Configuració de match - P1: " << (match_config_.jugador1_actiu ? "ACTIU" : "INACTIU") << ", P2: " << (match_config_.jugador2_actiu ? "ACTIU" : "INACTIU") @@ -514,7 +514,7 @@ void TitleScene::update(float delta_time) { void TitleScene::actualitzar_animacio_logo(float delta_time) { // Només calcular i aplicar offsets si l'animació està activa if (animacio_activa_) { - // Acumular temps escalat + // Acumular time escalat temps_animacio_ += delta_time * factor_lerp_; // Usar amplituds i freqüències completes @@ -529,14 +529,14 @@ void TitleScene::actualitzar_animacio_logo(float delta_time) { // Aplicar offset a totes les lletres de "ORNI" for (size_t i = 0; i < lletres_orni_.size(); ++i) { - lletres_orni_[i].posicio.x = posicions_originals_orni_[i].x + static_cast(std::round(offset_x)); - lletres_orni_[i].posicio.y = posicions_originals_orni_[i].y + static_cast(std::round(offset_y)); + lletres_orni_[i].position.x = posicions_originals_orni_[i].x + static_cast(std::round(offset_x)); + lletres_orni_[i].position.y = posicions_originals_orni_[i].y + static_cast(std::round(offset_y)); } // Aplicar offset a totes les lletres de "ATTACK!" for (size_t i = 0; i < lletres_attack_.size(); ++i) { - lletres_attack_[i].posicio.x = posicions_originals_attack_[i].x + static_cast(std::round(offset_x)); - lletres_attack_[i].posicio.y = posicions_originals_attack_[i].y + static_cast(std::round(offset_y)); + lletres_attack_[i].position.x = posicions_originals_attack_[i].x + static_cast(std::round(offset_x)); + lletres_attack_[i].position.y = posicions_originals_attack_[i].y + static_cast(std::round(offset_y)); } } } @@ -567,7 +567,7 @@ void TitleScene::draw() { // === Calcular i renderitzar ombra (només si animació activa) === if (animacio_activa_) { float temps_shadow = temps_animacio_ - SHADOW_DELAY; - temps_shadow = std::max(temps_shadow, 0.0F); // Evitar temps negatiu + temps_shadow = std::max(temps_shadow, 0.0F); // Evitar time negatiu // Usar amplituds i freqüències completes per l'ombra float amplitude_x_shadow = ORBIT_AMPLITUDE_X; @@ -588,13 +588,13 @@ void TitleScene::draw() { pos_shadow.y = posicions_originals_orni_[i].y + static_cast(std::round(shadow_offset_y)); Rendering::render_shape( - sdl_.obte_renderer(), - lletres_orni_[i].forma, + sdl_.getRenderer(), + lletres_orni_[i].shape, pos_shadow, 0.0F, Defaults::Title::Layout::LOGO_SCALE, 1.0F, // progress = 1.0 (totalment visible) - SHADOW_BRIGHTNESS // brightness = 0.4 (brillantor reduïda) + SHADOW_BRIGHTNESS // brightness = 0.4 (brightness reduïda) ); } @@ -605,8 +605,8 @@ void TitleScene::draw() { pos_shadow.y = posicions_originals_attack_[i].y + static_cast(std::round(shadow_offset_y)); Rendering::render_shape( - sdl_.obte_renderer(), - lletres_attack_[i].forma, + sdl_.getRenderer(), + lletres_attack_[i].shape, pos_shadow, 0.0F, Defaults::Title::Layout::LOGO_SCALE, @@ -620,9 +620,9 @@ void TitleScene::draw() { // Dibuixar "ORNI" (línia 1) for (const auto& lletra : lletres_orni_) { Rendering::render_shape( - sdl_.obte_renderer(), - lletra.forma, - lletra.posicio, + sdl_.getRenderer(), + lletra.shape, + lletra.position, 0.0F, Defaults::Title::Layout::LOGO_SCALE, 1.0F // Brillantor completa @@ -632,9 +632,9 @@ void TitleScene::draw() { // Dibuixar "ATTACK!" (línia 2) for (const auto& lletra : lletres_attack_) { Rendering::render_shape( - sdl_.obte_renderer(), - lletra.forma, - lletra.posicio, + sdl_.getRenderer(), + lletra.shape, + lletra.position, 0.0F, Defaults::Title::Layout::LOGO_SCALE, 1.0F // Brillantor completa @@ -642,15 +642,15 @@ void TitleScene::draw() { } // === Text "PRESS START TO PLAY" === - // En estat MAIN: sempre visible - // En estat TRANSITION: parpellejant (blink amb sinusoide) + // En state MAIN: sempre visible + // En state TRANSITION: parpellejant (blink amb sinusoide) const float spacing = Defaults::Title::Layout::TEXT_SPACING; bool mostrar_text = true; if (estat_actual_ == TitleState::PLAYER_JOIN_PHASE) { // Parpelleig: sin oscil·la entre -1 i 1, volem ON quan > 0 - float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0F * std::numbers::pi_v; // 2π × freq × temps + float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0F * std::numbers::pi_v; // 2π × freq × time mostrar_text = (std::sin(fase) > 0.0F); } @@ -661,7 +661,7 @@ void TitleScene::draw() { float centre_x = Defaults::Game::WIDTH / 2.0F; float centre_y = Defaults::Game::HEIGHT * Defaults::Title::Layout::PRESS_START_POS; - text_.render_centered(main_text, {.x = centre_x, .y = centre_y}, escala_main, spacing); + text_.renderCentered(main_text, {.x = centre_x, .y = centre_y}, escala_main, spacing); } // === Copyright a la part inferior (centrat horitzontalment, dues línies) === @@ -692,8 +692,8 @@ void TitleScene::draw() { // Renderitzar línees centrades float centre_x = Defaults::Game::WIDTH / 2.0F; - text_.render_centered(copyright_original, {.x = centre_x, .y = y_line1}, escala_copy, spacing); - text_.render_centered(copyright_port, {.x = centre_x, .y = y_line2}, escala_copy, spacing); + text_.renderCentered(copyright_original, {.x = centre_x, .y = y_line1}, escala_copy, spacing); + text_.renderCentered(copyright_port, {.x = centre_x, .y = y_line2}, escala_copy, spacing); } } diff --git a/source/game/scenes/title_scene.hpp b/source/game/scenes/title_scene.hpp index 82c1271..47194f3 100644 --- a/source/game/scenes/title_scene.hpp +++ b/source/game/scenes/title_scene.hpp @@ -1,5 +1,5 @@ // escena_titol.hpp - Pantalla de títol del joc -// Mostra missatge "PRESS BUTTON TO PLAY" i copyright +// Mostra message "PRESS BUTTON TO PLAY" i copyright // © 2025 Port a C++20 #pragma once @@ -43,8 +43,8 @@ class TitleScene { // Estructura per emmagatzemar informació de cada lletra del títol struct LetraLogo { - std::shared_ptr forma; // Forma vectorial de la lletra - Vec2 posicio; // Posició en pantalla + std::shared_ptr shape; // Forma vectorial de la lletra + Vec2 position; // Posició en pantalla float ancho; // Amplada escalada float altura; // Altura escalada float offset_centre; // Offset del centre per posicionament @@ -52,12 +52,12 @@ class TitleScene { SDLManager& sdl_; SceneManager::SceneContext& context_; - GameConfig::MatchConfig match_config_; // Configuració de jugadors actius + GameConfig::MatchConfig match_config_; // Configuració de jugadors active Graphics::VectorText text_; // Sistema de text vectorial std::unique_ptr starfield_; // Camp d'estrelles de fons std::unique_ptr ship_animator_; // Naus 3D flotants TitleState estat_actual_; // Estat actual de la màquina - float temps_acumulat_; // Temps acumulat per l'estat INIT + float temps_acumulat_; // Temps acumulat per l'state INIT // Lletres del títol "ORNI ATTACK!" std::vector lletres_orni_; // Lletres de "ORNI" (línia 1) @@ -70,14 +70,14 @@ class TitleScene { std::vector posicions_originals_attack_; // Posicions originals de "ATTACK!" // Estat d'arrencada de l'animació - float temps_estat_main_; // Temps acumulat en estat MAIN + float temps_estat_main_; // Temps acumulat en state MAIN bool animacio_activa_; // Flag: true quan animació està activa float factor_lerp_; // Factor de lerp actual (0.0 → 1.0) // Constants static constexpr float BRIGHTNESS_STARFIELD = 1.2F; // Brightness del starfield (>1.0 = més brillant) static constexpr float DURACIO_FADE_IN = 3.0F; // Duració del fade-in del starfield (1.5 segons) - static constexpr float DURACIO_INIT = 4.0F; // Duració de l'estat INIT (2 segons) + static constexpr float DURACIO_INIT = 4.0F; // Duració de l'state INIT (2 segons) static constexpr float DURACIO_TRANSITION = 2.5F; // Duració de la transició (1.5 segons) static constexpr float ESPAI_ENTRE_LLETRES = 10.0F; // Espai entre lletres static constexpr float BLINK_FREQUENCY = 3.0F; // Freqüència de parpelleig (3 Hz) @@ -93,7 +93,7 @@ class TitleScene { // Constants d'ombra del logo static constexpr float SHADOW_DELAY = 0.5F; // Retard temporal de l'ombra (segons) - static constexpr float SHADOW_BRIGHTNESS = 0.4F; // Multiplicador de brillantor de l'ombra (0.0-1.0) + static constexpr float SHADOW_BRIGHTNESS = 0.4F; // Multiplicador de brightness de l'ombra (0.0-1.0) static constexpr float SHADOW_OFFSET_X = 2.0F; // Offset espacial X fix (píxels) static constexpr float SHADOW_OFFSET_Y = 2.0F; // Offset espacial Y fix (píxels) diff --git a/source/game/stage_system/spawn_controller.cpp b/source/game/stage_system/spawn_controller.cpp index 844f053..ad654b1 100644 --- a/source/game/stage_system/spawn_controller.cpp +++ b/source/game/stage_system/spawn_controller.cpp @@ -21,7 +21,7 @@ SpawnController::SpawnController() index_spawn_actual_(0), ship_position_(nullptr) {} -void SpawnController::configurar(const ConfigStage* config) { +void SpawnController::configurar(const StageConfig* config) { config_ = config; } @@ -65,9 +65,9 @@ void SpawnController::update(float delta_time, std::array& orni_array if (temps_transcorregut_ >= event.temps_spawn) { // Find first inactive enemy - for (auto& enemic : orni_array) { - if (!enemic.isActive()) { - spawn_enemic(enemic, event.tipus, ship_position_); + for (auto& enemy : orni_array) { + if (!enemy.isActive()) { + spawn_enemic(enemy, event.type, ship_position_); event.spawnejat = true; index_spawn_actual_++; break; @@ -94,8 +94,8 @@ bool SpawnController::tots_enemics_destruits(const std::array& orni_a return false; } - for (const auto& enemic : orni_array) { - if (enemic.isActive()) { + for (const auto& enemy : orni_array) { + if (enemy.isActive()) { return false; } } @@ -105,8 +105,8 @@ bool SpawnController::tots_enemics_destruits(const std::array& orni_a uint8_t SpawnController::get_enemics_vius(const std::array& orni_array) const { uint8_t count = 0; - for (const auto& enemic : orni_array) { - if (enemic.isActive()) { + for (const auto& enemy : orni_array) { + if (enemy.isActive()) { count++; } } @@ -126,9 +126,9 @@ void SpawnController::generar_spawn_events() { float spawn_time = config_->config_spawn.delay_inicial + (i * config_->config_spawn.interval_spawn); - EnemyType tipus = seleccionar_tipus_aleatori(); + EnemyType type = seleccionar_tipus_aleatori(); - spawn_queue_.push_back({spawn_time, tipus, false}); + spawn_queue_.push_back({spawn_time, type, false}); } } @@ -149,29 +149,29 @@ EnemyType SpawnController::seleccionar_tipus_aleatori() const { return EnemyType::MOLINILLO; } -void SpawnController::spawn_enemic(Enemy& enemic, EnemyType tipus, const Vec2* ship_pos) { +void SpawnController::spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos) { // Initialize enemy (with safe spawn if ship_pos provided) - enemic.init(tipus, ship_pos); + enemy.init(type, ship_pos); // Apply difficulty multipliers - aplicar_multiplicadors(enemic); + aplicar_multiplicadors(enemy); } -void SpawnController::aplicar_multiplicadors(Enemy& enemic) const { +void SpawnController::aplicar_multiplicadors(Enemy& enemy) const { if (config_ == nullptr) { return; } // Apply velocity multiplier - float base_vel = enemic.get_base_velocity(); - enemic.set_velocity(base_vel * config_->multiplicadors.velocitat); + float base_vel = enemy.get_base_velocity(); + enemy.set_velocity(base_vel * config_->multiplicadors.velocity); // Apply rotation multiplier - float base_rot = enemic.get_base_rotation(); - enemic.set_rotation(base_rot * config_->multiplicadors.rotacio); + float base_rot = enemy.get_base_rotation(); + enemy.set_rotation(base_rot * config_->multiplicadors.rotation); // Apply tracking strength (only affects QUADRAT) - enemic.set_tracking_strength(config_->multiplicadors.tracking_strength); + enemy.set_tracking_strength(config_->multiplicadors.tracking_strength); } } // namespace StageSystem diff --git a/source/game/stage_system/spawn_controller.hpp b/source/game/stage_system/spawn_controller.hpp index f5cf23b..2f5923d 100644 --- a/source/game/stage_system/spawn_controller.hpp +++ b/source/game/stage_system/spawn_controller.hpp @@ -16,7 +16,7 @@ namespace StageSystem { // Informació de spawn planificat struct SpawnEvent { float temps_spawn; // Temps absolut (segons) per spawnejar - EnemyType tipus; // Tipus d'enemic + EnemyType type; // Tipus d'enemy bool spawnejat; // Ja s'ha processat? }; @@ -25,7 +25,7 @@ class SpawnController { SpawnController(); // Configuration - void configurar(const ConfigStage* config); // Set stage config + void configurar(const StageConfig* config); // Set stage config void iniciar(); // Generate spawn schedule void reset(); // Clear all pending spawns @@ -42,7 +42,7 @@ class SpawnController { void set_ship_position(const Vec2* ship_pos) { ship_position_ = ship_pos; } private: - const ConfigStage* config_; // Non-owning pointer to current stage config + const StageConfig* config_; // Non-owning pointer to current stage config std::vector spawn_queue_; float temps_transcorregut_; // Elapsed time since stage start uint8_t index_spawn_actual_; // Next spawn to process @@ -50,8 +50,8 @@ class SpawnController { // Spawn generation void generar_spawn_events(); [[nodiscard]] EnemyType seleccionar_tipus_aleatori() const; - void spawn_enemic(Enemy& enemic, EnemyType tipus, const Vec2* ship_pos = nullptr); - void aplicar_multiplicadors(Enemy& enemic) const; + void spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos = nullptr); + void aplicar_multiplicadors(Enemy& enemy) const; const Vec2* ship_position_; // [NEW] Non-owning pointer to ship position }; diff --git a/source/game/stage_system/stage_config.hpp b/source/game/stage_system/stage_config.hpp index ff41e34..9e347c6 100644 --- a/source/game/stage_system/stage_config.hpp +++ b/source/game/stage_system/stage_config.hpp @@ -24,7 +24,7 @@ struct ConfigSpawn { float interval_spawn; // Segons entre spawns consecutius }; -// Distribució de tipus d'enemics (percentatges) +// Distribució de type d'enemics (percentatges) struct DistribucioEnemics { uint8_t pentagon; // 0-100 uint8_t quadrat; // 0-100 @@ -34,8 +34,8 @@ struct DistribucioEnemics { // Multiplicadors de dificultat struct MultiplicadorsDificultat { - float velocitat; // 0.5-2.0 típic - float rotacio; // 0.5-2.0 típic + float velocity; // 0.5-2.0 típic + float rotation; // 0.5-2.0 típic float tracking_strength; // 0.0-1.5 (aplicat a Quadrat) }; @@ -47,7 +47,7 @@ struct MetadataStages { }; // Configuració completa d'un stage -struct ConfigStage { +struct StageConfig { uint8_t stage_id; // 1-10 uint8_t total_enemics; // 5-15 ConfigSpawn config_spawn; @@ -63,12 +63,12 @@ struct ConfigStage { }; // Configuració completa del sistema (carregada des de YAML) -struct ConfigSistemaStages { +struct StageSystemConfig { MetadataStages metadata; - std::vector stages; // Índex [0] = stage 1 + std::vector stages; // Índex [0] = stage 1 // Obtenir configuració d'un stage específic - [[nodiscard]] const ConfigStage* obte_stage(uint8_t stage_id) const { + [[nodiscard]] const StageConfig* obte_stage(uint8_t stage_id) const { if (stage_id < 1 || stage_id > stages.size()) { return nullptr; } diff --git a/source/game/stage_system/stage_loader.cpp b/source/game/stage_system/stage_loader.cpp index d1046f3..b233028 100644 --- a/source/game/stage_system/stage_loader.cpp +++ b/source/game/stage_system/stage_loader.cpp @@ -19,7 +19,7 @@ namespace StageSystem { -std::unique_ptr StageLoader::carregar(const std::string& path) { +std::unique_ptr StageLoader::load(const std::string& path) { try { // Normalize path: "data/stages/stages.yaml" → "stages/stages.yaml" std::string normalized = path; @@ -30,7 +30,7 @@ std::unique_ptr StageLoader::carregar(const std::string& pa // Load from resource system std::vector data = Resource::Helper::loadFile(normalized); if (data.empty()) { - std::cerr << "[StageLoader] Error: no es pot carregar " << normalized << '\n'; + std::cerr << "[StageLoader] Error: no es pot load " << normalized << '\n'; return nullptr; } @@ -40,7 +40,7 @@ std::unique_ptr StageLoader::carregar(const std::string& pa // Parse YAML fkyaml::node yaml = fkyaml::node::deserialize(stream); - auto config = std::make_unique(); + auto config = std::make_unique(); // Parse metadata if (!yaml.contains("metadata")) { @@ -63,7 +63,7 @@ std::unique_ptr StageLoader::carregar(const std::string& pa } for (const auto& stage_yaml : yaml["stages"]) { - ConfigStage stage; + StageConfig stage; if (!parse_stage(stage_yaml, stage)) { return nullptr; } @@ -105,7 +105,7 @@ bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta) } } -bool StageLoader::parse_stage(const fkyaml::node& yaml, ConfigStage& stage) { +bool StageLoader::parse_stage(const fkyaml::node& yaml, StageConfig& stage) { try { if (!yaml.contains("stage_id") || !yaml.contains("total_enemies") || !yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") || @@ -194,15 +194,15 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi return false; } - mult.velocitat = yaml["speed_multiplier"].get_value(); - mult.rotacio = yaml["rotation_multiplier"].get_value(); + mult.velocity = yaml["speed_multiplier"].get_value(); + mult.rotation = yaml["rotation_multiplier"].get_value(); mult.tracking_strength = yaml["tracking_strength"].get_value(); // Validar rangs raonables - if (mult.velocitat < 0.1F || mult.velocitat > 5.0F) { + if (mult.velocity < 0.1F || mult.velocity > 5.0F) { std::cerr << "[StageLoader] Warning: speed_multiplier fora de rang (0.1-5.0)" << '\n'; } - if (mult.rotacio < 0.1F || mult.rotacio > 5.0F) { + if (mult.rotation < 0.1F || mult.rotation > 5.0F) { std::cerr << "[StageLoader] Warning: rotation_multiplier fora de rang (0.1-5.0)" << '\n'; } if (mult.tracking_strength < 0.0F || mult.tracking_strength > 2.0F) { @@ -231,7 +231,7 @@ ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) { return ModeSpawn::PROGRESSIVE; } -bool StageLoader::validar_config(const ConfigSistemaStages& config) { +bool StageLoader::validar_config(const StageSystemConfig& config) { if (config.stages.empty()) { std::cerr << "[StageLoader] Error: cap stage carregat" << '\n'; return false; diff --git a/source/game/stage_system/stage_loader.hpp b/source/game/stage_system/stage_loader.hpp index 61238a3..f58a0cd 100644 --- a/source/game/stage_system/stage_loader.hpp +++ b/source/game/stage_system/stage_loader.hpp @@ -15,19 +15,19 @@ class StageLoader { public: // Carregar configuració des de fitxer YAML // Retorna nullptr si hi ha errors - static std::unique_ptr carregar(const std::string& path); + static std::unique_ptr load(const std::string& path); private: // Parsing helpers (implementats en .cpp) static bool parse_metadata(const fkyaml::node& yaml, MetadataStages& meta); - static bool parse_stage(const fkyaml::node& yaml, ConfigStage& stage); + static bool parse_stage(const fkyaml::node& yaml, StageConfig& stage); static bool parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& config); static bool parse_distribution(const fkyaml::node& yaml, DistribucioEnemics& dist); static bool parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult); static ModeSpawn parse_spawn_mode(const std::string& mode_str); // Validació - static bool validar_config(const ConfigSistemaStages& config); + static bool validar_config(const StageSystemConfig& config); }; } // namespace StageSystem diff --git a/source/game/stage_system/stage_manager.cpp b/source/game/stage_system/stage_manager.cpp index 7b1bc31..2ab2bc6 100644 --- a/source/game/stage_system/stage_manager.cpp +++ b/source/game/stage_system/stage_manager.cpp @@ -14,7 +14,7 @@ namespace StageSystem { -StageManager::StageManager(const ConfigSistemaStages* config) +StageManager::StageManager(const StageSystemConfig* config) : config_(config), estat_(EstatStage::LEVEL_START), stage_actual_(1), @@ -65,7 +65,7 @@ bool StageManager::tot_completat() const { timer_transicio_ <= 0.0F; } -const ConfigStage* StageManager::get_config_actual() const { +const StageConfig* StageManager::get_config_actual() const { return config_->obte_stage(stage_actual_); } @@ -87,13 +87,13 @@ void StageManager::canviar_estat(EstatStage nou_estat) { missatge_level_start_actual_ = Constants::MISSATGES_LEVEL_START[index]; // [NOU] Iniciar música al entrar en LEVEL_START (després de INIT_HUD) - // Només si no està sonant ja (per evitar reiniciar en loops posteriors) + // Només si no està sonant ja (per evitar reset en loops posteriors) if (Audio::get()->getMusicState() != Audio::MusicState::PLAYING) { Audio::get()->playMusic("game.ogg"); } } - std::cout << "[StageManager] Canvi d'estat: "; + std::cout << "[StageManager] Canvi d'state: "; switch (nou_estat) { case EstatStage::INIT_HUD: std::cout << "INIT_HUD"; @@ -156,7 +156,7 @@ void StageManager::processar_level_completed(float delta_time) { } void StageManager::carregar_stage(uint8_t stage_id) { - const ConfigStage* stage_config = config_->obte_stage(stage_id); + const StageConfig* stage_config = config_->obte_stage(stage_id); if (stage_config == nullptr) { std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast(stage_id) << '\n'; diff --git a/source/game/stage_system/stage_manager.hpp b/source/game/stage_system/stage_manager.hpp index bcf7ee9..eb0f3f6 100644 --- a/source/game/stage_system/stage_manager.hpp +++ b/source/game/stage_system/stage_manager.hpp @@ -1,4 +1,4 @@ -// stage_manager.hpp - Gestor d'estat i progressió d'stages +// stage_manager.hpp - Gestor d'state i progressió d'stages // © 2025 Orni Attack #pragma once @@ -21,7 +21,7 @@ enum class EstatStage { class StageManager { public: - explicit StageManager(const ConfigSistemaStages* config); + explicit StageManager(const StageSystemConfig* config); // Lifecycle void init(); // Reset to stage 1 @@ -34,7 +34,7 @@ class StageManager { // Current state queries [[nodiscard]] EstatStage get_estat() const { return estat_; } [[nodiscard]] uint8_t get_stage_actual() const { return stage_actual_; } - [[nodiscard]] const ConfigStage* get_config_actual() const; + [[nodiscard]] const StageConfig* get_config_actual() const; [[nodiscard]] float get_timer_transicio() const { return timer_transicio_; } [[nodiscard]] const std::string& get_missatge_level_start() const { return missatge_level_start_actual_; } @@ -43,7 +43,7 @@ class StageManager { [[nodiscard]] const SpawnController& get_spawn_controller() const { return spawn_controller_; } private: - const ConfigSistemaStages* config_; // Non-owning pointer + const StageSystemConfig* config_; // Non-owning pointer SpawnController spawn_controller_; EstatStage estat_; diff --git a/source/game/title/ship_animator.cpp b/source/game/title/ship_animator.cpp index dff2f83..ed1909e 100644 --- a/source/game/title/ship_animator.cpp +++ b/source/game/title/ship_animator.cpp @@ -22,53 +22,53 @@ void ShipAnimator::init() { auto forma_p1 = Graphics::ShapeLoader::load("ship_perspective.shp"); // Perspectiva esquerra auto forma_p2 = Graphics::ShapeLoader::load("ship2_perspective.shp"); // Perspectiva dreta - // Configurar nau P1 - naus_[0].jugador_id = 1; - naus_[0].forma = forma_p1; - configurar_nau_p1(naus_[0]); + // Configurar ship P1 + ships_[0].player_id = 1; + ships_[0].shape = forma_p1; + configurar_nau_p1(ships_[0]); - // Configurar nau P2 - naus_[1].jugador_id = 2; - naus_[1].forma = forma_p2; - configurar_nau_p2(naus_[1]); + // Configurar ship P2 + ships_[1].player_id = 2; + ships_[1].shape = forma_p2; + configurar_nau_p2(ships_[1]); } void ShipAnimator::update(float delta_time) { - // Dispatcher segons estat de cada nau - for (auto& nau : naus_) { - if (!nau.visible) { + // Dispatcher segons state de cada ship + for (auto& ship : ships_) { + if (!ship.visible) { continue; } - switch (nau.estat) { - case EstatNau::ENTERING: - actualitzar_entering(nau, delta_time); + switch (ship.state) { + case ShipState::ENTERING: + actualitzar_entering(ship, delta_time); break; - case EstatNau::FLOATING: - actualitzar_floating(nau, delta_time); + case ShipState::FLOATING: + actualitzar_floating(ship, delta_time); break; - case EstatNau::EXITING: - actualitzar_exiting(nau, delta_time); + case ShipState::EXITING: + actualitzar_exiting(ship, delta_time); break; } } } void ShipAnimator::draw() const { - for (const auto& nau : naus_) { - if (!nau.visible) { + for (const auto& ship : ships_) { + if (!ship.visible) { continue; } - // Renderitzar nau (perspectiva ja incorporada a la forma) + // Renderitzar ship (perspectiva ja incorporada a la shape) Rendering::render_shape( renderer_, - nau.forma, - nau.posicio_actual, + ship.shape, + ship.current_position, 0.0F, // angle (rotació 2D no utilitzada) - nau.escala_actual, + ship.current_scale, 1.0F, // progress (sempre visible) - 1.0F // brightness (brillantor màxima) + 1.0F // brightness (brightness màxima) ); } } @@ -76,46 +76,46 @@ void ShipAnimator::draw() const { void ShipAnimator::start_entry_animation() { using namespace Defaults::Title::Ships; - // Configurar nau P1 per a l'animació d'entrada - naus_[0].estat = EstatNau::ENTERING; - naus_[0].temps_estat = 0.0F; - naus_[0].posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE); - naus_[0].posicio_actual = naus_[0].posicio_inicial; - naus_[0].escala_actual = naus_[0].escala_inicial; + // Configurar ship P1 per a l'animació d'entrada + ships_[0].state = ShipState::ENTERING; + ships_[0].state_time = 0.0F; + ships_[0].initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE); + ships_[0].current_position = ships_[0].initial_position; + ships_[0].current_scale = ships_[0].initial_scale; - // Configurar nau P2 per a l'animació d'entrada - naus_[1].estat = EstatNau::ENTERING; - naus_[1].temps_estat = 0.0F; - naus_[1].posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE); - naus_[1].posicio_actual = naus_[1].posicio_inicial; - naus_[1].escala_actual = naus_[1].escala_inicial; + // Configurar ship P2 per a l'animació d'entrada + ships_[1].state = ShipState::ENTERING; + ships_[1].state_time = 0.0F; + ships_[1].initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE); + ships_[1].current_position = ships_[1].initial_position; + ships_[1].current_scale = ships_[1].initial_scale; } void ShipAnimator::trigger_exit_animation() { // Configurar ambdues naus per a l'animació de sortida - for (auto& nau : naus_) { - // Canviar estat a EXITING - nau.estat = EstatNau::EXITING; - nau.temps_estat = 0.0F; + for (auto& ship : ships_) { + // Canviar state a EXITING + ship.state = ShipState::EXITING; + ship.state_time = 0.0F; // Preservar posició actual (pot estar a mig camí si START es prem durant ENTERING) - nau.posicio_inicial = nau.posicio_actual; + ship.initial_position = ship.current_position; - // La escala objectiu es preserva per a calcular la interpolació - // (escala_actual pot ser diferent si està en ENTERING) + // La scale objectiu es preserva per a calcular la interpolació + // (current_scale pot ser diferent si està en ENTERING) } } void ShipAnimator::skip_to_floating_state() { - // Posar ambdues naus directament en estat FLOATING - for (auto& nau : naus_) { - nau.estat = EstatNau::FLOATING; - nau.temps_estat = 0.0F; - nau.fase_oscilacio = 0.0F; + // Posar ambdues naus directament en state FLOATING + for (auto& ship : ships_) { + ship.state = ShipState::FLOATING; + ship.state_time = 0.0F; + ship.oscillation_phase = 0.0F; // Posar en posició objectiu (sense animació) - nau.posicio_actual = nau.posicio_objectiu; - nau.escala_actual = nau.escala_objectiu; + ship.current_position = ship.target_position; + ship.current_scale = ship.target_scale; // NO establir visibilitat aquí - ja ho fa el caller // (evita fer visibles ambdues naus quan només una ha premut START) @@ -123,201 +123,201 @@ void ShipAnimator::skip_to_floating_state() { } bool ShipAnimator::is_visible() const { - // Retorna true si almenys una nau és visible - for (const auto& nau : naus_) { - if (nau.visible) { + // Retorna true si almenys una ship és visible + for (const auto& ship : ships_) { + if (ship.visible) { return true; } } return false; } -void ShipAnimator::trigger_exit_animation_for_player(int jugador_id) { - // Trobar la nau del jugador especificat - for (auto& nau : naus_) { - if (nau.jugador_id == jugador_id) { - // Canviar estat a EXITING només per aquesta nau - nau.estat = EstatNau::EXITING; - nau.temps_estat = 0.0F; +void ShipAnimator::trigger_exit_animation_for_player(int player_id) { + // Trobar la ship del player especificat + for (auto& ship : ships_) { + if (ship.player_id == player_id) { + // Canviar state a EXITING només per aquesta ship + ship.state = ShipState::EXITING; + ship.state_time = 0.0F; // Preservar posició actual (pot estar a mig camí si START es prem durant ENTERING) - nau.posicio_inicial = nau.posicio_actual; + ship.initial_position = ship.current_position; - // La escala objectiu es preserva per a calcular la interpolació - // (escala_actual pot ser diferent si està en ENTERING) - break; // Només una nau per jugador + // La scale objectiu es preserva per a calcular la interpolació + // (current_scale pot ser diferent si està en ENTERING) + break; // Només una ship per player } } } void ShipAnimator::set_visible(bool visible) { - for (auto& nau : naus_) { - nau.visible = visible; + for (auto& ship : ships_) { + ship.visible = visible; } } bool ShipAnimator::is_animation_complete() const { // Comprovar si totes les naus són invisibles (han completat l'animació de sortida) - for (const auto& nau : naus_) { - if (nau.visible) { - return false; // Encara hi ha alguna nau visible + for (const auto& ship : ships_) { + if (ship.visible) { + return false; // Encara hi ha alguna ship visible } } return true; // Totes les naus són invisibles } // Mètodes d'animació (stubs) -void ShipAnimator::actualitzar_entering(NauTitol& nau, float delta_time) { +void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) { using namespace Defaults::Title::Ships; - nau.temps_estat += delta_time; + ship.state_time += delta_time; // Esperar al delay abans de començar l'animació - if (nau.temps_estat < nau.entry_delay) { - // Encara en delay: la nau es queda fora de pantalla (posició inicial) - nau.posicio_actual = nau.posicio_inicial; - nau.escala_actual = nau.escala_inicial; + if (ship.state_time < ship.entry_delay) { + // Encara en delay: la ship es queda fora de pantalla (posició inicial) + ship.current_position = ship.initial_position; + ship.current_scale = ship.initial_scale; return; } // Càlcul del progrés (restant el delay) - float elapsed = nau.temps_estat - nau.entry_delay; + float elapsed = ship.state_time - ship.entry_delay; float progress = std::min(1.0F, elapsed / ENTRY_DURATION); // Aplicar easing (ease_out_quad per arribada suau) float eased_progress = Easing::ease_out_quad(progress); // Lerp posició (inicial → objectiu) - nau.posicio_actual.x = Easing::lerp(nau.posicio_inicial.x, nau.posicio_objectiu.x, eased_progress); - nau.posicio_actual.y = Easing::lerp(nau.posicio_inicial.y, nau.posicio_objectiu.y, eased_progress); + ship.current_position.x = Easing::lerp(ship.initial_position.x, ship.target_position.x, eased_progress); + ship.current_position.y = Easing::lerp(ship.initial_position.y, ship.target_position.y, eased_progress); - // Lerp escala (gran → normal) - nau.escala_actual = Easing::lerp(nau.escala_inicial, nau.escala_objectiu, eased_progress); + // Lerp scale (gran → normal) + ship.current_scale = Easing::lerp(ship.initial_scale, ship.target_scale, eased_progress); // Transicionar a FLOATING quan completi if (elapsed >= ENTRY_DURATION) { - nau.estat = EstatNau::FLOATING; - nau.temps_estat = 0.0F; - nau.fase_oscilacio = 0.0F; // Reiniciar fase d'oscil·lació + ship.state = ShipState::FLOATING; + ship.state_time = 0.0F; + ship.oscillation_phase = 0.0F; // Reiniciar fase d'oscil·lació } } -void ShipAnimator::actualitzar_floating(NauTitol& nau, float delta_time) { +void ShipAnimator::actualitzar_floating(TitleShip& ship, float delta_time) { using namespace Defaults::Title::Ships; - // Actualitzar temps i fase d'oscil·lació - nau.temps_estat += delta_time; - nau.fase_oscilacio += delta_time; + // Actualitzar time i fase d'oscil·lació + ship.state_time += delta_time; + ship.oscillation_phase += delta_time; - // Oscil·lació sinusoïdal X/Y (paràmetres específics per nau) - float offset_x = nau.amplitude_x * std::sin(2.0F * Defaults::Math::PI * nau.frequency_x * nau.fase_oscilacio); - float offset_y = nau.amplitude_y * std::sin((2.0F * Defaults::Math::PI * nau.frequency_y * nau.fase_oscilacio) + FLOAT_PHASE_OFFSET); + // Oscil·lació sinusoïdal X/Y (paràmetres específics per ship) + float offset_x = ship.amplitude_x * std::sin(2.0F * Defaults::Math::PI * ship.frequency_x * ship.oscillation_phase); + float offset_y = ship.amplitude_y * std::sin((2.0F * Defaults::Math::PI * ship.frequency_y * ship.oscillation_phase) + FLOAT_PHASE_OFFSET); // Aplicar oscil·lació a la posició objectiu - nau.posicio_actual.x = nau.posicio_objectiu.x + offset_x; - nau.posicio_actual.y = nau.posicio_objectiu.y + offset_y; + ship.current_position.x = ship.target_position.x + offset_x; + ship.current_position.y = ship.target_position.y + offset_y; // Escala constant (sense "breathing" per ara) - nau.escala_actual = nau.escala_objectiu; + ship.current_scale = ship.target_scale; } -void ShipAnimator::actualitzar_exiting(NauTitol& nau, float delta_time) { +void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) { using namespace Defaults::Title::Ships; - nau.temps_estat += delta_time; + ship.state_time += delta_time; // Calcular progrés (0.0 → 1.0) - float progress = std::min(1.0F, nau.temps_estat / EXIT_DURATION); + float progress = std::min(1.0F, ship.state_time / EXIT_DURATION); - // Aplicar easing (ease_in_quad per acceleració cap al punt de fuga) + // Aplicar easing (ease_in_quad per acceleració cap al point de fuga) float eased_progress = Easing::ease_in_quad(progress); // Vec2 de fuga (centre del starfield) constexpr Vec2 punt_fuga{.x = VANISHING_POINT_X, .y = VANISHING_POINT_Y}; - // Lerp posició cap al punt de fuga (preservar posició inicial actual) - // Nota: posicio_inicial conté la posició on estava quan es va activar EXITING - nau.posicio_actual.x = Easing::lerp(nau.posicio_inicial.x, punt_fuga.x, eased_progress); - nau.posicio_actual.y = Easing::lerp(nau.posicio_inicial.y, punt_fuga.y, eased_progress); + // Lerp posició cap al point de fuga (preservar posició inicial actual) + // Nota: initial_position conté la posició on estava quan es va activar EXITING + ship.current_position.x = Easing::lerp(ship.initial_position.x, punt_fuga.x, eased_progress); + ship.current_position.y = Easing::lerp(ship.initial_position.y, punt_fuga.y, eased_progress); // Escala redueix a 0 (simula Z → infinit) - nau.escala_actual = nau.escala_objectiu * (1.0F - eased_progress); + ship.current_scale = ship.target_scale * (1.0F - eased_progress); // Marcar invisible quan l'animació completi if (progress >= 1.0F) { - nau.visible = false; + ship.visible = false; } } // Configuració -void ShipAnimator::configurar_nau_p1(NauTitol& nau) { +void ShipAnimator::configurar_nau_p1(TitleShip& ship) { using namespace Defaults::Title::Ships; // Estat inicial: FLOATING (per test estàtic) - nau.estat = EstatNau::FLOATING; - nau.temps_estat = 0.0F; + ship.state = ShipState::FLOATING; + ship.state_time = 0.0F; // Posicions (clock 8, bottom-left) - nau.posicio_objectiu = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()}; + ship.target_position = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()}; // Calcular posició inicial (fora de pantalla) - nau.posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE); - nau.posicio_actual = nau.posicio_inicial; // Començar fora de pantalla + ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE); + ship.current_position = ship.initial_position; // Començar fora de pantalla // Escales - nau.escala_objectiu = FLOATING_SCALE; - nau.escala_actual = FLOATING_SCALE; - nau.escala_inicial = ENTRY_SCALE_START; + ship.target_scale = FLOATING_SCALE; + ship.current_scale = FLOATING_SCALE; + ship.initial_scale = ENTRY_SCALE_START; // Flotació - nau.fase_oscilacio = 0.0F; + ship.oscillation_phase = 0.0F; // Paràmetres d'entrada - nau.entry_delay = P1_ENTRY_DELAY; + ship.entry_delay = P1_ENTRY_DELAY; // Paràmetres d'oscil·lació específics P1 - nau.amplitude_x = FLOAT_AMPLITUDE_X; - nau.amplitude_y = FLOAT_AMPLITUDE_Y; - nau.frequency_x = FLOAT_FREQUENCY_X_BASE * P1_FREQUENCY_MULTIPLIER; - nau.frequency_y = FLOAT_FREQUENCY_Y_BASE * P1_FREQUENCY_MULTIPLIER; + ship.amplitude_x = FLOAT_AMPLITUDE_X; + ship.amplitude_y = FLOAT_AMPLITUDE_Y; + ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P1_FREQUENCY_MULTIPLIER; + ship.frequency_y = FLOAT_FREQUENCY_Y_BASE * P1_FREQUENCY_MULTIPLIER; // Visibilitat - nau.visible = true; + ship.visible = true; } -void ShipAnimator::configurar_nau_p2(NauTitol& nau) { +void ShipAnimator::configurar_nau_p2(TitleShip& ship) { using namespace Defaults::Title::Ships; // Estat inicial: FLOATING (per test estàtic) - nau.estat = EstatNau::FLOATING; - nau.temps_estat = 0.0F; + ship.state = ShipState::FLOATING; + ship.state_time = 0.0F; // Posicions (clock 4, bottom-right) - nau.posicio_objectiu = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()}; + ship.target_position = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()}; // Calcular posició inicial (fora de pantalla) - nau.posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE); - nau.posicio_actual = nau.posicio_inicial; // Començar fora de pantalla + ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE); + ship.current_position = ship.initial_position; // Començar fora de pantalla // Escales - nau.escala_objectiu = FLOATING_SCALE; - nau.escala_actual = FLOATING_SCALE; - nau.escala_inicial = ENTRY_SCALE_START; + ship.target_scale = FLOATING_SCALE; + ship.current_scale = FLOATING_SCALE; + ship.initial_scale = ENTRY_SCALE_START; // Flotació - nau.fase_oscilacio = 0.0F; + ship.oscillation_phase = 0.0F; // Paràmetres d'entrada - nau.entry_delay = P2_ENTRY_DELAY; + ship.entry_delay = P2_ENTRY_DELAY; // Paràmetres d'oscil·lació específics P2 - nau.amplitude_x = FLOAT_AMPLITUDE_X; - nau.amplitude_y = FLOAT_AMPLITUDE_Y; - nau.frequency_x = FLOAT_FREQUENCY_X_BASE * P2_FREQUENCY_MULTIPLIER; - nau.frequency_y = FLOAT_FREQUENCY_Y_BASE * P2_FREQUENCY_MULTIPLIER; + ship.amplitude_x = FLOAT_AMPLITUDE_X; + ship.amplitude_y = FLOAT_AMPLITUDE_Y; + ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P2_FREQUENCY_MULTIPLIER; + ship.frequency_y = FLOAT_FREQUENCY_Y_BASE * P2_FREQUENCY_MULTIPLIER; // Visibilitat - nau.visible = true; + ship.visible = true; } Vec2 ShipAnimator::calcular_posicio_fora_pantalla(float angle_rellotge) const { diff --git a/source/game/title/ship_animator.hpp b/source/game/title/ship_animator.hpp index 20f7641..d0c6b72 100644 --- a/source/game/title/ship_animator.hpp +++ b/source/game/title/ship_animator.hpp @@ -13,46 +13,46 @@ namespace Title { -// Estats de l'animació de la nau -enum class EstatNau { +// Estats de l'animació de la ship +enum class ShipState { ENTERING, // Entrant des de fora de pantalla FLOATING, // Flotant en posició estàtica - EXITING // Volant cap al punt de fuga + EXITING // Volant cap al point de fuga }; -// Dades d'una nau individual al títol -struct NauTitol { +// Dades d'una ship individual al títol +struct TitleShip { // Identificació - int jugador_id; // 1 o 2 + int player_id; // 1 o 2 // Estat - EstatNau estat; - float temps_estat; // Temps acumulat en l'estat actual + ShipState state; + float state_time; // Temps acumulat en l'state actual // Posicions - Vec2 posicio_inicial; // Posició d'inici (fora de pantalla per ENTERING) - Vec2 posicio_objectiu; // Posició objectiu (rellotge 8 o 4) - Vec2 posicio_actual; // Posició interpolada actual + Vec2 initial_position; // Posició d'inici (fora de pantalla per ENTERING) + Vec2 target_position; // Posició objectiu (rellotge 8 o 4) + Vec2 current_position; // Posició interpolada actual // Escales (simulació eix Z) - float escala_inicial; // Escala d'inici (més gran = més a prop) - float escala_objectiu; // Escala objectiu (mida flotació) - float escala_actual; // Escala interpolada actual + float initial_scale; // Escala d'inici (més gran = més a prop) + float target_scale; // Escala objectiu (mida flotació) + float current_scale; // Escala interpolada actual // Flotació - float fase_oscilacio; // Acumulador de fase per moviment sinusoïdal + float oscillation_phase; // Acumulador de fase per moviment sinusoïdal // Paràmetres d'entrada float entry_delay; // Delay abans d'entrar (0.0 per P1, 0.5 per P2) - // Paràmetres d'oscil·lació per nau + // Paràmetres d'oscil·lació per ship float amplitude_x; float amplitude_y; float frequency_x; float frequency_y; // Forma - std::shared_ptr forma; + std::shared_ptr shape; // Visibilitat bool visible; @@ -68,29 +68,29 @@ class ShipAnimator { void update(float delta_time); void draw() const; - // Control d'estat (cridat per TitleScene) + // Control d'state (cridat per TitleScene) void start_entry_animation(); void trigger_exit_animation(); // Anima totes les naus - void trigger_exit_animation_for_player(int jugador_id); // Anima només una nau (P1=1, P2=2) + void trigger_exit_animation_for_player(int player_id); // Anima només una ship (P1=1, P2=2) void skip_to_floating_state(); // Salta directament a FLOATING sense animació // Control de visibilitat void set_visible(bool visible); [[nodiscard]] bool is_animation_complete() const; - [[nodiscard]] bool is_visible() const; // Comprova si alguna nau és visible + [[nodiscard]] bool is_visible() const; // Comprova si alguna ship és visible private: SDL_Renderer* renderer_; - std::array naus_; // Naus P1 i P2 + std::array ships_; // Naus P1 i P2 // Mètodes d'animació - void actualitzar_entering(NauTitol& nau, float delta_time); - void actualitzar_floating(NauTitol& nau, float delta_time); - void actualitzar_exiting(NauTitol& nau, float delta_time); + void actualitzar_entering(TitleShip& ship, float delta_time); + void actualitzar_floating(TitleShip& ship, float delta_time); + void actualitzar_exiting(TitleShip& ship, float delta_time); // Configuració - void configurar_nau_p1(NauTitol& nau); - void configurar_nau_p2(NauTitol& nau); + void configurar_nau_p1(TitleShip& ship); + void configurar_nau_p2(TitleShip& ship); [[nodiscard]] Vec2 calcular_posicio_fora_pantalla(float angle_rellotge) const; };