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 @@
|
||||
// ship_animator.cpp - Implementació del sistema d'animació de naus
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// ship_animator.cpp - Implementació del sistema de animación de naves
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "ship_animator.hpp"
|
||||
|
||||
@@ -18,9 +18,9 @@ ShipAnimator::ShipAnimator(SDL_Renderer* renderer)
|
||||
}
|
||||
|
||||
void ShipAnimator::init() {
|
||||
// Carregar formes de naus amb perspectiva pre-calculada
|
||||
auto forma_p1 = Graphics::ShapeLoader::load("ship_perspective.shp"); // Perspectiva esquerra
|
||||
auto forma_p2 = Graphics::ShapeLoader::load("ship2_perspective.shp"); // Perspectiva dreta
|
||||
// Carregar formes de naves con perspectiva pre-calculada
|
||||
auto forma_p1 = Graphics::ShapeLoader::load("ship_perspective.shp"); // Perspectiva izquierda
|
||||
auto forma_p2 = Graphics::ShapeLoader::load("ship2_perspective.shp"); // Perspectiva derecha
|
||||
|
||||
// Configurar ship P1
|
||||
ships_[0].player_id = 1;
|
||||
@@ -60,14 +60,14 @@ void ShipAnimator::draw() const {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Renderitzar ship (perspectiva ja incorporada a la shape)
|
||||
// Renderizar ship (perspectiva ya incorporada a la shape)
|
||||
Rendering::render_shape(
|
||||
renderer_,
|
||||
ship.shape,
|
||||
ship.current_position,
|
||||
0.0F, // angle (rotació 2D no utilitzada)
|
||||
0.0F, // angle (rotación 2D no utilitzada)
|
||||
ship.current_scale,
|
||||
1.0F, // progress (sempre visible)
|
||||
1.0F, // progress (siempre visible)
|
||||
1.0F // brightness (brightness màxima)
|
||||
);
|
||||
}
|
||||
@@ -76,14 +76,14 @@ void ShipAnimator::draw() const {
|
||||
void ShipAnimator::start_entry_animation() {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Configurar ship P1 per a l'animació d'entrada
|
||||
// Configurar ship P1 para l'animación de 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 ship P2 per a l'animació d'entrada
|
||||
// Configurar ship P2 para l'animación de entrada
|
||||
ships_[1].state = ShipState::ENTERING;
|
||||
ships_[1].state_time = 0.0F;
|
||||
ships_[1].initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
@@ -92,38 +92,38 @@ void ShipAnimator::start_entry_animation() {
|
||||
}
|
||||
|
||||
void ShipAnimator::trigger_exit_animation() {
|
||||
// Configurar ambdues naus per a l'animació de sortida
|
||||
// Configurar ambdues naves para l'animación de salida
|
||||
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)
|
||||
// Preservar posición actual (pot estar a mig camí si START es prem durante ENTERING)
|
||||
ship.initial_position = ship.current_position;
|
||||
|
||||
// La scale objectiu es preserva per a calcular la interpolació
|
||||
// (current_scale pot ser diferent si està en ENTERING)
|
||||
// La scale objetivo es preserva para calcular la interpolació
|
||||
// (current_scale pot ser diferent si está en ENTERING)
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::skip_to_floating_state() {
|
||||
// Posar ambdues naus directament en state FLOATING
|
||||
// Posar ambdues naves 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ó)
|
||||
// Posar en posición objetivo (sin animación)
|
||||
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)
|
||||
// NO establir visibilitat aquí - ya ho hace el caller
|
||||
// (evita fer visibles ambdues naves cuando solo una ha premut START)
|
||||
}
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_visible() const {
|
||||
// Retorna true si almenys una ship és visible
|
||||
// Retorna true si almenys una ship es visible
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return true;
|
||||
@@ -136,16 +136,16 @@ 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
|
||||
// Canviar state a EXITING solo per esta ship
|
||||
ship.state = ShipState::EXITING;
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Preservar posició actual (pot estar a mig camí si START es prem durant ENTERING)
|
||||
// Preservar posición actual (pot estar a mig camí si START es prem durante ENTERING)
|
||||
ship.initial_position = ship.current_position;
|
||||
|
||||
// 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
|
||||
// La scale objetivo es preserva para calcular la interpolació
|
||||
// (current_scale pot ser diferent si está en ENTERING)
|
||||
break; // Solo una ship per player
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,67 +157,67 @@ void ShipAnimator::set_visible(bool visible) {
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_animation_complete() const {
|
||||
// Comprovar si totes les naus són invisibles (han completat l'animació de sortida)
|
||||
// Comprovar si todas las naves són invisibles (han completat l'animación de salida)
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return false; // Encara hi ha alguna ship visible
|
||||
return false; // Aún hay alguna ship visible
|
||||
}
|
||||
}
|
||||
return true; // Totes les naus són invisibles
|
||||
return true; // Todas las naves són invisibles
|
||||
}
|
||||
|
||||
// Mètodes d'animació (stubs)
|
||||
// Métodos de animación (stubs)
|
||||
void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
ship.state_time += delta_time;
|
||||
|
||||
// Esperar al delay abans de començar l'animació
|
||||
// Esperar al delay antes de començar l'animación
|
||||
if (ship.state_time < ship.entry_delay) {
|
||||
// Encara en delay: la ship es queda fora de pantalla (posició inicial)
|
||||
// Aún en delay: la ship es queda fuera de pantalla (posición inicial)
|
||||
ship.current_position = ship.initial_position;
|
||||
ship.current_scale = ship.initial_scale;
|
||||
return;
|
||||
}
|
||||
|
||||
// Càlcul del progrés (restant el delay)
|
||||
// Cálculo del progrés (restant el 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)
|
||||
// Lerp posición (inicial → objetivo)
|
||||
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 scale (gran → normal)
|
||||
// Lerp scale (grande → normal)
|
||||
ship.current_scale = Easing::lerp(ship.initial_scale, ship.target_scale, eased_progress);
|
||||
|
||||
// Transicionar a FLOATING quan completi
|
||||
// Transicionar a FLOATING cuando completi
|
||||
if (elapsed >= ENTRY_DURATION) {
|
||||
ship.state = ShipState::FLOATING;
|
||||
ship.state_time = 0.0F;
|
||||
ship.oscillation_phase = 0.0F; // Reiniciar fase d'oscil·lació
|
||||
ship.oscillation_phase = 0.0F; // Reiniciar fase de oscil·lació
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::actualitzar_floating(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Actualitzar time i fase d'oscil·lació
|
||||
// Actualitzar time i fase de oscil·lació
|
||||
ship.state_time += delta_time;
|
||||
ship.oscillation_phase += delta_time;
|
||||
|
||||
// Oscil·lació sinusoïdal X/Y (paràmetres específics per ship)
|
||||
// Oscil·lació sinusoïdal X/Y (parámetros 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
|
||||
// Aplicar oscil·lació a la posición objetivo
|
||||
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)
|
||||
// Escala constant (sin "breathing" per ara)
|
||||
ship.current_scale = ship.target_scale;
|
||||
}
|
||||
|
||||
@@ -229,27 +229,27 @@ void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) {
|
||||
// Calcular progrés (0.0 → 1.0)
|
||||
float progress = std::min(1.0F, ship.state_time / EXIT_DURATION);
|
||||
|
||||
// Aplicar easing (ease_in_quad per acceleració cap al point de fuga)
|
||||
// Aplicar easing (ease_in_quad per aceleración hacia el point de fuga)
|
||||
float eased_progress = Easing::ease_in_quad(progress);
|
||||
|
||||
// Vec2 de fuga (centre del starfield)
|
||||
// Vec2 de fuga (centro del starfield)
|
||||
constexpr Vec2 punt_fuga{.x = VANISHING_POINT_X, .y = VANISHING_POINT_Y};
|
||||
|
||||
// Lerp posició cap al point de fuga (preservar posició inicial actual)
|
||||
// Nota: initial_position conté la posició on estava quan es va activar EXITING
|
||||
// Lerp posición hacia el point de fuga (preservar posición inicial actual)
|
||||
// Nota: initial_position conté la posición on estava cuando 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)
|
||||
ship.current_scale = ship.target_scale * (1.0F - eased_progress);
|
||||
|
||||
// Marcar invisible quan l'animació completi
|
||||
// Marcar invisible cuando l'animación completi
|
||||
if (progress >= 1.0F) {
|
||||
ship.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Configuració
|
||||
// Configuración
|
||||
void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
@@ -260,9 +260,9 @@ void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
// Posicions (clock 8, bottom-left)
|
||||
ship.target_position = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()};
|
||||
|
||||
// Calcular posició inicial (fora de pantalla)
|
||||
// Calcular posición inicial (fuera de pantalla)
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fora de pantalla
|
||||
ship.current_position = ship.initial_position; // Començar fuera de pantalla
|
||||
|
||||
// Escales
|
||||
ship.target_scale = FLOATING_SCALE;
|
||||
@@ -272,10 +272,10 @@ void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
// Flotació
|
||||
ship.oscillation_phase = 0.0F;
|
||||
|
||||
// Paràmetres d'entrada
|
||||
// Parámetros de entrada
|
||||
ship.entry_delay = P1_ENTRY_DELAY;
|
||||
|
||||
// Paràmetres d'oscil·lació específics P1
|
||||
// Parámetros de oscil·lació específics P1
|
||||
ship.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
ship.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P1_FREQUENCY_MULTIPLIER;
|
||||
@@ -295,9 +295,9 @@ void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
// Posicions (clock 4, bottom-right)
|
||||
ship.target_position = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()};
|
||||
|
||||
// Calcular posició inicial (fora de pantalla)
|
||||
// Calcular posición inicial (fuera de pantalla)
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fora de pantalla
|
||||
ship.current_position = ship.initial_position; // Començar fuera de pantalla
|
||||
|
||||
// Escales
|
||||
ship.target_scale = FLOATING_SCALE;
|
||||
@@ -307,10 +307,10 @@ void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
// Flotació
|
||||
ship.oscillation_phase = 0.0F;
|
||||
|
||||
// Paràmetres d'entrada
|
||||
// Parámetros de entrada
|
||||
ship.entry_delay = P2_ENTRY_DELAY;
|
||||
|
||||
// Paràmetres d'oscil·lació específics P2
|
||||
// Parámetros de oscil·lació específics P2
|
||||
ship.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
ship.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P2_FREQUENCY_MULTIPLIER;
|
||||
@@ -324,7 +324,7 @@ Vec2 ShipAnimator::calcular_posicio_fora_pantalla(float angle_rellotge) const {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Convertir angle del rellotge a radians (per exemple: 240° per clock 8)
|
||||
// Calcular posició en direcció radial des del centre, però més lluny
|
||||
// Calcular posición en direcció radial des del centro, pero més lluny
|
||||
// ENTRY_OFFSET es calcula automàticament: (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN
|
||||
float extended_radius = CLOCK_RADIUS + ENTRY_OFFSET;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user