treballant en el starfield
This commit is contained in:
@@ -45,6 +45,7 @@ set(APP_SOURCES
|
|||||||
source/core/graphics/shape.cpp
|
source/core/graphics/shape.cpp
|
||||||
source/core/graphics/shape_loader.cpp
|
source/core/graphics/shape_loader.cpp
|
||||||
source/core/graphics/vector_text.cpp
|
source/core/graphics/vector_text.cpp
|
||||||
|
source/core/graphics/starfield.cpp
|
||||||
source/core/audio/audio.cpp
|
source/core/audio/audio.cpp
|
||||||
source/core/audio/audio_cache.cpp
|
source/core/audio/audio_cache.cpp
|
||||||
source/game/options.cpp
|
source/game/options.cpp
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -47,6 +47,7 @@ APP_SOURCES := \
|
|||||||
source/core/graphics/shape.cpp \
|
source/core/graphics/shape.cpp \
|
||||||
source/core/graphics/shape_loader.cpp \
|
source/core/graphics/shape_loader.cpp \
|
||||||
source/core/graphics/vector_text.cpp \
|
source/core/graphics/vector_text.cpp \
|
||||||
|
source/core/graphics/starfield.cpp \
|
||||||
source/game/options.cpp \
|
source/game/options.cpp \
|
||||||
source/game/escenes/escena_logo.cpp \
|
source/game/escenes/escena_logo.cpp \
|
||||||
source/game/escenes/escena_titol.cpp \
|
source/game/escenes/escena_titol.cpp \
|
||||||
|
|||||||
19
data/shapes/star.shp
Normal file
19
data/shapes/star.shp
Normal file
@@ -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
|
||||||
@@ -17,6 +17,24 @@ EscenaTitol::EscenaTitol(SDLManager& sdl)
|
|||||||
estat_actual_(EstatTitol::INIT),
|
estat_actual_(EstatTitol::INIT),
|
||||||
temps_acumulat_(0.0f) {
|
temps_acumulat_(0.0f) {
|
||||||
std::cout << "Escena Titol: Inicialitzant...\n";
|
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<float>(Defaults::Game::WIDTH),
|
||||||
|
static_cast<float>(Defaults::Game::HEIGHT)};
|
||||||
|
|
||||||
|
starfield_ = std::make_unique<Graphics::Starfield>(
|
||||||
|
sdl_.obte_renderer(),
|
||||||
|
centre_pantalla,
|
||||||
|
area_completa,
|
||||||
|
100, // densitat: 100 estrelles
|
||||||
|
30.0f // velocitat base: 30 px/s
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EscenaTitol::executar() {
|
void EscenaTitol::executar() {
|
||||||
@@ -76,6 +94,11 @@ void EscenaTitol::executar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EscenaTitol::actualitzar(float delta_time) {
|
void EscenaTitol::actualitzar(float delta_time) {
|
||||||
|
// Actualitzar starfield (sempre actiu)
|
||||||
|
if (starfield_) {
|
||||||
|
starfield_->actualitzar(delta_time);
|
||||||
|
}
|
||||||
|
|
||||||
switch (estat_actual_) {
|
switch (estat_actual_) {
|
||||||
case EstatTitol::INIT:
|
case EstatTitol::INIT:
|
||||||
temps_acumulat_ += delta_time;
|
temps_acumulat_ += delta_time;
|
||||||
@@ -90,12 +113,17 @@ void EscenaTitol::actualitzar(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EscenaTitol::dibuixar() {
|
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) {
|
if (estat_actual_ == EstatTitol::INIT) {
|
||||||
return;
|
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) {
|
if (estat_actual_ == EstatTitol::MAIN) {
|
||||||
// Text principal centrat (vertical i horitzontalment)
|
// Text principal centrat (vertical i horitzontalment)
|
||||||
const std::string main_text = "PRESS BUTTON TO PLAY";
|
const std::string main_text = "PRESS BUTTON TO PLAY";
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "../../core/graphics/starfield.hpp"
|
||||||
#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 "core/defaults.hpp"
|
#include "core/defaults.hpp"
|
||||||
@@ -23,9 +26,10 @@ class EscenaTitol {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SDLManager& sdl_;
|
SDLManager& sdl_;
|
||||||
Graphics::VectorText text_; // Sistema de text vectorial
|
Graphics::VectorText text_; // Sistema de text vectorial
|
||||||
EstatTitol estat_actual_; // Estat actual de la màquina
|
std::unique_ptr<Graphics::Starfield> starfield_; // Camp d'estrelles de fons
|
||||||
float temps_acumulat_; // Temps acumulat per l'estat INIT
|
EstatTitol estat_actual_; // Estat actual de la màquina
|
||||||
|
float temps_acumulat_; // Temps acumulat per l'estat INIT
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
static constexpr float DURACIO_INIT = 2.0f; // Duració de l'estat INIT (2 segons)
|
static constexpr float DURACIO_INIT = 2.0f; // Duració de l'estat INIT (2 segons)
|
||||||
|
|||||||
Reference in New Issue
Block a user