cd38101f99
Primera sub-fase del naming sweep. Punt era un struct sense
operacions, conservat per compatibilitat amb el Pascal original.
Substituit per Vec2, un aggregate amb operadors aritmetics, dot,
length, normalized i length_squared (camelBack: lengthSquared)
seguint les regles del .clang-tidy del projecte.
Canvis:
- core/types.hpp reescrit: nou struct Vec2 amb +=,-=,*=,/=,
unary -, ==, dot, length, lengthSquared, normalized
- Operadors fora de la classe: +, -, *, / (amb float per ambdues
bandes), - unari, ==
- Vec2 segueix sent aggregate (sense constructors definits):
els 'designated initializers' del codi existent funcionen igual:
Vec2{.x = ..., .y = ...}
- Sed global sobre 35 fitxers: tots els 'Punt' -> 'Vec2'
Net: 35 fitxers tocats, +180 / -114. Compila i enllaça.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
98 lines
3.0 KiB
C++
98 lines
3.0 KiB
C++
// ship_animator.hpp - Sistema d'animació de naus per a l'escena de títol
|
|
// © 2025 Port a C++20 amb SDL3
|
|
|
|
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
|
|
#include "core/graphics/shape.hpp"
|
|
#include "core/types.hpp"
|
|
|
|
namespace Title {
|
|
|
|
// Estats de l'animació de la nau
|
|
enum class EstatNau {
|
|
ENTERING, // Entrant des de fora de pantalla
|
|
FLOATING, // Flotant en posició estàtica
|
|
EXITING // Volant cap al punt de fuga
|
|
};
|
|
|
|
// Dades d'una nau individual al títol
|
|
struct NauTitol {
|
|
// Identificació
|
|
int jugador_id; // 1 o 2
|
|
|
|
// Estat
|
|
EstatNau estat;
|
|
float temps_estat; // Temps acumulat en l'estat 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
|
|
|
|
// 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
|
|
|
|
// Flotació
|
|
float fase_oscilacio; // 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
|
|
float amplitude_x;
|
|
float amplitude_y;
|
|
float frequency_x;
|
|
float frequency_y;
|
|
|
|
// Forma
|
|
std::shared_ptr<Graphics::Shape> forma;
|
|
|
|
// Visibilitat
|
|
bool visible;
|
|
};
|
|
|
|
// Gestor d'animació de naus per a l'escena de títol
|
|
class ShipAnimator {
|
|
public:
|
|
explicit ShipAnimator(SDL_Renderer* renderer);
|
|
|
|
// Cicle de vida
|
|
void inicialitzar();
|
|
void actualitzar(float delta_time);
|
|
void dibuixar() const;
|
|
|
|
// Control d'estat (cridat per EscenaTitol)
|
|
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 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
|
|
|
|
private:
|
|
SDL_Renderer* renderer_;
|
|
std::array<NauTitol, 2> naus_; // 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);
|
|
|
|
// Configuració
|
|
void configurar_nau_p1(NauTitol& nau);
|
|
void configurar_nau_p2(NauTitol& nau);
|
|
[[nodiscard]] Vec2 calcular_posicio_fora_pantalla(float angle_rellotge) const;
|
|
};
|
|
|
|
} // namespace Title
|