Fase 1d: rename del codi restant (effects, stage_system, locals)

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) <noreply@anthropic.com>
This commit is contained in:
2026-05-19 11:44:45 +02:00
parent 5871d29d48
commit 7ee359b910
59 changed files with 998 additions and 998 deletions
+63 -63
View File
@@ -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<Graphics::Shape>& shape,
void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& 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<std::pair<Vec2, Vec2>> segments;
@@ -83,14 +83,14 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& 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<Graphics::Shape>& 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<float>(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<Graphics::Shape>& 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<Graphics::Shape>& 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<Graphics::Shape>& 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++;
}
}