LOGO explota

This commit is contained in:
2025-12-02 08:50:38 +01:00
parent 73f222fcb7
commit 20538af4c6
22 changed files with 1754 additions and 1598 deletions

21
.clang-format Normal file
View File

@@ -0,0 +1,21 @@
BasedOnStyle: Google
IndentWidth: 4
IndentAccessModifiers: true
ColumnLimit: 0 # Sin límite de longitud de línea
BreakBeforeBraces: Attach # Llaves en la misma línea
AllowShortIfStatementsOnASingleLine: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlignOperands: DontAlign
AlignAfterOpenBracket: DontAlign
BinPackArguments: false
BinPackParameters: false
ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4
IndentWrappedFunctionNames: false
Cpp11BracedListStyle: true
BreakConstructorInitializers: BeforeColon
AllowAllConstructorInitializersOnNextLine: false
PackConstructorInitializers: Never
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false

View File

@@ -2,19 +2,24 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "sdl_manager.hpp" #include "sdl_manager.hpp"
#include "core/defaults.hpp"
#include "core/rendering/line_renderer.hpp"
#include "game/options.hpp"
#include "project.h"
#include <algorithm> #include <algorithm>
#include <format> #include <format>
#include <iostream> #include <iostream>
#include "core/defaults.hpp"
#include "core/rendering/line_renderer.hpp"
#include "game/options.hpp"
#include "project.h"
SDLManager::SDLManager() SDLManager::SDLManager()
: finestra_(nullptr), renderer_(nullptr), : finestra_(nullptr),
renderer_(nullptr),
current_width_(Defaults::Window::WIDTH), current_width_(Defaults::Window::WIDTH),
current_height_(Defaults::Window::HEIGHT), is_fullscreen_(false), current_height_(Defaults::Window::HEIGHT),
max_width_(1920), max_height_(1080) { is_fullscreen_(false),
max_width_(1920),
max_height_(1080) {
// Inicialitzar SDL3 // Inicialitzar SDL3
if (!SDL_Init(SDL_INIT_VIDEO)) { if (!SDL_Init(SDL_INIT_VIDEO)) {
std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl; std::cerr << "Error inicialitzant SDL3: " << SDL_GetError() << std::endl;
@@ -25,8 +30,7 @@ SDLManager::SDLManager()
calculateMaxWindowSize(); calculateMaxWindowSize();
// Construir títol dinàmic igual que en pollo // Construir títol dinàmic igual que en pollo
std::string window_title = std::format("{} v{} ({})", Project::LONG_NAME, std::string window_title = std::format("{} v{} ({})", Project::LONG_NAME, Project::VERSION, Project::COPYRIGHT);
Project::VERSION, Project::COPYRIGHT);
// Crear finestra CENTRADA (SDL ho fa automàticament amb CENTERED) // Crear finestra CENTRADA (SDL ho fa automàticament amb CENTERED)
finestra_ = finestra_ =
@@ -41,8 +45,7 @@ SDLManager::SDLManager()
} }
// IMPORTANT: Centrar explícitament la finestra // IMPORTANT: Centrar explícitament la finestra
SDL_SetWindowPosition(finestra_, SDL_WINDOWPOS_CENTERED, SDL_SetWindowPosition(finestra_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_WINDOWPOS_CENTERED);
// Crear renderer amb acceleració // Crear renderer amb acceleració
renderer_ = SDL_CreateRenderer(finestra_, nullptr); renderer_ = SDL_CreateRenderer(finestra_, nullptr);
@@ -64,8 +67,12 @@ SDLManager::SDLManager()
// Constructor amb configuració // Constructor amb configuració
SDLManager::SDLManager(int width, int height, bool fullscreen) SDLManager::SDLManager(int width, int height, bool fullscreen)
: finestra_(nullptr), renderer_(nullptr), current_width_(width), : finestra_(nullptr),
current_height_(height), is_fullscreen_(fullscreen), max_width_(1920), renderer_(nullptr),
current_width_(width),
current_height_(height),
is_fullscreen_(fullscreen),
max_width_(1920),
max_height_(1080) { max_height_(1080) {
// Inicialitzar SDL3 // Inicialitzar SDL3
if (!SDL_Init(SDL_INIT_VIDEO)) { if (!SDL_Init(SDL_INIT_VIDEO)) {
@@ -77,8 +84,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
calculateMaxWindowSize(); calculateMaxWindowSize();
// Construir títol dinàmic // Construir títol dinàmic
std::string window_title = std::format("{} v{} ({})", Project::LONG_NAME, std::string window_title = std::format("{} v{} ({})", Project::LONG_NAME, Project::VERSION, Project::COPYRIGHT);
Project::VERSION, Project::COPYRIGHT);
// Configurar flags de la finestra // Configurar flags de la finestra
SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE; SDL_WindowFlags flags = SDL_WINDOW_RESIZABLE;
@@ -87,8 +93,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
} }
// Crear finestra // Crear finestra
finestra_ = SDL_CreateWindow(window_title.c_str(), current_width_, finestra_ = SDL_CreateWindow(window_title.c_str(), current_width_, current_height_, flags);
current_height_, flags);
if (!finestra_) { if (!finestra_) {
std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl; std::cerr << "Error creant finestra: " << SDL_GetError() << std::endl;
@@ -98,8 +103,7 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
// Centrar explícitament la finestra (si no és fullscreen) // Centrar explícitament la finestra (si no és fullscreen)
if (!is_fullscreen_) { if (!is_fullscreen_) {
SDL_SetWindowPosition(finestra_, SDL_WINDOWPOS_CENTERED, SDL_SetWindowPosition(finestra_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_WINDOWPOS_CENTERED);
} }
// Crear renderer amb acceleració // Crear renderer amb acceleració

View File

@@ -4,10 +4,12 @@
#ifndef SDL_MANAGER_HPP #ifndef SDL_MANAGER_HPP
#define SDL_MANAGER_HPP #define SDL_MANAGER_HPP
#include "core/rendering/color_oscillator.hpp"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <cstdint> #include <cstdint>
#include "core/rendering/color_oscillator.hpp"
class SDLManager { class SDLManager {
public: public:
SDLManager(); // Constructor per defecte (usa Defaults::) SDLManager(); // Constructor per defecte (usa Defaults::)

2
source/external/.clang-format vendored Normal file
View File

@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never

View File

@@ -32,8 +32,7 @@ inline bool dins_zona_joc(float x, float y) {
return SDL_PointInRectFloat(&punt, &Defaults::Zones::PLAYAREA); return SDL_PointInRectFloat(&punt, &Defaults::Zones::PLAYAREA);
} }
inline void obtenir_limits_zona(float &min_x, float &max_x, float &min_y, inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float& max_y) {
float &max_y) {
const auto& zona = Defaults::Zones::PLAYAREA; const auto& zona = Defaults::Zones::PLAYAREA;
min_x = zona.x; min_x = zona.x;
max_x = zona.x + zona.w; max_x = zona.x + zona.w;

View File

@@ -2,18 +2,19 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "debris_manager.hpp" #include "debris_manager.hpp"
#include "core/defaults.hpp"
#include "core/rendering/line_renderer.hpp"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "core/defaults.hpp"
#include "core/rendering/line_renderer.hpp"
namespace Effects { namespace Effects {
// Helper: transformar punt amb rotació, escala i trasllació // Helper: transformar punt amb rotació, escala i trasllació
// (Copiat de shape_renderer.cpp:12-34) // (Copiat de shape_renderer.cpp:12-34)
static Punt transform_point(const Punt &point, const Punt &shape_centre, static Punt transform_point(const Punt& point, const Punt& shape_centre, const Punt& posicio, float angle, float escala) {
const Punt &posicio, float angle, float escala) {
// 1. Centrar el punt respecte al centre de la forma // 1. Centrar el punt respecte al centre de la forma
float centered_x = point.x - shape_centre.x; float centered_x = point.x - shape_centre.x;
float centered_y = point.y - shape_centre.y; float centered_y = point.y - shape_centre.y;
@@ -33,7 +34,8 @@ static Punt transform_point(const Punt &point, const Punt &shape_centre,
return {rotated_x + posicio.x, rotated_y + posicio.y}; return {rotated_x + posicio.x, rotated_y + posicio.y};
} }
DebrisManager::DebrisManager(SDL_Renderer *renderer) : renderer_(renderer) { DebrisManager::DebrisManager(SDL_Renderer* renderer)
: renderer_(renderer) {
// Inicialitzar tots els debris com inactius // Inicialitzar tots els debris com inactius
for (auto& debris : debris_pool_) { for (auto& debris : debris_pool_) {
debris.actiu = false; debris.actiu = false;
@@ -41,7 +43,9 @@ DebrisManager::DebrisManager(SDL_Renderer *renderer) : renderer_(renderer) {
} }
void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape, void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
const Punt &centre, float angle, float escala, const Punt& centre,
float angle,
float escala,
float velocitat_base) { float velocitat_base) {
if (!shape || !shape->es_valida()) { if (!shape || !shape->es_valida()) {
return; return;
@@ -199,10 +203,7 @@ void DebrisManager::dibuixar() const {
continue; continue;
// Dibuixar segment de línia // Dibuixar segment de línia
Rendering::linea(renderer_, static_cast<int>(debris.p1.x), Rendering::linea(renderer_, static_cast<int>(debris.p1.x), static_cast<int>(debris.p1.y), static_cast<int>(debris.p2.x), static_cast<int>(debris.p2.y), true);
static_cast<int>(debris.p1.y),
static_cast<int>(debris.p2.x),
static_cast<int>(debris.p2.y), true);
} }
} }

View File

@@ -2,13 +2,15 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#pragma once #pragma once
#include "debris.hpp"
#include "core/graphics/shape.hpp"
#include "core/types.hpp"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <array> #include <array>
#include <memory> #include <memory>
#include "core/graphics/shape.hpp"
#include "core/types.hpp"
#include "debris.hpp"
namespace Effects { namespace Effects {
// Gestor de fragments d'explosions // Gestor de fragments d'explosions
@@ -24,7 +26,9 @@ public:
// - escala: escala de l'objecte (1.0 = normal) // - escala: escala de l'objecte (1.0 = normal)
// - velocitat_base: velocitat inicial dels fragments (px/s) // - velocitat_base: velocitat inicial dels fragments (px/s)
void explotar(const std::shared_ptr<Graphics::Shape>& shape, void explotar(const std::shared_ptr<Graphics::Shape>& shape,
const Punt &centre, float angle, float escala, const Punt& centre,
float angle,
float escala,
float velocitat_base); float velocitat_base);
// Actualitzar tots els fragments actius // Actualitzar tots els fragments actius

View File

@@ -3,16 +3,20 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "game/entities/bala.hpp" #include "game/entities/bala.hpp"
#include "core/graphics/shape_loader.hpp"
#include "core/rendering/shape_renderer.hpp"
#include "game/constants.hpp"
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
Bala::Bala(SDL_Renderer *renderer) #include "core/graphics/shape_loader.hpp"
: renderer_(renderer), centre_({0.0f, 0.0f}), angle_(0.0f), #include "core/rendering/shape_renderer.hpp"
velocitat_(0.0f), esta_(false) { #include "game/constants.hpp"
Bala::Bala(SDL_Renderer* renderer)
: renderer_(renderer),
centre_({0.0f, 0.0f}),
angle_(0.0f),
velocitat_(0.0f),
esta_(false) {
// [NUEVO] Carregar forma compartida des de fitxer // [NUEVO] Carregar forma compartida des de fitxer
forma_ = Graphics::ShapeLoader::load("bullet.shp"); forma_ = Graphics::ShapeLoader::load("bullet.shp");

View File

@@ -3,14 +3,17 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#pragma once #pragma once
#include <SDL3/SDL.h>
#include <memory>
#include "core/graphics/shape.hpp" #include "core/graphics/shape.hpp"
#include "core/types.hpp" #include "core/types.hpp"
#include <SDL3/SDL.h>
#include <memory>
class Bala { class Bala {
public: public:
Bala() : renderer_(nullptr) {} Bala()
: renderer_(nullptr) {}
Bala(SDL_Renderer* renderer); Bala(SDL_Renderer* renderer);
void inicialitzar(); void inicialitzar();

View File

@@ -3,17 +3,23 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "game/entities/enemic.hpp" #include "game/entities/enemic.hpp"
#include "core/graphics/shape_loader.hpp"
#include "core/rendering/shape_renderer.hpp"
#include "game/constants.hpp"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
Enemic::Enemic(SDL_Renderer *renderer) #include "core/graphics/shape_loader.hpp"
: renderer_(renderer), centre_({0.0f, 0.0f}), angle_(0.0f), #include "core/rendering/shape_renderer.hpp"
velocitat_(0.0f), drotacio_(0.0f), rotacio_(0.0f), esta_(false) { #include "game/constants.hpp"
Enemic::Enemic(SDL_Renderer* renderer)
: renderer_(renderer),
centre_({0.0f, 0.0f}),
angle_(0.0f),
velocitat_(0.0f),
drotacio_(0.0f),
rotacio_(0.0f),
esta_(false) {
// [NUEVO] Carregar forma compartida des de fitxer // [NUEVO] Carregar forma compartida des de fitxer
forma_ = Graphics::ShapeLoader::load("enemy_pentagon.shp"); forma_ = Graphics::ShapeLoader::load("enemy_pentagon.shp");

View File

@@ -3,14 +3,17 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#pragma once #pragma once
#include <SDL3/SDL.h>
#include <memory>
#include "core/graphics/shape.hpp" #include "core/graphics/shape.hpp"
#include "core/types.hpp" #include "core/types.hpp"
#include <SDL3/SDL.h>
#include <memory>
class Enemic { class Enemic {
public: public:
Enemic() : renderer_(nullptr) {} Enemic()
: renderer_(nullptr) {}
Enemic(SDL_Renderer* renderer); Enemic(SDL_Renderer* renderer);
void inicialitzar(); void inicialitzar();

View File

@@ -3,18 +3,23 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "game/entities/nau.hpp" #include "game/entities/nau.hpp"
#include <SDL3/SDL.h>
#include <cmath>
#include <iostream>
#include "core/defaults.hpp" #include "core/defaults.hpp"
#include "core/graphics/shape_loader.hpp" #include "core/graphics/shape_loader.hpp"
#include "core/rendering/shape_renderer.hpp" #include "core/rendering/shape_renderer.hpp"
#include "game/constants.hpp" #include "game/constants.hpp"
#include <SDL3/SDL.h>
#include <cmath>
#include <iostream>
Nau::Nau(SDL_Renderer* renderer) Nau::Nau(SDL_Renderer* renderer)
: renderer_(renderer), centre_({0.0f, 0.0f}), angle_(0.0f), : renderer_(renderer),
velocitat_(0.0f), esta_tocada_(false) { centre_({0.0f, 0.0f}),
angle_(0.0f),
velocitat_(0.0f),
esta_tocada_(false) {
// [NUEVO] Carregar forma compartida des de fitxer // [NUEVO] Carregar forma compartida des de fitxer
forma_ = Graphics::ShapeLoader::load("ship.shp"); forma_ = Graphics::ShapeLoader::load("ship.shp");

View File

@@ -3,14 +3,17 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#pragma once #pragma once
#include <SDL3/SDL.h>
#include <memory>
#include "core/graphics/shape.hpp" #include "core/graphics/shape.hpp"
#include "core/types.hpp" #include "core/types.hpp"
#include <SDL3/SDL.h>
#include <memory>
class Nau { class Nau {
public: public:
Nau() : renderer_(nullptr) {} Nau()
: renderer_(nullptr) {}
Nau(SDL_Renderer* renderer); Nau(SDL_Renderer* renderer);
void inicialitzar(); void inicialitzar();

View File

@@ -3,18 +3,23 @@
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "escena_joc.hpp" #include "escena_joc.hpp"
#include "../../core/rendering/line_renderer.hpp"
#include "../../core/system/gestor_escenes.hpp"
#include "../../core/system/global_events.hpp"
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "../../core/rendering/line_renderer.hpp"
#include "../../core/system/gestor_escenes.hpp"
#include "../../core/system/global_events.hpp"
EscenaJoc::EscenaJoc(SDLManager& sdl) EscenaJoc::EscenaJoc(SDLManager& sdl)
: sdl_(sdl), debris_manager_(sdl.obte_renderer()), : sdl_(sdl),
nau_(sdl.obte_renderer()), itocado_(0), text_(sdl.obte_renderer()) { debris_manager_(sdl.obte_renderer()),
nau_(sdl.obte_renderer()),
itocado_(0),
text_(sdl.obte_renderer()) {
// Inicialitzar bales amb renderer // Inicialitzar bales amb renderer
for (auto& bala : bales_) { for (auto& bala : bales_) {
bala = Bala(sdl.obte_renderer()); bala = Bala(sdl.obte_renderer());

View File

@@ -5,17 +5,19 @@
#ifndef ESCENA_JOC_HPP #ifndef ESCENA_JOC_HPP
#define ESCENA_JOC_HPP #define ESCENA_JOC_HPP
#include <SDL3/SDL.h>
#include <array>
#include <cstdint>
#include "../../core/graphics/vector_text.hpp" #include "../../core/graphics/vector_text.hpp"
#include "../../core/rendering/sdl_manager.hpp" #include "../../core/rendering/sdl_manager.hpp"
#include "../effects/debris_manager.hpp"
#include "../../core/types.hpp" #include "../../core/types.hpp"
#include "../constants.hpp" #include "../constants.hpp"
#include "../effects/debris_manager.hpp"
#include "../entities/bala.hpp" #include "../entities/bala.hpp"
#include "../entities/enemic.hpp" #include "../entities/enemic.hpp"
#include "../entities/nau.hpp" #include "../entities/nau.hpp"
#include <SDL3/SDL.h>
#include <array>
#include <cstdint>
// Classe principal del joc (escena) // Classe principal del joc (escena)
class EscenaJoc { class EscenaJoc {

View File

@@ -2,18 +2,19 @@
// © 2025 Port a C++20 // © 2025 Port a C++20
#include "escena_logo.hpp" #include "escena_logo.hpp"
#include "../../core/graphics/shape_loader.hpp"
#include "../../core/rendering/shape_renderer.hpp"
#include "../../core/system/gestor_escenes.hpp"
#include "../../core/system/global_events.hpp"
#include <algorithm> #include <algorithm>
#include <cfloat> #include <cfloat>
#include <iostream> #include <iostream>
#include "../../core/graphics/shape_loader.hpp"
#include "../../core/rendering/shape_renderer.hpp"
#include "../../core/system/gestor_escenes.hpp"
#include "../../core/system/global_events.hpp"
// Helper: calcular el progrés individual d'una lletra // Helper: calcular el progrés individual d'una lletra
// en funció del progrés global (efecte seqüencial) // en funció del progrés global (efecte seqüencial)
static float calcular_progress_letra(size_t letra_index, size_t num_letras, static float calcular_progress_letra(size_t letra_index, size_t num_letras, float global_progress, float threshold) {
float global_progress, float threshold) {
if (num_letras == 0) if (num_letras == 0)
return 1.0f; return 1.0f;
@@ -34,8 +35,12 @@ static float calcular_progress_letra(size_t letra_index, size_t num_letras,
} }
EscenaLogo::EscenaLogo(SDLManager& sdl) EscenaLogo::EscenaLogo(SDLManager& sdl)
: sdl_(sdl), estat_actual_(EstatAnimacio::PRE_ANIMATION), : sdl_(sdl),
temps_estat_actual_(0.0f) { estat_actual_(EstatAnimacio::PRE_ANIMATION),
temps_estat_actual_(0.0f),
debris_manager_(std::make_unique<Effects::DebrisManager>(sdl.obte_renderer())),
lletra_explosio_index_(0),
temps_des_ultima_explosio_(0.0f) {
std::cout << "Escena Logo: Inicialitzant...\n"; std::cout << "Escena Logo: Inicialitzant...\n";
inicialitzar_lletres(); inicialitzar_lletres();
} }
@@ -89,9 +94,15 @@ void EscenaLogo::inicialitzar_lletres() {
// Llista de fitxers .shp (A repetida per a les dues A's) // Llista de fitxers .shp (A repetida per a les dues A's)
std::vector<std::string> fitxers = { std::vector<std::string> fitxers = {
"logo/letra_j.shp", "logo/letra_a.shp", "logo/letra_i.shp", "logo/letra_j.shp",
"logo/letra_l.shp", "logo/letra_g.shp", "logo/letra_a.shp", "logo/letra_a.shp",
"logo/letra_m.shp", "logo/letra_e.shp", "logo/letra_s.shp"}; "logo/letra_i.shp",
"logo/letra_l.shp",
"logo/letra_g.shp",
"logo/letra_a.shp",
"logo/letra_m.shp",
"logo/letra_e.shp",
"logo/letra_s.shp"};
// Pas 1: Carregar totes les formes i calcular amplades // Pas 1: Carregar totes les formes i calcular amplades
float ancho_total = 0.0f; float ancho_total = 0.0f;
@@ -160,6 +171,13 @@ void EscenaLogo::inicialitzar_lletres() {
void EscenaLogo::canviar_estat(EstatAnimacio nou_estat) { void EscenaLogo::canviar_estat(EstatAnimacio nou_estat) {
estat_actual_ = nou_estat; estat_actual_ = nou_estat;
temps_estat_actual_ = 0.0f; // Reset temps temps_estat_actual_ = 0.0f; // Reset temps
// Inicialitzar estat d'explosió
if (nou_estat == EstatAnimacio::EXPLOSION) {
lletra_explosio_index_ = 0;
temps_des_ultima_explosio_ = 0.0f;
}
std::cout << "[EscenaLogo] Canvi a estat: " << static_cast<int>(nou_estat) std::cout << "[EscenaLogo] Canvi a estat: " << static_cast<int>(nou_estat)
<< "\n"; << "\n";
} }
@@ -169,6 +187,35 @@ bool EscenaLogo::totes_lletres_completes() const {
return temps_estat_actual_ >= DURACIO_ZOOM; return temps_estat_actual_ >= DURACIO_ZOOM;
} }
void EscenaLogo::actualitzar_explosions(float delta_time) {
temps_des_ultima_explosio_ += delta_time;
// Comprovar si és el moment d'explotar la següent lletra
if (temps_des_ultima_explosio_ >= DELAY_ENTRE_EXPLOSIONS) {
if (lletra_explosio_index_ < lletres_.size()) {
// Explotar lletra actual
const auto& lletra = lletres_[lletra_explosio_index_];
debris_manager_->explotar(
lletra.forma, // Forma a explotar
lletra.posicio, // Posició
0.0f, // Angle (sense rotació)
ESCALA_FINAL, // Escala (lletres a escala final)
VELOCITAT_EXPLOSIO // Velocitat base
);
std::cout << "[EscenaLogo] Explota lletra " << lletra_explosio_index_ << "\n";
// Passar a la següent lletra
lletra_explosio_index_++;
temps_des_ultima_explosio_ = 0.0f;
} else {
// Totes les lletres han explotat, transició a POST_EXPLOSION
canviar_estat(EstatAnimacio::POST_EXPLOSION);
}
}
}
void EscenaLogo::actualitzar(float delta_time) { void EscenaLogo::actualitzar(float delta_time) {
temps_estat_actual_ += delta_time; temps_estat_actual_ += delta_time;
@@ -186,11 +233,24 @@ void EscenaLogo::actualitzar(float delta_time) {
break; break;
case EstatAnimacio::POST_ANIMATION: case EstatAnimacio::POST_ANIMATION:
if (temps_estat_actual_ >= DURACIO_POST) { if (temps_estat_actual_ >= DURACIO_POST_ANIMATION) {
canviar_estat(EstatAnimacio::EXPLOSION);
}
break;
case EstatAnimacio::EXPLOSION:
actualitzar_explosions(delta_time);
break;
case EstatAnimacio::POST_EXPLOSION:
if (temps_estat_actual_ >= DURACIO_POST_EXPLOSION) {
GestorEscenes::actual = GestorEscenes::Escena::JOC; GestorEscenes::actual = GestorEscenes::Escena::JOC;
} }
break; break;
} }
// Actualitzar animacions de debris
debris_manager_->actualitzar(delta_time);
} }
void EscenaLogo::dibuixar() { void EscenaLogo::dibuixar() {
@@ -203,53 +263,71 @@ void EscenaLogo::dibuixar() {
return; // No renderitzar lletres return; // No renderitzar lletres
} }
// ANIMATION o POST_ANIMATION: Calcular progrés // ANIMATION o POST_ANIMATION: Dibuixar lletres amb animació
if (estat_actual_ == EstatAnimacio::ANIMATION ||
estat_actual_ == EstatAnimacio::POST_ANIMATION) {
float global_progress = float global_progress =
(estat_actual_ == EstatAnimacio::ANIMATION) (estat_actual_ == EstatAnimacio::ANIMATION)
? std::min(temps_estat_actual_ / DURACIO_ZOOM, 1.0f) ? std::min(temps_estat_actual_ / DURACIO_ZOOM, 1.0f)
: 1.0f; // POST: mantenir al 100% : 1.0f; // POST: mantenir al 100%
// Punt inicial del zoom (configurable amb ORIGEN_ZOOM_X/Y)
const Punt ORIGEN_ZOOM = {ORIGEN_ZOOM_X, ORIGEN_ZOOM_Y}; const Punt ORIGEN_ZOOM = {ORIGEN_ZOOM_X, ORIGEN_ZOOM_Y};
// Dibuixar cada lletra amb animació seqüencial
for (size_t i = 0; i < lletres_.size(); i++) { for (size_t i = 0; i < lletres_.size(); i++) {
const auto& lletra = lletres_[i]; const auto& lletra = lletres_[i];
// Calcular progrés individual d'aquesta lletra (0.0 → 1.0)
float letra_progress = calcular_progress_letra( float letra_progress = calcular_progress_letra(
i, lletres_.size(), global_progress, THRESHOLD_LETRA); i,
lletres_.size(),
global_progress,
THRESHOLD_LETRA);
// Si la lletra encara no ha començat, saltar-la
if (letra_progress <= 0.0f) { if (letra_progress <= 0.0f) {
continue; continue;
} }
// Interpolar posició: des del origen zoom cap a posició final
Punt pos_actual; Punt pos_actual;
pos_actual.x = pos_actual.x =
ORIGEN_ZOOM.x + (lletra.posicio.x - ORIGEN_ZOOM.x) * letra_progress; ORIGEN_ZOOM.x + (lletra.posicio.x - ORIGEN_ZOOM.x) * letra_progress;
pos_actual.y = pos_actual.y =
ORIGEN_ZOOM.y + (lletra.posicio.y - ORIGEN_ZOOM.y) * letra_progress; ORIGEN_ZOOM.y + (lletra.posicio.y - ORIGEN_ZOOM.y) * letra_progress;
// Aplicar ease-out quadràtic per suavitat
float t = letra_progress; float t = letra_progress;
float ease_factor = 1.0f - (1.0f - t) * (1.0f - t); float ease_factor = 1.0f - (1.0f - t) * (1.0f - t);
// Interpolar escala amb ease-out: des de ESCALA_INICIAL cap a ESCALA_FINAL
float escala_actual = float escala_actual =
ESCALA_INICIAL + (ESCALA_FINAL - ESCALA_INICIAL) * ease_factor; ESCALA_INICIAL + (ESCALA_FINAL - ESCALA_INICIAL) * ease_factor;
// Renderitzar la lletra
Rendering::render_shape( Rendering::render_shape(
sdl_.obte_renderer(), lletra.forma, sdl_.obte_renderer(),
pos_actual, // Posició interpolada lletra.forma,
0.0f, // Sense rotació pos_actual,
escala_actual, // Escala interpolada amb ease-out 0.0f,
true, // Dibuixar escala_actual,
1.0f // Progress = 1.0 (lletra completa, sense animació de primitives) true,
); 1.0f);
} }
}
// EXPLOSION: Dibuixar només lletres que encara no han explotat
if (estat_actual_ == EstatAnimacio::EXPLOSION) {
for (size_t i = lletra_explosio_index_; i < lletres_.size(); i++) {
const auto& lletra = lletres_[i];
Rendering::render_shape(
sdl_.obte_renderer(),
lletra.forma,
lletra.posicio,
0.0f,
ESCALA_FINAL,
true,
1.0f);
}
}
// POST_EXPLOSION: No dibuixar lletres, només debris (a baix)
// Sempre dibuixar debris (si n'hi ha d'actius)
debris_manager_->dibuixar();
sdl_.presenta(); sdl_.presenta();
} }

View File

@@ -4,12 +4,15 @@
#pragma once #pragma once
#include <SDL3/SDL.h>
#include <memory>
#include <vector>
#include "../../core/graphics/shape.hpp" #include "../../core/graphics/shape.hpp"
#include "../../core/rendering/sdl_manager.hpp" #include "../../core/rendering/sdl_manager.hpp"
#include "../../core/types.hpp" #include "../../core/types.hpp"
#include <SDL3/SDL.h> #include "../effects/debris_manager.hpp"
#include <memory>
#include <vector>
class EscenaLogo { class EscenaLogo {
public: public:
@@ -21,7 +24,9 @@ private:
enum class EstatAnimacio { enum class EstatAnimacio {
PRE_ANIMATION, // Pantalla negra inicial PRE_ANIMATION, // Pantalla negra inicial
ANIMATION, // Animació de zoom de lletres ANIMATION, // Animació de zoom de lletres
POST_ANIMATION // Logo complet visible POST_ANIMATION, // Logo complet visible
EXPLOSION, // Explosió seqüencial de lletres
POST_EXPLOSION // Espera després de l'última explosió
}; };
SDLManager& sdl_; SDLManager& sdl_;
@@ -29,6 +34,13 @@ private:
float float
temps_estat_actual_; // Temps en l'estat actual (reset en cada transició) temps_estat_actual_; // Temps en l'estat 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
float temps_des_ultima_explosio_; // Temps des de l'última explosió
// Estructura per a cada lletra del logo // Estructura per a cada lletra del logo
struct LetraLogo { struct LetraLogo {
std::shared_ptr<Graphics::Shape> forma; std::shared_ptr<Graphics::Shape> forma;
@@ -40,26 +52,25 @@ private:
std::vector<LetraLogo> lletres_; // 9 lletres: J-A-I-L-G-A-M-E-S std::vector<LetraLogo> lletres_; // 9 lletres: J-A-I-L-G-A-M-E-S
// Constants d'animació // Constants d'animació
static constexpr float DURACIO_PRE = static constexpr float DURACIO_PRE = 1.5f; // Duració PRE_ANIMATION (pantalla negra)
1.5f; // Duració PRE_ANIMATION (pantalla negra)
static constexpr float DURACIO_ZOOM = 4.0f; // Duració del zoom (segons) static constexpr float DURACIO_ZOOM = 4.0f; // Duració del zoom (segons)
static constexpr float DURACIO_POST = static constexpr float DURACIO_POST_ANIMATION = 3.0f; // Duració POST_ANIMATION (logo complet)
4.0f; // Duració POST_ANIMATION (logo complet) static constexpr float DURACIO_POST_EXPLOSION = 3.0f; // Duració POST_EXPLOSION (espera final)
static constexpr float DELAY_ENTRE_EXPLOSIONS = 1.0f; // Temps entre explosions de lletres
static constexpr float VELOCITAT_EXPLOSIO = 80.0f; // Velocitat base fragments (px/s)
static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%) static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%)
static constexpr float ESCALA_FINAL = 0.8f; // Escala final (80%) static constexpr float ESCALA_FINAL = 0.8f; // Escala final (80%)
static constexpr float ESPAI_ENTRE_LLETRES = 10.0f; // Espaiat entre lletres static constexpr float ESPAI_ENTRE_LLETRES = 10.0f; // Espaiat entre lletres
// Constants d'animació seqüencial // Constants d'animació seqüencial
static constexpr float THRESHOLD_LETRA = static constexpr float THRESHOLD_LETRA = 0.6f; // Umbral per activar següent lletra (0.0-1.0)
0.6f; // Umbral per activar següent lletra (0.0-1.0) static constexpr float ORIGEN_ZOOM_X = 640.0f / 2.0f; // Punt inicial X del zoom (320)
static constexpr float ORIGEN_ZOOM_X = static constexpr float ORIGEN_ZOOM_Y = 480.0f * 0.4f; // Punt inicial Y del zoom (240)
640.0f / 2.0f; // Punt inicial X del zoom (320)
static constexpr float ORIGEN_ZOOM_Y =
480.0f * 0.4f; // Punt inicial Y del zoom (240)
// Mètodes privats // Mètodes privats
void inicialitzar_lletres(); void inicialitzar_lletres();
void actualitzar(float delta_time); void actualitzar(float delta_time);
void actualitzar_explosions(float delta_time);
void dibuixar(); void dibuixar();
void processar_events(const SDL_Event& event); void processar_events(const SDL_Event& event);

View File

@@ -1,12 +1,13 @@
#include "options.hpp" #include "options.hpp"
#include "../core/defaults.hpp"
#include "../external/fkyaml_node.hpp"
#include "project.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "../core/defaults.hpp"
#include "../external/fkyaml_node.hpp"
#include "project.h"
namespace Options { namespace Options {
// Inicialitzar opcions amb valors per defecte de Defaults:: // Inicialitzar opcions amb valors per defecte de Defaults::

View File

@@ -1,4 +1,5 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@@ -2,10 +2,11 @@
// © 1999 Visente i Sergi (versió Pascal) // © 1999 Visente i Sergi (versió Pascal)
// © 2025 Port a C++20 amb SDL3 // © 2025 Port a C++20 amb SDL3
#include "core/system/director.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
#include "core/system/director.hpp"
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Convertir arguments a std::vector<std::string> // Convertir arguments a std::vector<std::string>
std::vector<std::string> args(argv, argv + argc); std::vector<std::string> args(argv, argv + argc);