Fase 1e: cierre de naming sweep (#pragma once, locals, comentarios castellano)
Tres tareas de pulido para cerrar la Fase 1 por completo: #pragma once uniforme: - sdl_manager.hpp y game_scene.hpp pasan de #ifndef/#define guards a #pragma once. Los archivos externos (stb_vorbis.h, fkyaml_node.hpp) se mantienen intactos (codigo de terceros). Variables locales y parametros restantes (catalan -> ingles): - fitxer -> file, moviment -> movement, inici -> start - comptador -> counter, escalada -> scaled - missatges -> messages, llista -> list - alçada -> height, amplada -> width, llargada -> length - origen -> origin, distancia -> distance, valor -> value, desti -> target - neteja -> clear, presenta -> present (SDLManager) - total_enemics -> total_enemies, configurar -> configure, iniciar -> start Comentarios catalan -> castellano: - Cabeceras de fichero actualizadas con nombres nuevos (escena_joc.hpp -> game_scene.hpp, etc.) - Palabras tecnicas: trasllacio->traslacion, col-lisio->colision, inicialitzacio->inicializacion, posicio->posicion, rotacio->rotacion, velocitat->velocidad, acceleracio->aceleracion, explosio->explosion, renderitzat->renderizado, calcul->calculo, transicio->transicion, comprovacio->comprobacion, substitucio->sustitucion, utilitzacio->utilizacion, opcio->opcion, configuracio->configuracion, funcio->funcion, distancia, animacio->animacion - Determinantes y conectores: aquest->este, aquesta->esta, amb->con, sense->sin, pero->pero, mai->nunca, nomes->solo, tambe->tambien, sempre->siempre, ja->ya, mateix->mismo, vegada->vez, dintre->dentro, fora->fuera, dreta->derecha, esquerra->izquierda, sortir->salir, sortida->salida, petit->pequeno, gran->grande, nou->nuevo, vell->viejo, molt->mucho, els->los, les->las, totes les->todas las, d'->de, com->como, quan->cuando, mentre->mientras, despres->despues, abans->antes, durant->durante, fins->hasta, encara->aun, llavors->entonces, aixi->asi, perque->porque - Sustantivos: classe->clase, metode->metodo, parametre->parametro, versio->version, entitat->entidad, joc->juego, nivell->nivel, enemic->enemigo, naus->naves, bales->balas, fitxer->archivo, pentagon->pentagono, pun- tuacio->puntuacion, flotant->flotante, titol->titulo, objectiu->objetivo, mostra->muestra, tipus->tipo Strings literales preservados en valenciano segun decision del usuario: el texto del HUD del juego (puntuaciones, mensajes en pantalla, archivo de config) se mantiene en valenciano original. 70 fitxers tocats, +1117 / -1123. Compila i enllaca. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// debris_manager.cpp - Implementació del gestor de fragments
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "debris_manager.hpp"
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
|
||||
namespace Effects {
|
||||
|
||||
// Helper: transformar point amb rotació, scale i trasllació
|
||||
// Helper: transformar point con rotación, scale i traslación
|
||||
// (Copiat de shape_renderer.cpp:12-34)
|
||||
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
|
||||
// 1. Centrar el point respecte al centro de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
@@ -25,27 +25,27 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
float scaled_x = centered_x * scale;
|
||||
float scaled_y = centered_y * scale;
|
||||
|
||||
// 3. Aplicar rotació
|
||||
// 3. Aplicar rotación
|
||||
float cos_a = std::cos(angle);
|
||||
float sin_a = std::sin(angle);
|
||||
|
||||
float rotated_x = (scaled_x * cos_a) - (scaled_y * sin_a);
|
||||
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
|
||||
|
||||
// 4. Aplicar trasllació a posició mundial
|
||||
// 4. Aplicar traslación a posición mundial
|
||||
return {.x = rotated_x + position.x, .y = rotated_y + position.y};
|
||||
}
|
||||
|
||||
DebrisManager::DebrisManager(SDL_Renderer* renderer)
|
||||
: renderer_(renderer) {
|
||||
// Inicialitzar tots els debris com inactius
|
||||
// Inicialitzar todos los debris como inactius
|
||||
for (auto& debris : debris_pool_) {
|
||||
debris.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& centre,
|
||||
const Vec2& centro,
|
||||
float angle,
|
||||
float scale,
|
||||
float velocitat_base,
|
||||
@@ -61,10 +61,10 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
// Reproducir sonido de explosión
|
||||
Audio::get()->playSound(sound, Audio::Group::GAME);
|
||||
|
||||
// Obtenir centre de la shape per a transformacions
|
||||
// Obtenir centro de la shape para transformacions
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
// Iterar sobre totes les primitives de la shape
|
||||
// Iterar sobre todas las primitives de la shape
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
// Processar cada segment de línia
|
||||
std::vector<std::pair<Vec2, Vec2>> segments;
|
||||
@@ -81,13 +81,13 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
}
|
||||
}
|
||||
|
||||
// Crear debris per a cada segment
|
||||
// Crear debris para cada segment
|
||||
for (const auto& [local_p1, local_p2] : segments) {
|
||||
// 1. Transformar points locals → coordenades mundials
|
||||
Vec2 world_p1 =
|
||||
transform_point(local_p1, shape_centre, centre, angle, scale);
|
||||
transform_point(local_p1, shape_centre, centro, angle, scale);
|
||||
Vec2 world_p2 =
|
||||
transform_point(local_p2, shape_centre, centre, angle, scale);
|
||||
transform_point(local_p2, shape_centre, centro, angle, scale);
|
||||
|
||||
// 2. Trobar slot lliure
|
||||
Debris* debris = findFreeSlot();
|
||||
@@ -100,10 +100,10 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->p1 = world_p1;
|
||||
debris->p2 = world_p2;
|
||||
|
||||
// 4. Calcular direcció d'explosió (radial, des del centre cap a fora)
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centre);
|
||||
// 4. Calcular direcció de explosión (radial, des del centro hacia fuera)
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centro);
|
||||
|
||||
// 5. Velocitat inicial (base ± variació aleatòria + velocity heretada)
|
||||
// 5. Velocidad inicial (base ± variació aleatòria + velocity heretada)
|
||||
float speed =
|
||||
velocitat_base +
|
||||
(((std::rand() / static_cast<float>(RAND_MAX)) * 2.0F - 1.0F) *
|
||||
@@ -114,11 +114,11 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->velocity.y = (direccio.y * speed) + velocitat_objecte.y;
|
||||
debris->acceleration = Defaults::Physics::Debris::ACCELERACIO;
|
||||
|
||||
// 6. Herència de velocity angular amb cap + conversió d'excés
|
||||
// 6. Herència de velocity angular con sin + conversió de excés
|
||||
|
||||
// 6a. Rotació de TRAYECTORIA amb cap + conversió tangencial
|
||||
// 6a. Rotación de TRAYECTORIA con sin + conversió tangencial
|
||||
if (std::abs(velocitat_angular) > 0.01F) {
|
||||
// FASE 1: Aplicar herència i variació (igual que abans)
|
||||
// FASE 1: Aplicar herència i variació (igual que antes)
|
||||
float factor_herencia =
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
@@ -131,7 +131,7 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) * 0.2F) - 0.1F;
|
||||
velocitat_ang_heretada *= (1.0F + variacio);
|
||||
|
||||
// FASE 2: Aplicar cap i calcular excés
|
||||
// FASE 2: Aplicar sin i calcular excés
|
||||
constexpr float CAP = Defaults::Physics::Debris::VELOCITAT_ROT_MAX;
|
||||
float abs_ang = std::abs(velocitat_ang_heretada);
|
||||
float sign_ang = (velocitat_ang_heretada >= 0.0F) ? 1.0F : -1.0F;
|
||||
@@ -140,10 +140,10 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
// Excés: convertir a velocity tangencial
|
||||
float excess = abs_ang - CAP;
|
||||
|
||||
// Radi de la shape (enemics = 20 px)
|
||||
// Radi de la shape (enemigos = 20 px)
|
||||
float radius = 20.0F;
|
||||
|
||||
// Velocitat tangencial = ω_excés × radi
|
||||
// Velocidad tangencial = ω_excés × radi
|
||||
float v_tangential = excess * radius;
|
||||
|
||||
// Direcció tangencial: perpendicular a la radial (90° CCW)
|
||||
@@ -151,38 +151,38 @@ void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
float tangent_x = -direccio.y;
|
||||
float tangent_y = direccio.x;
|
||||
|
||||
// Afegir velocity tangencial (suma vectorial)
|
||||
// Añadir velocity tangencial (suma vectorial)
|
||||
debris->velocity.x += tangent_x * v_tangential;
|
||||
debris->velocity.y += tangent_y * v_tangential;
|
||||
|
||||
// Aplicar cap a velocity angular (preservar signe)
|
||||
// Aplicar hacia velocity angular (preservar signe)
|
||||
debris->velocitat_rot = sign_ang * CAP;
|
||||
} else {
|
||||
// Per sota del cap: comportament normal
|
||||
// Per sota del sin: comportament normal
|
||||
debris->velocitat_rot = velocitat_ang_heretada;
|
||||
}
|
||||
} else {
|
||||
debris->velocitat_rot = 0.0F; // Nave: sin curvas
|
||||
}
|
||||
|
||||
// 6b. Rotació VISUAL (proporcional según factor_herencia_visual)
|
||||
// 6b. Rotación VISUAL (proporcional según factor_herencia_visual)
|
||||
if (factor_herencia_visual > 0.01F && std::abs(velocitat_angular) > 0.01F) {
|
||||
// Heredar rotación visual con factor proporcional
|
||||
debris->velocitat_rot_visual = debris->velocitat_rot * factor_herencia_visual;
|
||||
|
||||
// Variació aleatòria petita (±5%) per naturalitat
|
||||
// Variació aleatòria pequeña (±5%) per naturalitat
|
||||
float variacio_visual =
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) * 0.1F) - 0.05F;
|
||||
debris->velocitat_rot_visual *= (1.0F + variacio_visual);
|
||||
} else {
|
||||
// Rotació visual aleatòria (factor = 0.0 o sin velocidad angular)
|
||||
// Rotación visual aleatòria (factor = 0.0 o sin velocidad angular)
|
||||
debris->velocitat_rot_visual =
|
||||
Defaults::Physics::Debris::ROTACIO_MIN +
|
||||
((std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::ROTACIO_MAX -
|
||||
Defaults::Physics::Debris::ROTACIO_MIN));
|
||||
|
||||
// 50% probabilitat de rotació en sentit contrari
|
||||
// 50% probabilitat de rotación en sentit contrari
|
||||
if (std::rand() % 2 == 0) {
|
||||
debris->velocitat_rot_visual = -debris->velocitat_rot_visual;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ void DebrisManager::update(float delta_time) {
|
||||
}
|
||||
|
||||
// 2. Actualitzar velocity (desacceleració)
|
||||
// Aplicar fricció en la direcció del moviment
|
||||
// Aplicar fricció en la direcció del movement
|
||||
float speed = std::sqrt((debris.velocity.x * debris.velocity.x) +
|
||||
(debris.velocity.y * debris.velocity.y));
|
||||
|
||||
@@ -229,24 +229,24 @@ void DebrisManager::update(float delta_time) {
|
||||
float dir_x = debris.velocity.x / speed;
|
||||
float dir_y = debris.velocity.y / speed;
|
||||
|
||||
// Aplicar acceleració negativa (fricció)
|
||||
// Aplicar aceleración negativa (fricció)
|
||||
float nova_speed = speed + (debris.acceleration * delta_time);
|
||||
nova_speed = std::max(nova_speed, 0.0F);
|
||||
|
||||
debris.velocity.x = dir_x * nova_speed;
|
||||
debris.velocity.y = dir_y * nova_speed;
|
||||
} else {
|
||||
// Velocitat molt baixa, aturar
|
||||
// Velocidad mucho baixa, aturar
|
||||
debris.velocity.x = 0.0F;
|
||||
debris.velocity.y = 0.0F;
|
||||
}
|
||||
|
||||
// 2b. Rotar vector de velocity (trayectoria curva)
|
||||
if (std::abs(debris.velocitat_rot) > 0.01F) {
|
||||
// Calcular angle de rotació aquest frame
|
||||
// Calcular angle de rotación este frame
|
||||
float dangle = debris.velocitat_rot * delta_time;
|
||||
|
||||
// Rotar vector de velocity usant matriu de rotació 2D
|
||||
// Rotar vector de velocity usant matriu de rotación 2D
|
||||
float vel_x_old = debris.velocity.x;
|
||||
float vel_y_old = debris.velocity.y;
|
||||
|
||||
@@ -270,35 +270,35 @@ void DebrisManager::update(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Calcular centre del segment
|
||||
Vec2 centre = {.x = (debris.p1.x + debris.p2.x) / 2.0F,
|
||||
// 3. Calcular centro del segment
|
||||
Vec2 centro = {.x = (debris.p1.x + debris.p2.x) / 2.0F,
|
||||
.y = (debris.p1.y + debris.p2.y) / 2.0F};
|
||||
|
||||
// 4. Actualitzar posició del centre
|
||||
centre.x += debris.velocity.x * delta_time;
|
||||
centre.y += debris.velocity.y * delta_time;
|
||||
// 4. Actualitzar posición del centro
|
||||
centro.x += debris.velocity.x * delta_time;
|
||||
centro.y += debris.velocity.y * delta_time;
|
||||
|
||||
// 5. Actualitzar rotació VISUAL
|
||||
// 5. Actualitzar rotación VISUAL
|
||||
debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;
|
||||
|
||||
// 6. Aplicar shrinking (reducció de distància entre points)
|
||||
// 6. Aplicar shrinking (reducció de distancia 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 points
|
||||
// Calcular distancia original entre points
|
||||
float dx = debris.p2.x - debris.p1.x;
|
||||
float dy = debris.p2.y - debris.p1.y;
|
||||
|
||||
// 7. Reconstruir segment amb nova mida i rotació
|
||||
// 7. Reconstruir segment con nueva mida i rotación
|
||||
float half_length = std::sqrt((dx * dx) + (dy * dy)) * shrink_factor / 2.0F;
|
||||
float original_angle = std::atan2(dy, dx);
|
||||
float new_angle = original_angle + debris.angle_rotacio;
|
||||
|
||||
debris.p1.x = centre.x - (half_length * std::cos(new_angle));
|
||||
debris.p1.y = centre.y - (half_length * std::sin(new_angle));
|
||||
debris.p2.x = centre.x + (half_length * std::cos(new_angle));
|
||||
debris.p2.y = centre.y + (half_length * std::sin(new_angle));
|
||||
debris.p1.x = centro.x - (half_length * std::cos(new_angle));
|
||||
debris.p1.y = centro.y - (half_length * std::sin(new_angle));
|
||||
debris.p2.x = centro.x + (half_length * std::cos(new_angle));
|
||||
debris.p2.y = centro.y + (half_length * std::sin(new_angle));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ void DebrisManager::draw() const {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Dibuixar segment de línia amb brightness heretat
|
||||
// Dibuixar segment de línia con brightness heretat
|
||||
Rendering::linea(renderer_,
|
||||
static_cast<int>(debris.p1.x),
|
||||
static_cast<int>(debris.p1.y),
|
||||
@@ -330,19 +330,19 @@ Debris* DebrisManager::findFreeSlot() {
|
||||
Vec2 DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||
const Vec2& p2,
|
||||
const Vec2& centre_objecte) const {
|
||||
// 1. Calcular centre del segment
|
||||
// 1. Calcular centro del segment
|
||||
float centro_seg_x = (p1.x + p2.x) / 2.0F;
|
||||
float centro_seg_y = (p1.y + p2.y) / 2.0F;
|
||||
|
||||
// 2. Calcular vector des del centre de l'objecte cap al centre del segment
|
||||
// Això garanteix que la direcció sempre apunte cap a fora (direcció radial)
|
||||
// 2. Calcular vector des del centro de l'objecte hacia el centro del segment
|
||||
// Això garanteix que la direcció siempre apunte hacia fuera (direcció radial)
|
||||
float dx = centro_seg_x - centre_objecte.x;
|
||||
float dy = centro_seg_y - centre_objecte.y;
|
||||
|
||||
// 3. Normalitzar (obtenir vector unitari)
|
||||
float length = std::sqrt((dx * dx) + (dy * dy));
|
||||
if (length < 0.001F) {
|
||||
// Segment al centre (cas extrem molt improbable), retornar direcció aleatòria
|
||||
// Segment al centro (cas extrem mucho improbable), retornar direcció aleatòria
|
||||
float angle_rand =
|
||||
(std::rand() / static_cast<float>(RAND_MAX)) * 2.0F * Defaults::Math::PI;
|
||||
return {.x = std::cos(angle_rand), .y = std::sin(angle_rand)};
|
||||
@@ -351,7 +351,7 @@ Vec2 DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||
dx /= length;
|
||||
dy /= length;
|
||||
|
||||
// 4. Afegir variació aleatòria petita (±15°) per varietat visual
|
||||
// 4. Añadir variació aleatòria pequeña (±15°) per varietat visual
|
||||
float angle_variacio =
|
||||
((std::rand() % 30) - 15) * Defaults::Math::PI / 180.0F;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user