From 98c90e6075833e27ca1882a07af5109affe562dd Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 2 Dec 2025 21:19:43 +0100 Subject: [PATCH] treballant en el starfield --- CMakeLists.txt | 1 + Makefile | 1 + data/shapes/star.shp | 19 +++++++++++++++++ source/game/escenes/escena_titol.cpp | 32 ++++++++++++++++++++++++++-- source/game/escenes/escena_titol.hpp | 10 ++++++--- 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 data/shapes/star.shp diff --git a/CMakeLists.txt b/CMakeLists.txt index a2ec0dc..d497514 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(APP_SOURCES source/core/graphics/shape.cpp source/core/graphics/shape_loader.cpp source/core/graphics/vector_text.cpp + source/core/graphics/starfield.cpp source/core/audio/audio.cpp source/core/audio/audio_cache.cpp source/game/options.cpp diff --git a/Makefile b/Makefile index 8bbf43b..c8dfd7a 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,7 @@ APP_SOURCES := \ source/core/graphics/shape.cpp \ source/core/graphics/shape_loader.cpp \ source/core/graphics/vector_text.cpp \ + source/core/graphics/starfield.cpp \ source/game/options.cpp \ source/game/escenes/escena_logo.cpp \ source/game/escenes/escena_titol.cpp \ diff --git a/data/shapes/star.shp b/data/shapes/star.shp new file mode 100644 index 0000000..749de82 --- /dev/null +++ b/data/shapes/star.shp @@ -0,0 +1,19 @@ +# star.shp - Estrella per a starfield +# © 2025 Orni Attack + +name: star +scale: 1.0 +center: 0, 0 + +# Estrella de 4 puntes (diamant/creu) +# Petita i simple per a l'efecte starfield +# +# Punts: +# angle=0°: (0, -3) Dalt +# angle=90°: (3, 0) Dreta +# angle=180°: (0, 3) Baix +# angle=270°: (-3, 0) Esquerra +# +# Forma de diamant amb línies de centre a puntes + +polyline: 0,-3 3,0 0,3 -3,0 0,-3 diff --git a/source/game/escenes/escena_titol.cpp b/source/game/escenes/escena_titol.cpp index 6029706..02be840 100644 --- a/source/game/escenes/escena_titol.cpp +++ b/source/game/escenes/escena_titol.cpp @@ -17,6 +17,24 @@ EscenaTitol::EscenaTitol(SDLManager& sdl) estat_actual_(EstatTitol::INIT), temps_acumulat_(0.0f) { std::cout << "Escena Titol: Inicialitzant...\n"; + + // Crear starfield de fons + Punt centre_pantalla{ + Defaults::Game::WIDTH / 2.0f, + Defaults::Game::HEIGHT / 2.0f}; + + SDL_FRect area_completa{ + 0, 0, + static_cast(Defaults::Game::WIDTH), + static_cast(Defaults::Game::HEIGHT)}; + + starfield_ = std::make_unique( + sdl_.obte_renderer(), + centre_pantalla, + area_completa, + 100, // densitat: 100 estrelles + 30.0f // velocitat base: 30 px/s + ); } void EscenaTitol::executar() { @@ -76,6 +94,11 @@ void EscenaTitol::executar() { } void EscenaTitol::actualitzar(float delta_time) { + // Actualitzar starfield (sempre actiu) + if (starfield_) { + starfield_->actualitzar(delta_time); + } + switch (estat_actual_) { case EstatTitol::INIT: temps_acumulat_ += delta_time; @@ -90,12 +113,17 @@ void EscenaTitol::actualitzar(float delta_time) { } void EscenaTitol::dibuixar() { - // En l'estat INIT, no dibuixar res (pantalla negra) + // Dibuixar starfield de fons (sempre, en tots els estats) + if (starfield_) { + starfield_->dibuixar(); + } + + // En l'estat INIT, només mostrar starfield (sense text) if (estat_actual_ == EstatTitol::INIT) { return; } - // Estat MAIN: Dibuixar text de títol i copyright + // Estat MAIN: Dibuixar text de títol i copyright (sobre el starfield) if (estat_actual_ == EstatTitol::MAIN) { // Text principal centrat (vertical i horitzontalment) const std::string main_text = "PRESS BUTTON TO PLAY"; diff --git a/source/game/escenes/escena_titol.hpp b/source/game/escenes/escena_titol.hpp index f010a58..3646027 100644 --- a/source/game/escenes/escena_titol.hpp +++ b/source/game/escenes/escena_titol.hpp @@ -6,6 +6,9 @@ #include +#include + +#include "../../core/graphics/starfield.hpp" #include "../../core/graphics/vector_text.hpp" #include "../../core/rendering/sdl_manager.hpp" #include "core/defaults.hpp" @@ -23,9 +26,10 @@ class EscenaTitol { }; SDLManager& sdl_; - Graphics::VectorText text_; // Sistema de text vectorial - EstatTitol estat_actual_; // Estat actual de la màquina - float temps_acumulat_; // Temps acumulat per l'estat INIT + Graphics::VectorText text_; // Sistema de text vectorial + std::unique_ptr starfield_; // Camp d'estrelles de fons + EstatTitol estat_actual_; // Estat actual de la màquina + float temps_acumulat_; // Temps acumulat per l'estat INIT // Constants static constexpr float DURACIO_INIT = 2.0f; // Duració de l'estat INIT (2 segons)