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:
+258
-258
File diff suppressed because it is too large
Load Diff
@@ -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<Ship, 2> naus_; // [0]=P1, [1]=P2
|
||||
std::array<Enemy, Constants::MAX_ORNIS> orni_;
|
||||
std::array<Bullet, Constants::MAX_BALES * 2> bales_; // 6 balas: P1=[0,1,2], P2=[3,4,5]
|
||||
std::array<float, 2> itocado_per_jugador_; // Death timers per player (seconds)
|
||||
std::array<Ship, 2> ships_; // [0]=P1, [1]=P2
|
||||
std::array<Enemy, Constants::MAX_ORNIS> enemies_;
|
||||
std::array<Bullet, Constants::MAX_BALES * 2> bullets_; // 6 balas: P1=[0,1,2], P2=[3,4,5]
|
||||
std::array<float, 2> hit_timer_per_player_; // Death timers per player (seconds)
|
||||
|
||||
// Lives and game over system
|
||||
std::array<int, 2> vides_per_jugador_; // [0]=P1, [1]=P2
|
||||
GameOverState estat_game_over_; // Game over state machine (NONE, CONTINUE, GAME_OVER)
|
||||
std::array<int, 2> 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<int, 2> puntuacio_per_jugador_; // [0]=P1, [1]=P2
|
||||
Vec2 death_position_; // Death position (for respawn)
|
||||
std::array<int, 2> score_per_player_; // [0]=P1, [1]=P2
|
||||
|
||||
// Text vectorial
|
||||
Graphics::VectorText text_;
|
||||
|
||||
// [NEW] Stage system
|
||||
std::unique_ptr<StageSystem::ConfigSistemaStages> stage_config_;
|
||||
std::unique_ptr<StageSystem::StageSystemConfig> stage_config_;
|
||||
std::unique_ptr<StageSystem::StageManager> 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
|
||||
|
||||
@@ -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<float>(num_letras);
|
||||
float step = threshold * duration_per_letra;
|
||||
float start = static_cast<float>(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<Effects::DebrisManager>(sdl.obte_renderer())),
|
||||
debris_manager_(std::make_unique<Effects::DebrisManager>(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<int>(nou_estat)
|
||||
std::cout << "[LogoScene] Canvi a state: " << static_cast<int>(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();
|
||||
|
||||
@@ -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<Effects::DebrisManager> 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<size_t> ordre_explosio_; // Ordre aleatori d'índexs de lletres
|
||||
|
||||
// Estructura per a cada lletra del logo
|
||||
struct LetraLogo {
|
||||
std::shared_ptr<Graphics::Shape> forma;
|
||||
Vec2 posicio; // Posició final en pantalla
|
||||
std::shared_ptr<Graphics::Shape> 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
|
||||
};
|
||||
|
||||
@@ -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<float>(Defaults::Game::HEIGHT)};
|
||||
|
||||
starfield_ = std::make_unique<Graphics::Starfield>(
|
||||
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<Title::ShipAnimator>(sdl_.obte_renderer());
|
||||
ship_animator_ = std::make_unique<Title::ShipAnimator>(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<int>(std::round(offset_x));
|
||||
lletres_orni_[i].posicio.y = posicions_originals_orni_[i].y + static_cast<int>(std::round(offset_y));
|
||||
lletres_orni_[i].position.x = posicions_originals_orni_[i].x + static_cast<int>(std::round(offset_x));
|
||||
lletres_orni_[i].position.y = posicions_originals_orni_[i].y + static_cast<int>(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<int>(std::round(offset_x));
|
||||
lletres_attack_[i].posicio.y = posicions_originals_attack_[i].y + static_cast<int>(std::round(offset_y));
|
||||
lletres_attack_[i].position.x = posicions_originals_attack_[i].x + static_cast<int>(std::round(offset_x));
|
||||
lletres_attack_[i].position.y = posicions_originals_attack_[i].y + static_cast<int>(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<int>(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<int>(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<float>; // 2π × freq × temps
|
||||
float fase = temps_acumulat_ * BLINK_FREQUENCY * 2.0F * std::numbers::pi_v<float>; // 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Graphics::Shape> forma; // Forma vectorial de la lletra
|
||||
Vec2 posicio; // Posició en pantalla
|
||||
std::shared_ptr<Graphics::Shape> 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<Graphics::Starfield> starfield_; // Camp d'estrelles de fons
|
||||
std::unique_ptr<Title::ShipAnimator> 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<LetraLogo> lletres_orni_; // Lletres de "ORNI" (línia 1)
|
||||
@@ -70,14 +70,14 @@ class TitleScene {
|
||||
std::vector<Vec2> 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user