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:
@@ -30,7 +30,7 @@ JA_Sound_t* AudioCache::getSound(const std::string& name) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ JA_Music_t* AudioCache::getMusic(const std::string& name) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -107,7 +107,7 @@ constexpr float ENEMY_RADIUS = 20.0F;
|
||||
constexpr float BULLET_RADIUS = 3.0F;
|
||||
} // namespace Entities
|
||||
|
||||
// Ship (nave del jugador)
|
||||
// Ship (nave del player)
|
||||
namespace Ship {
|
||||
// Invulnerabilidad post-respawn
|
||||
constexpr float INVULNERABILITY_DURATION = 3.0F; // Segundos de invulnerabilidad
|
||||
@@ -151,11 +151,11 @@ constexpr float INIT_HUD_RECT_RATIO_END = 0.85F;
|
||||
constexpr float INIT_HUD_SCORE_RATIO_INIT = 0.60F;
|
||||
constexpr float INIT_HUD_SCORE_RATIO_END = 0.90F;
|
||||
|
||||
// SHIP1 (nave jugador 1)
|
||||
// SHIP1 (nave player 1)
|
||||
constexpr float INIT_HUD_SHIP1_RATIO_INIT = 0.0F;
|
||||
constexpr float INIT_HUD_SHIP1_RATIO_END = 1.0F;
|
||||
|
||||
// SHIP2 (nave jugador 2)
|
||||
// SHIP2 (nave player 2)
|
||||
constexpr float INIT_HUD_SHIP2_RATIO_INIT = 0.20F;
|
||||
constexpr float INIT_HUD_SHIP2_RATIO_END = 1.0F;
|
||||
|
||||
@@ -220,7 +220,7 @@ constexpr float TEMPS_VIDA = 2.0F; // Duració màxima (segons) - enem
|
||||
constexpr float TEMPS_VIDA_NAU = 3.0F; // Ship debris lifetime (matches DEATH_DURATION)
|
||||
constexpr float SHRINK_RATE = 0.5F; // Reducció de mida (factor/s)
|
||||
|
||||
// Herència de velocitat angular (trayectorias curvas)
|
||||
// Herència de velocity angular (trayectorias curvas)
|
||||
constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat
|
||||
constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat
|
||||
constexpr float FRICCIO_ANGULAR = 0.5F; // Desacceleració angular (rad/s²)
|
||||
@@ -261,10 +261,10 @@ constexpr uint8_t BACKGROUND_MAX_G = 15;
|
||||
constexpr uint8_t BACKGROUND_MAX_B = 0;
|
||||
} // namespace Color
|
||||
|
||||
// Brillantor (control de intensitat per cada tipus d'entitat)
|
||||
// Brillantor (control de intensitat per cada type d'entitat)
|
||||
namespace Brightness {
|
||||
// Brillantor estàtica per entitats de joc (0.0-1.0)
|
||||
constexpr float NAU = 1.0F; // Màxima visibilitat (jugador)
|
||||
constexpr float NAU = 1.0F; // Màxima visibilitat (player)
|
||||
constexpr float ENEMIC = 0.7F; // 30% més tènue (destaca menys)
|
||||
constexpr float BALA = 1.0F; // Brillo a tope (màxima visibilitat)
|
||||
|
||||
@@ -306,7 +306,7 @@ constexpr const char* FRIENDLY_FIRE_HIT = "effects/friendly_fire.wav"; //
|
||||
constexpr const char* INIT_HUD = "effects/init_hud.wav"; // Para la animación del HUD
|
||||
constexpr const char* LASER = "effects/laser_shoot.wav"; // Disparo
|
||||
constexpr const char* LOGO = "effects/logo.wav"; // Logo
|
||||
constexpr const char* START = "effects/start.wav"; // El jugador pulsa START
|
||||
constexpr const char* START = "effects/start.wav"; // El player pulsa START
|
||||
constexpr const char* GOOD_JOB_COMMANDER = "voices/good_job_commander.wav"; // Voz: "Good job, commander"
|
||||
} // namespace Sound
|
||||
|
||||
@@ -327,7 +327,7 @@ constexpr SDL_Keycode SHOOT = SDLK_LSHIFT;
|
||||
} // namespace P2
|
||||
} // namespace Controls
|
||||
|
||||
// Enemy type configuration (tipus d'enemics)
|
||||
// Enemy type configuration (type d'enemics)
|
||||
namespace Enemies {
|
||||
// Pentagon (esquivador - zigzag evasion)
|
||||
namespace Pentagon {
|
||||
@@ -395,7 +395,7 @@ constexpr float INVULNERABILITY_SCALE_START = 0.0F; // Invisible
|
||||
constexpr float INVULNERABILITY_SCALE_END = 1.0F; // Full size
|
||||
} // namespace Spawn
|
||||
|
||||
// Scoring system (puntuació per tipus d'enemic)
|
||||
// Scoring system (puntuació per type d'enemy)
|
||||
namespace Scoring {
|
||||
constexpr int PENTAGON_SCORE = 100; // Pentàgon (esquivador, 35 px/s)
|
||||
constexpr int QUADRAT_SCORE = 150; // Quadrat (perseguidor, 40 px/s)
|
||||
@@ -426,7 +426,7 @@ constexpr float CLOCK_RADIUS = 150.0F; // Distància des del centre
|
||||
constexpr float CLOCK_8_ANGLE = 150.0F * Math::PI / 180.0F; // 8 o'clock (bottom-left)
|
||||
constexpr float CLOCK_4_ANGLE = 30.0F * Math::PI / 180.0F; // 4 o'clock (bottom-right)
|
||||
|
||||
// 5. Radio máximo de la forma de la nave (para calcular offset automáticamente)
|
||||
// 5. Radio máximo de la shape de la nave (para calcular offset automáticamente)
|
||||
constexpr float SHIP_MAX_RADIUS = 30.0F; // Radi del cercle circumscrit a ship_starfield.shp
|
||||
|
||||
// 6. Margen de seguridad para offset de entrada
|
||||
@@ -436,7 +436,7 @@ constexpr float ENTRY_OFFSET_MARGIN = 227.5F; // Para offset total de ~340px (a
|
||||
// VALORS DERIVATS (calculats automàticament - NO modificar)
|
||||
// ============================================================
|
||||
|
||||
// Centre de la pantalla (punt de referència)
|
||||
// Centre de la pantalla (point de referència)
|
||||
constexpr float CENTER_X = Game::WIDTH / 2.0F; // 320.0f
|
||||
constexpr float CENTER_Y = Game::HEIGHT / 2.0F; // 240.0f
|
||||
|
||||
@@ -458,10 +458,10 @@ inline float P2_TARGET_Y() {
|
||||
|
||||
// Escales d'animació (relatives a SHIP_BASE_SCALE)
|
||||
constexpr float ENTRY_SCALE_START = 1.5F * SHIP_BASE_SCALE; // Entrada: 50% més gran
|
||||
constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: escala base
|
||||
constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: scale base
|
||||
|
||||
// Offset d'entrada (ajustat automàticament a l'escala)
|
||||
// Fórmula: (radi màxim de la nau * escala d'entrada) + marge
|
||||
// Offset d'entrada (ajustat automàticament a l'scale)
|
||||
// Fórmula: (radi màxim de la ship * scale d'entrada) + marge
|
||||
constexpr float ENTRY_OFFSET = (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN;
|
||||
|
||||
// Vec2 de fuga (centre per a l'animació de sortida)
|
||||
@@ -476,7 +476,7 @@ constexpr float VANISHING_POINT_Y = CENTER_Y; // 240.0f
|
||||
constexpr float ENTRY_DURATION = 2.0F; // Entrada (segons)
|
||||
constexpr float EXIT_DURATION = 1.0F; // Sortida (segons)
|
||||
|
||||
// Flotació (oscil·lació reduïda i diferenciada per nau)
|
||||
// Flotació (oscil·lació reduïda i diferenciada per ship)
|
||||
constexpr float FLOAT_AMPLITUDE_X = 4.0F; // Amplitud X (píxels)
|
||||
constexpr float FLOAT_AMPLITUDE_Y = 2.5F; // Amplitud Y (píxels)
|
||||
|
||||
@@ -489,10 +489,10 @@ constexpr float FLOAT_PHASE_OFFSET = 1.57F; // π/2 (90°)
|
||||
constexpr float P1_ENTRY_DELAY = 0.0F; // P1 entra immediatament
|
||||
constexpr float P2_ENTRY_DELAY = 0.5F; // P2 entra 0.5s després
|
||||
|
||||
// Delay global abans d'iniciar l'animació d'entrada al estat MAIN
|
||||
// Delay global abans d'iniciar l'animació d'entrada al state MAIN
|
||||
constexpr float ENTRANCE_DELAY = 5.0F; // Temps d'espera abans que les naus entrin
|
||||
|
||||
// Multiplicadors de freqüència per a cada nau (variació sutil ±12%)
|
||||
// Multiplicadors de freqüència per a cada ship (variació sutil ±12%)
|
||||
constexpr float P1_FREQUENCY_MULTIPLIER = 0.88F; // 12% més lenta
|
||||
constexpr float P2_FREQUENCY_MULTIPLIER = 1.12F; // 12% més ràpida
|
||||
|
||||
@@ -508,7 +508,7 @@ constexpr float COPYRIGHT1_POS = 0.90F; // Primera línia copyright
|
||||
constexpr float LOGO_LINE_SPACING = 0.02F; // Entre "ORNI" i "ATTACK!" (10px)
|
||||
constexpr float COPYRIGHT_LINE_SPACING = 0.0F; // Entre línies copyright (5px)
|
||||
|
||||
// Factors d'escala
|
||||
// Factors d'scale
|
||||
constexpr float LOGO_SCALE = 0.6F; // Escala "ORNI ATTACK!"
|
||||
constexpr float PRESS_START_SCALE = 1.0F; // Escala "PRESS START TO PLAY"
|
||||
constexpr float COPYRIGHT_SCALE = 0.5F; // Escala copyright
|
||||
|
||||
@@ -14,10 +14,10 @@ Shape::Shape(const std::string& filepath)
|
||||
: center_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
nom_("unnamed") {
|
||||
carregar(filepath);
|
||||
load(filepath);
|
||||
}
|
||||
|
||||
bool Shape::carregar(const std::string& filepath) {
|
||||
bool Shape::load(const std::string& filepath) {
|
||||
// Llegir fitxer
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
@@ -32,10 +32,10 @@ bool Shape::carregar(const std::string& filepath) {
|
||||
file.close();
|
||||
|
||||
// Parsejar
|
||||
return parsejar_fitxer(contingut);
|
||||
return parseFile(contingut);
|
||||
}
|
||||
|
||||
bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
bool Shape::parseFile(const std::string& contingut) {
|
||||
std::istringstream iss(contingut);
|
||||
std::string line;
|
||||
|
||||
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
try {
|
||||
escala_defecte_ = std::stof(extract_value(line));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n';
|
||||
std::cerr << "[Shape] Warning: scale invàlida, usant 1.0" << '\n';
|
||||
escala_defecte_ = 1.0F;
|
||||
}
|
||||
} else if (starts_with(line, "center:")) {
|
||||
@@ -65,7 +65,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() >= 2) {
|
||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 points ignorada"
|
||||
<< '\n';
|
||||
}
|
||||
} else if (starts_with(line, "line:")) {
|
||||
@@ -73,7 +73,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() == 2) {
|
||||
primitives_.push_back({PrimitiveType::LINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 points"
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
float y = std::stof(pair.substr(comma + 1));
|
||||
points.push_back({x, y});
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
||||
std::cerr << "[Shape] Warning: point invàlid ignorat: " << pair
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,30 @@
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
// Tipus de primitiva dins d'una forma
|
||||
// Tipus de primitiva dins d'una shape
|
||||
enum class PrimitiveType {
|
||||
POLYLINE, // Seqüència de punts connectats
|
||||
LINE // Línia individual (2 punts)
|
||||
POLYLINE, // Seqüència de points connectats
|
||||
LINE // Línia individual (2 points)
|
||||
};
|
||||
|
||||
// Primitiva individual (polyline o line)
|
||||
struct ShapePrimitive {
|
||||
PrimitiveType type;
|
||||
std::vector<Vec2> points; // 2+ punts per polyline, exactament 2 per line
|
||||
std::vector<Vec2> points; // 2+ points per polyline, exactament 2 per line
|
||||
};
|
||||
|
||||
// Classe Shape - representa una forma vectorial carregada des de .shp
|
||||
// Classe Shape - representa una shape vectorial carregada des de .shp
|
||||
class Shape {
|
||||
public:
|
||||
// Constructors
|
||||
Shape() = default;
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar forma des de fitxer .shp
|
||||
bool carregar(const std::string& filepath);
|
||||
// Carregar shape des de fitxer .shp
|
||||
bool load(const std::string& filepath);
|
||||
|
||||
// Parsejar forma des de buffer de memòria (per al sistema de recursos)
|
||||
bool parsejar_fitxer(const std::string& contingut);
|
||||
// Parsejar shape des de buffer de memòria (per al sistema de recursos)
|
||||
bool parseFile(const std::string& contingut);
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
@@ -41,7 +41,7 @@ class Shape {
|
||||
}
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool es_valida() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
@@ -49,9 +49,9 @@ class Shape {
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Vec2 center_; // Centre/origen de la forma
|
||||
Vec2 center_; // Centre/origen de la shape
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
[[nodiscard]] std::string trim(const std::string& str) const;
|
||||
|
||||
@@ -32,7 +32,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut load " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
@@ -40,15 +40,15 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Convert bytes to string and parse
|
||||
std::string file_content(data.begin(), data.end());
|
||||
auto shape = std::make_shared<Shape>();
|
||||
if (!shape->parsejar_fitxer(file_content)) {
|
||||
if (!shape->parseFile(file_content)) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Verify shape is valid
|
||||
if (!shape->es_valida()) {
|
||||
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n';
|
||||
if (!shape->isValid()) {
|
||||
std::cerr << "[ShapeLoader] Error: shape invàlida " << normalized << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class ShapeLoader {
|
||||
// No instanciable (tot estàtic)
|
||||
ShapeLoader() = delete;
|
||||
|
||||
// Carregar forma des de fitxer (amb caché)
|
||||
// Carregar shape des de fitxer (amb caché)
|
||||
// Retorna punter compartit (nullptr si error)
|
||||
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
||||
static std::shared_ptr<Shape> load(const std::string& filename);
|
||||
|
||||
@@ -22,11 +22,11 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
punt_fuga_(punt_fuga),
|
||||
area_(area),
|
||||
densitat_(densitat) {
|
||||
// Carregar forma d'estrella amb ShapeLoader
|
||||
// Carregar shape d'estrella amb ShapeLoader
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
|
||||
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n';
|
||||
if (!shape_estrella_ || !shape_estrella_->isValid()) {
|
||||
std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Calcular posició des de la distància
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
|
||||
estrelles_.push_back(estrella);
|
||||
}
|
||||
@@ -70,27 +70,27 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Inicialitzar una estrella (nova o regenerada)
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
// Angle aleatori des del punt de fuga cap a fora
|
||||
// Angle aleatori des del point de fuga cap a fora
|
||||
estrella.angle = (static_cast<float>(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI;
|
||||
|
||||
// Distància inicial petita (5% del radi màxim) - neix prop del centre
|
||||
estrella.distancia_centre = 0.05F;
|
||||
|
||||
// Posició inicial: molt prop del punt de fuga
|
||||
// Posició inicial: molt prop del point de fuga
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
}
|
||||
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
return (estrella.posicio.x < area_.x ||
|
||||
estrella.posicio.x > area_.x + area_.w ||
|
||||
estrella.posicio.y < area_.y ||
|
||||
estrella.posicio.y > area_.y + area_.h);
|
||||
return (estrella.position.x < area_.x ||
|
||||
estrella.position.x > area_.x + area_.w ||
|
||||
estrella.position.y < area_.y ||
|
||||
estrella.position.y > area_.y + area_.h);
|
||||
}
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
@@ -119,16 +119,16 @@ void Starfield::update(float delta_time) {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
// Moure cap a fora des del centre
|
||||
float velocitat = capa.velocitat_base;
|
||||
float dx = velocitat * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocitat * std::sin(estrella.angle) * delta_time;
|
||||
float velocity = capa.velocitat_base;
|
||||
float dx = velocity * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocity * std::sin(estrella.angle) * delta_time;
|
||||
|
||||
estrella.posicio.x += dx;
|
||||
estrella.posicio.y += dy;
|
||||
estrella.position.x += dx;
|
||||
estrella.position.y += dy;
|
||||
|
||||
// Actualitzar distància del centre
|
||||
float dx_centre = estrella.posicio.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.posicio.y - punt_fuga_.y;
|
||||
float dx_centre = estrella.position.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.position.y - punt_fuga_.y;
|
||||
float dist_px = std::sqrt((dx_centre * dx_centre) + (dy_centre * dy_centre));
|
||||
estrella.distancia_centre = dist_px / radi_max_;
|
||||
|
||||
@@ -146,22 +146,22 @@ void Starfield::set_brightness(float multiplier) {
|
||||
|
||||
// Dibuixar totes les estrelles
|
||||
void Starfield::draw() {
|
||||
if (!shape_estrella_->es_valida()) {
|
||||
if (!shape_estrella_->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& estrella : estrelles_) {
|
||||
// Calcular escala i brightness dinàmicament
|
||||
float escala = calcular_escala(estrella);
|
||||
// Calcular scale i brightness dinàmicament
|
||||
float scale = calcular_escala(estrella);
|
||||
float brightness = calcular_brightness(estrella);
|
||||
|
||||
// Renderitzar estrella sense rotació
|
||||
Rendering::render_shape(
|
||||
renderer_,
|
||||
shape_estrella_,
|
||||
estrella.posicio,
|
||||
estrella.position,
|
||||
0.0F, // angle (les estrelles no giren)
|
||||
escala, // escala dinàmica
|
||||
scale, // scale dinàmica
|
||||
1.0F, // progress (sempre visible)
|
||||
brightness // brightness dinàmica
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ class Starfield {
|
||||
public:
|
||||
// Constructor
|
||||
// - renderer: SDL renderer
|
||||
// - punt_fuga: punt d'origen/fuga des d'on surten les estrelles
|
||||
// - punt_fuga: point d'origen/fuga des d'on surten les estrelles
|
||||
// - area: rectangle on actuen les estrelles (SDL_FRect)
|
||||
// - densitat: nombre total d'estrelles (es divideix entre capes)
|
||||
Starfield(SDL_Renderer* renderer,
|
||||
@@ -40,14 +40,14 @@ class Starfield {
|
||||
// Dibuixar totes les estrelles
|
||||
void draw();
|
||||
|
||||
// Setters per ajustar paràmetres en temps real
|
||||
void set_punt_fuga(const Vec2& punt) { punt_fuga_ = punt; }
|
||||
// Setters per ajustar paràmetres en time real
|
||||
void set_punt_fuga(const Vec2& point) { punt_fuga_ = point; }
|
||||
void set_brightness(float multiplier);
|
||||
|
||||
private:
|
||||
// Estructura interna per cada estrella
|
||||
struct Estrella {
|
||||
Vec2 posicio; // Posició actual
|
||||
Vec2 position; // Posició actual
|
||||
float angle; // Angle de moviment (radians)
|
||||
float distancia_centre; // Distància normalitzada del centre (0.0-1.0)
|
||||
int capa; // Índex de capa (0=lluny, 1=mitjà, 2=prop)
|
||||
@@ -59,7 +59,7 @@ class Starfield {
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
|
||||
// Calcular brightness dinàmica segons distància del centre
|
||||
@@ -76,7 +76,7 @@ class Starfield {
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brillantor (1.0 = default)
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brightness (1.0 = default)
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -26,10 +26,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -54,10 +54,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
case '?':
|
||||
return "font/char_question.shp";
|
||||
case ' ':
|
||||
return ""; // Espai es maneja sense carregar shape
|
||||
return ""; // Espai es maneja sense load shape
|
||||
|
||||
case '\xA9': // Copyright symbol (©) - UTF-8 U+00A9
|
||||
return "font/char_copyright.shp";
|
||||
@@ -182,23 +182,23 @@ bool VectorText::is_supported(char c) const {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
void VectorText::render(const std::string& text, const Vec2& posicio, float escala, float spacing, float brightness) const {
|
||||
void VectorText::render(const std::string& text, const Vec2& position, float scale, float spacing, float brightness) const {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ancho de un carácter base (20 px a escala 1.0)
|
||||
const float char_width_scaled = char_width * escala;
|
||||
// Ancho de un carácter base (20 px a scale 1.0)
|
||||
const float char_width_scaled = char_width * scale;
|
||||
|
||||
// Spacing escalado
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Altura de un carácter escalado (necesario para ajustar Y)
|
||||
const float char_height_scaled = char_height * escala;
|
||||
const float char_height_scaled = char_height * scale;
|
||||
|
||||
// Posición X del borde izquierdo del carácter actual
|
||||
// (se ajustará +char_width/2 para obtener el centro al renderizar)
|
||||
float current_x = posicio.x;
|
||||
float current_x = position.x;
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
@@ -221,10 +221,10 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
auto it = chars_.find(c);
|
||||
if (it != chars_.end()) {
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// Ajustar X e Y para que position represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
@@ -237,28 +237,28 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::render_centered(const std::string& text, const Vec2& centre_punt, float escala, float spacing, float brightness) const {
|
||||
void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt, float scale, float spacing, float brightness) const {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, escala, spacing);
|
||||
float text_height = get_text_height(escala);
|
||||
float text_width = get_text_width(text, scale, spacing);
|
||||
float text_height = get_text_height(scale);
|
||||
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
// restant la meitat de les dimensions del point central
|
||||
Vec2 posicio_esquerra = {
|
||||
.x = centre_punt.x - (text_width / 2.0F),
|
||||
.y = centre_punt.y - (text_height / 2.0F)};
|
||||
|
||||
// Delegar al mètode render() existent
|
||||
render(text, posicio_esquerra, escala, spacing, brightness);
|
||||
render(text, posicio_esquerra, scale, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float escala, float spacing) const {
|
||||
float VectorText::get_text_width(const std::string& text, float scale, float spacing) const {
|
||||
if (text.empty()) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
const float char_width_scaled = char_width * escala;
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float char_width_scaled = char_width * scale;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
@@ -279,8 +279,8 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
|
||||
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float escala) const {
|
||||
return char_height * escala;
|
||||
float VectorText::get_text_height(float scale) const {
|
||||
return char_height * scale;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -21,25 +21,25 @@ class VectorText {
|
||||
// Renderizar string completo
|
||||
// - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':',
|
||||
// '!', '?', ' ')
|
||||
// - posicio: posición inicial (esquina superior izquierda)
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render(const std::string& text, const Vec2& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - position: posición inicial (esquina superior izquierda)
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render(const std::string& text, const Vec2& position, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Renderizar string centrado en un punto
|
||||
// - text: cadena a renderizar
|
||||
// - centre_punt: punto central del texto (no esquina superior izquierda)
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render_centered(const std::string& text, const Vec2& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
[[nodiscard]] float get_text_height(float escala = 1.0F) const;
|
||||
[[nodiscard]] float get_text_height(float scale = 1.0F) const;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
|
||||
@@ -30,7 +30,7 @@ Input::Input(std::string game_controller_db_path)
|
||||
// Inicializar bindings del teclado (valores por defecto)
|
||||
// Estos serán sobrescritos por applyPlayer1BindingsFromOptions()
|
||||
keyboard_.bindings = {
|
||||
// Movimiento del jugador
|
||||
// Movimiento del player
|
||||
{Action::LEFT, KeyState{.scancode = SDL_SCANCODE_LEFT}},
|
||||
{Action::RIGHT, KeyState{.scancode = SDL_SCANCODE_RIGHT}},
|
||||
{Action::THRUST, KeyState{.scancode = SDL_SCANCODE_UP}},
|
||||
@@ -188,7 +188,7 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si algún jugador (P1 o P2) presionó alguna acción de una lista
|
||||
// Comprueba si algún player (P1 o P2) presionó alguna acción de una lista
|
||||
auto Input::checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat) -> bool {
|
||||
for (const auto& action : actions) {
|
||||
if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) {
|
||||
@@ -388,14 +388,14 @@ void Input::update() {
|
||||
binding.second.is_held = key_is_down_now;
|
||||
}
|
||||
|
||||
// Actualizar bindings de jugador 1
|
||||
// Actualizar bindings de player 1
|
||||
for (auto& binding : player1_keyboard_bindings_) {
|
||||
bool key_is_down_now = key_states[binding.second.scancode];
|
||||
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
||||
binding.second.is_held = key_is_down_now;
|
||||
}
|
||||
|
||||
// Actualizar bindings de jugador 2
|
||||
// Actualizar bindings de player 2
|
||||
for (auto& binding : player2_keyboard_bindings_) {
|
||||
bool key_is_down_now = key_states[binding.second.scancode];
|
||||
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
||||
@@ -493,7 +493,7 @@ auto Input::findAvailableGamepadByName(const std::string& gamepad_name) -> std::
|
||||
|
||||
// ========== MÉTODOS ESPECÍFICOS POR JUGADOR (ORNI) ==========
|
||||
|
||||
// Aplica configuración de controles del jugador 1
|
||||
// Aplica configuración de controles del player 1
|
||||
void Input::applyPlayer1BindingsFromOptions() {
|
||||
// 1. Aplicar bindings de teclado (NO usar bindKey, llenar mapa específico)
|
||||
player1_keyboard_bindings_[Action::LEFT].scancode = Options::player1.keyboard.key_left;
|
||||
@@ -527,7 +527,7 @@ void Input::applyPlayer1BindingsFromOptions() {
|
||||
player1_gamepad_ = gamepad;
|
||||
}
|
||||
|
||||
// Aplica configuración de controles del jugador 2
|
||||
// Aplica configuración de controles del player 2
|
||||
void Input::applyPlayer2BindingsFromOptions() {
|
||||
// 1. Aplicar bindings de teclado (mapa específico de P2, no sobrescribe P1)
|
||||
player2_keyboard_bindings_[Action::LEFT].scancode = Options::player2.keyboard.key_left;
|
||||
@@ -561,7 +561,7 @@ void Input::applyPlayer2BindingsFromOptions() {
|
||||
player2_gamepad_ = gamepad;
|
||||
}
|
||||
|
||||
// Consulta de input para jugador 1
|
||||
// Consulta de input para player 1
|
||||
auto Input::checkActionPlayer1(Action action, bool repeat) -> bool {
|
||||
// Comprobar teclado con el mapa específico de P1
|
||||
bool keyboard_active = false;
|
||||
@@ -583,7 +583,7 @@ auto Input::checkActionPlayer1(Action action, bool repeat) -> bool {
|
||||
return keyboard_active || gamepad_active;
|
||||
}
|
||||
|
||||
// Consulta de input para jugador 2
|
||||
// Consulta de input para player 2
|
||||
auto Input::checkActionPlayer2(Action action, bool repeat) -> bool {
|
||||
// Comprobar teclado con el mapa específico de P2
|
||||
bool keyboard_active = false;
|
||||
|
||||
@@ -58,7 +58,7 @@ class Input {
|
||||
name(std::string(SDL_GetGamepadName(gamepad))),
|
||||
path(std::string(SDL_GetGamepadPath(pad))),
|
||||
bindings{
|
||||
// Movimiento y acciones del jugador
|
||||
// Movimiento y acciones del player
|
||||
{Action::LEFT, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}},
|
||||
{Action::RIGHT, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}},
|
||||
{Action::THRUST, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_WEST)}},
|
||||
@@ -92,7 +92,7 @@ class Input {
|
||||
void applyKeyboardBindingsFromOptions();
|
||||
void applyGamepadBindingsFromOptions();
|
||||
|
||||
// Configuración por jugador (Orni - dos jugadores)
|
||||
// Configuración por player (Orni - dos jugadores)
|
||||
void applyPlayer1BindingsFromOptions();
|
||||
void applyPlayer2BindingsFromOptions();
|
||||
|
||||
@@ -105,7 +105,7 @@ class Input {
|
||||
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool;
|
||||
void resetInputStates();
|
||||
|
||||
// Consulta por jugador (Orni - dos jugadores)
|
||||
// Consulta por player (Orni - dos jugadores)
|
||||
auto checkActionPlayer1(Action action, bool repeat = true) -> bool;
|
||||
auto checkActionPlayer2(Action action, bool repeat = true) -> bool;
|
||||
|
||||
@@ -152,11 +152,11 @@ class Input {
|
||||
Keyboard keyboard_{}; // Estado del teclado (solo acciones globales)
|
||||
std::string gamepad_mappings_file_; // Ruta al archivo de mappings
|
||||
|
||||
// Referencias cacheadas a gamepads por jugador (Orni)
|
||||
// Referencias cacheadas a gamepads por player (Orni)
|
||||
std::shared_ptr<Gamepad> player1_gamepad_;
|
||||
std::shared_ptr<Gamepad> player2_gamepad_;
|
||||
|
||||
// Mapas de bindings separados por jugador (Orni - dos jugadores)
|
||||
// Mapas de bindings separados por player (Orni - dos jugadores)
|
||||
std::unordered_map<Action, KeyState> player1_keyboard_bindings_;
|
||||
std::unordered_map<Action, KeyState> player2_keyboard_bindings_;
|
||||
};
|
||||
@@ -13,7 +13,7 @@ enum class InputAction : int { // Acciones de entrada posibles en el juego
|
||||
RIGHT, // Rotar derecha
|
||||
THRUST, // Acelerar
|
||||
SHOOT, // Disparar
|
||||
START, // Empezar partida
|
||||
START, // Empezar match
|
||||
|
||||
// Inputs de sistema (globales)
|
||||
WINDOW_INC_ZOOM, // F2
|
||||
|
||||
@@ -17,13 +17,13 @@ Uint32 initialization_time = 0;
|
||||
constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms
|
||||
|
||||
void forceHide() {
|
||||
// Forçar ocultació sincronitzant estat SDL i estat intern
|
||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
|
||||
// Forçar ocultació sincronitzant state SDL i state intern
|
||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant state. cursor_visible=" << cursor_visible
|
||||
<< " -> false" << '\n';
|
||||
SDL_HideCursor();
|
||||
cursor_visible = false;
|
||||
last_mouse_move_time = 0;
|
||||
initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials
|
||||
initialization_time = SDL_GetTicks(); // Marcar time per ignorar esdeveniments inicials
|
||||
std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << '\n';
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el c
|
||||
extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió
|
||||
extern bool cursor_visible; // Estado del cursor
|
||||
|
||||
void forceHide(); // Forçar ocultació del cursor (sincronitza estat intern)
|
||||
void forceHide(); // Forçar ocultació del cursor (sincronitza state intern)
|
||||
void handleEvent(const SDL_Event& event);
|
||||
void updateCursorVisibility();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Factor d'escala global (inicialitzat a 1.0 per defecte)
|
||||
// Factor d'scale global (inicialitzat a 1.0 per defecte)
|
||||
float g_current_scale_factor = 1.0F;
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Factor d'escala global (actualitzat cada frame per SDLManager)
|
||||
// Factor d'scale global (actualitzat cada frame per SDLManager)
|
||||
extern float g_current_scale_factor;
|
||||
|
||||
// Transforma coordenada lògica a física amb arrodoniment
|
||||
@@ -19,7 +19,7 @@ inline int transform_y(int logical_y, float scale) {
|
||||
return static_cast<int>(std::round(logical_y * scale));
|
||||
}
|
||||
|
||||
// Variant que usa el factor d'escala global
|
||||
// Variant que usa el factor d'scale global
|
||||
inline int transform_x(int logical_x) {
|
||||
return transform_x(logical_x, g_current_scale_factor);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Dibuixa una línia entre dos punts en coordenades lògiques (640x480).
|
||||
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor).
|
||||
// Dibuixa una línia entre dos points en coordenades lògiques (640x480).
|
||||
// brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness).
|
||||
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness = 1.0F);
|
||||
|
||||
// Estableix el color global de les línies (utilitzat per ColorOscillator).
|
||||
|
||||
@@ -283,7 +283,7 @@ void SDLManager::updateViewport() {
|
||||
}
|
||||
|
||||
void SDLManager::updateRenderingContext() const {
|
||||
// Actualitzar el factor d'escala global per a totes les funcions de renderitzat
|
||||
// Actualitzar el factor d'scale global per a totes les funcions de renderitzat
|
||||
Rendering::g_current_scale_factor = zoom_factor_;
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ void SDLManager::updateColors(float delta_time) {
|
||||
|
||||
// [NUEVO] Actualitzar comptador de FPS
|
||||
void SDLManager::updateFPS(float delta_time) {
|
||||
// Acumular temps i frames
|
||||
// Acumular time i frames
|
||||
fps_accumulator_ += delta_time;
|
||||
fps_frame_count_++;
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ class SDLManager {
|
||||
void updateFPS(float delta_time);
|
||||
|
||||
// Getters
|
||||
SDL_Renderer* obte_renderer() { return renderer_; }
|
||||
SDL_Renderer* getRenderer() { return renderer_; }
|
||||
[[nodiscard]] float getScaleFactor() const { return zoom_factor_; }
|
||||
|
||||
// [NUEVO] Actualitzar títol de la finestra
|
||||
void setWindowTitle(const std::string& title);
|
||||
|
||||
// [NUEVO] Actualitzar context de renderitzat (factor d'escala global)
|
||||
// [NUEVO] Actualitzar context de renderitzat (factor d'scale global)
|
||||
void updateRenderingContext() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Helper: aplicar rotació 3D a un punt 2D (assumeix Z=0)
|
||||
// Helper: aplicar rotació 3D a un point 2D (assumeix Z=0)
|
||||
static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
float z = 0.0F; // Tots els punts 2D comencen a Z=0
|
||||
float z = 0.0F; // Tots els points 2D comencen a Z=0
|
||||
|
||||
// Pitch (rotació eix X): cabeceo arriba/baix
|
||||
float cos_pitch = std::cos(rot.pitch);
|
||||
@@ -33,7 +33,7 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
float y3 = (x2 * sin_roll) + (y1 * cos_roll);
|
||||
|
||||
// Proyecció perspectiva (Z-divide simple)
|
||||
// Naus volen cap al punt de fuga (320, 240) a "infinit" (Z → +∞)
|
||||
// Naus volen cap al point de fuga (320, 240) a "infinit" (Z → +∞)
|
||||
// Z més gran = més lluny = més petit a pantalla
|
||||
constexpr float perspective_factor = 500.0F;
|
||||
float scale_factor = perspective_factor / (perspective_factor + z2);
|
||||
@@ -41,9 +41,9 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
return {.x = x3 * scale_factor, .y = y3 * scale_factor};
|
||||
}
|
||||
|
||||
// Helper: transformar un punt amb rotació, escala i trasllació
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala, const Rotation3D* rotation_3d) {
|
||||
// 1. Centrar el punt respecte al centre de la forma
|
||||
// Helper: transformar un point amb rotació, scale i trasllació
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale, const Rotation3D* rotation_3d) {
|
||||
// 1. Centrar el point respecte al centre de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
@@ -54,9 +54,9 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
centered_y = rotated_3d.y;
|
||||
}
|
||||
|
||||
// 3. Aplicar escala al punt (després de rotació 3D)
|
||||
float scaled_x = centered_x * escala;
|
||||
float scaled_y = centered_y * escala;
|
||||
// 3. Aplicar scale al point (després de rotació 3D)
|
||||
float scaled_x = centered_x * scale;
|
||||
float scaled_y = centered_y * scale;
|
||||
|
||||
// 4. Aplicar rotació 2D (Z-axis, tradicional)
|
||||
// IMPORTANT: En el sistema original, angle=0 apunta AMUNT (no dreta)
|
||||
@@ -69,19 +69,19 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
|
||||
|
||||
// 5. Aplicar trasllació a posició mundial
|
||||
return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y};
|
||||
return {.x = rotated_x + position.x, .y = rotated_y + position.y};
|
||||
}
|
||||
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& posicio,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
float escala,
|
||||
float scale,
|
||||
float progress,
|
||||
float brightness,
|
||||
const Rotation3D* rotation_3d) {
|
||||
// Verificar que la forma és vàlida
|
||||
if (!shape || !shape->es_valida()) {
|
||||
// Verificar que la shape és vàlida
|
||||
if (!shape || !shape->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,25 +90,25 @@ void render_shape(SDL_Renderer* renderer,
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtenir el centre de la forma per a transformacions
|
||||
// Obtenir el centre de la shape per a transformacions
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
// Iterar sobre totes les primitives
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// POLYLINE: connectar punts consecutius
|
||||
// POLYLINE: connectar points consecutius
|
||||
for (size_t i = 0; i < primitive.points.size() - 1; i++) {
|
||||
Vec2 p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p1 = transform_point(primitive.points[i], shape_centre, position, angle, scale, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
}
|
||||
} else { // PrimitiveType::LINE
|
||||
// LINE: exactament 2 punts
|
||||
// LINE: exactament 2 points
|
||||
if (primitive.points.size() >= 2) {
|
||||
Vec2 p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p1 = transform_point(primitive.points[0], shape_centre, position, angle, scale, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[1], shape_centre, position, angle, scale, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
|
||||
@@ -32,19 +32,19 @@ struct Rotation3D {
|
||||
}
|
||||
};
|
||||
|
||||
// Renderitzar forma amb transformacions
|
||||
// Renderitzar shape amb transformacions
|
||||
// - renderer: SDL renderer
|
||||
// - shape: forma vectorial a draw
|
||||
// - posicio: posició del centre en coordenades mundials
|
||||
// - shape: shape vectorial a draw
|
||||
// - position: posició del centre en coordenades mundials
|
||||
// - angle: rotació en radians (0 = amunt, sentit horari)
|
||||
// - escala: factor d'escala (1.0 = mida original)
|
||||
// - scale: factor d'scale (1.0 = mida original)
|
||||
// - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& posicio,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
float escala = 1.0F,
|
||||
float scale = 1.0F,
|
||||
float progress = 1.0F,
|
||||
float brightness = 1.0F,
|
||||
const Rotation3D* rotation_3d = nullptr);
|
||||
|
||||
@@ -19,12 +19,12 @@ Loader& Loader::get() {
|
||||
bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
fallback_enabled_ = enable_fallback;
|
||||
|
||||
// Intentar carregar el paquet
|
||||
// Intentar load el paquet
|
||||
pack_ = std::make_unique<Pack>();
|
||||
|
||||
if (!pack_->loadPack(pack_file)) {
|
||||
if (!fallback_enabled_) {
|
||||
std::cerr << "[ResourceLoader] ERROR FATAL: No es pot carregar " << pack_file
|
||||
std::cerr << "[ResourceLoader] ERROR FATAL: No es pot load " << pack_file
|
||||
<< " i el fallback està desactivat\n";
|
||||
return false;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
|
||||
// Carregar un recurs
|
||||
std::vector<uint8_t> Loader::loadResource(const std::string& filename) {
|
||||
// Intentar carregar del paquet primer
|
||||
// Intentar load del paquet primer
|
||||
if (pack_) {
|
||||
if (pack_->hasResource(filename)) {
|
||||
auto data = pack_->getResource(filename);
|
||||
|
||||
@@ -35,7 +35,7 @@ class Pack {
|
||||
bool addFile(const std::string& filepath, const std::string& pack_name);
|
||||
bool addDirectory(const std::string& dir_path, const std::string& base_path = "");
|
||||
|
||||
// Guardar i carregar paquets
|
||||
// Guardar i load paquets
|
||||
bool savePack(const std::string& pack_file);
|
||||
bool loadPack(const std::string& pack_file);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Director::Director(std::vector<std::string> const& args) {
|
||||
// Mode release: paquet obligatori, sense fallback
|
||||
std::string pack_path = resource_base + "/resources.pack";
|
||||
if (!Resource::Helper::initializeResourceSystem(pack_path, false)) {
|
||||
std::cerr << "ERROR FATAL: No es pot carregar " << pack_path << "\n";
|
||||
std::cerr << "ERROR FATAL: No es pot load " << pack_path << "\n";
|
||||
std::cerr << "El joc no pot continuar sense els recursos.\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
@@ -10,36 +10,36 @@ enum class Mode {
|
||||
DEMO // Mode demostració (futur)
|
||||
};
|
||||
|
||||
// Configuració d'una partida
|
||||
// Configuració d'una match
|
||||
struct MatchConfig {
|
||||
bool jugador1_actiu{false}; // És actiu el jugador 1?
|
||||
bool jugador2_actiu{false}; // És actiu el jugador 2?
|
||||
bool jugador1_actiu{false}; // És active el player 1?
|
||||
bool jugador2_actiu{false}; // És active el player 2?
|
||||
Mode mode{Mode::NORMAL}; // Mode de joc
|
||||
|
||||
// Mètodes auxiliars
|
||||
|
||||
// Retorna true si només hi ha un jugador actiu
|
||||
// Retorna true si només hi ha un player active
|
||||
[[nodiscard]] bool es_un_jugador() const {
|
||||
return (jugador1_actiu && !jugador2_actiu) ||
|
||||
(!jugador1_actiu && jugador2_actiu);
|
||||
}
|
||||
|
||||
// Retorna true si hi ha dos jugadors actius
|
||||
// Retorna true si hi ha dos jugadors active
|
||||
[[nodiscard]] bool son_dos_jugadors() const {
|
||||
return jugador1_actiu && jugador2_actiu;
|
||||
}
|
||||
|
||||
// Retorna true si no hi ha cap jugador actiu
|
||||
// Retorna true si no hi ha cap player active
|
||||
[[nodiscard]] bool cap_jugador() const {
|
||||
return !jugador1_actiu && !jugador2_actiu;
|
||||
}
|
||||
|
||||
// Compte de jugadors actius (0, 1 o 2)
|
||||
// Compte de jugadors active (0, 1 o 2)
|
||||
[[nodiscard]] uint8_t compte_jugadors() const {
|
||||
return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0);
|
||||
}
|
||||
|
||||
// Retorna l'ID de l'únic jugador actiu (0 o 1)
|
||||
// Retorna l'ID de l'únic player active (0 o 1)
|
||||
// Només vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
if (jugador1_actiu && !jugador2_actiu) {
|
||||
|
||||
@@ -14,6 +14,6 @@ class SceneContext;
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Processa events globals (F1/F2/F3/ESC/QUIT)
|
||||
// Retorna true si l'event ha estat processat i no cal seguir processant-lo
|
||||
// Retorna true si l'event ha state processat i no cal seguir processant-lo
|
||||
bool handle(const SDL_Event& event, SDLManager& sdl, SceneManager::SceneContext& context);
|
||||
} // namespace GlobalEvents
|
||||
|
||||
@@ -58,12 +58,12 @@ class SceneContext {
|
||||
option_ = Option::NONE;
|
||||
}
|
||||
|
||||
// Configurar partida abans de transicionar a GAME
|
||||
// Configurar match abans de transicionar a GAME
|
||||
void setMatchConfig(const GameConfig::MatchConfig& config) {
|
||||
match_config_ = config;
|
||||
}
|
||||
|
||||
// Obtenir configuració de partida (consumit per GameScene)
|
||||
// Obtenir configuració de match (consumit per GameScene)
|
||||
[[nodiscard]] const GameConfig::MatchConfig& getMatchConfig() const {
|
||||
return match_config_;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class SceneContext {
|
||||
private:
|
||||
SceneType next_scene_{SceneType::LOGO}; // SceneType a la qual transicionar
|
||||
Option option_{Option::NONE}; // Opció específica per l'escena
|
||||
GameConfig::MatchConfig match_config_; // Configuració de partida (jugadors actius, mode)
|
||||
GameConfig::MatchConfig match_config_; // Configuració de match (jugadors active, mode)
|
||||
};
|
||||
|
||||
// Variable global inline per gestionar l'escena actual (backward compatibility)
|
||||
|
||||
@@ -50,7 +50,7 @@ bool isMacOSBundle() {
|
||||
#ifdef MACOS_BUNDLE
|
||||
return true;
|
||||
#else
|
||||
// Detecció en temps d'execució
|
||||
// Detecció en time d'execució
|
||||
// Cercar ".app/Contents/MacOS" a la ruta de l'executable
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
return exe_dir.find(".app/Contents/MacOS") != std::string::npos;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
#include "core/defaults.hpp"
|
||||
|
||||
// Aliases per a backward compatibility amb codi existent
|
||||
// Permet usar Constants::MARGE_ESQ en lloc de Defaults::Game::MARGIN_LEFT
|
||||
// Permet usar Constants::MARGIN_LEFT en lloc de Defaults::Game::MARGIN_LEFT
|
||||
|
||||
namespace Constants {
|
||||
// Marges de l'àrea de joc (derivats de Defaults::Zones::GAME)
|
||||
constexpr int MARGE_ESQ = static_cast<int>(Defaults::Zones::PLAYAREA.x);
|
||||
constexpr int MARGE_DRET =
|
||||
constexpr int MARGIN_LEFT = static_cast<int>(Defaults::Zones::PLAYAREA.x);
|
||||
constexpr int MARGIN_RIGHT =
|
||||
static_cast<int>(Defaults::Zones::PLAYAREA.x + Defaults::Zones::PLAYAREA.w);
|
||||
constexpr int MARGE_DALT = static_cast<int>(Defaults::Zones::PLAYAREA.y);
|
||||
constexpr int MARGE_BAIX =
|
||||
constexpr int MARGIN_TOP = static_cast<int>(Defaults::Zones::PLAYAREA.y);
|
||||
constexpr int MARGIN_BOTTOM =
|
||||
static_cast<int>(Defaults::Zones::PLAYAREA.y + Defaults::Zones::PLAYAREA.h);
|
||||
|
||||
// Límits d'objectes
|
||||
@@ -27,8 +27,8 @@ constexpr float PI = Defaults::Math::PI;
|
||||
|
||||
// Helpers per comprovar límits de zona
|
||||
inline bool dins_zona_joc(float x, float y) {
|
||||
const SDL_FPoint punt = {x, y};
|
||||
return SDL_PointInRectFloat(&punt, &Defaults::Zones::PLAYAREA);
|
||||
const SDL_FPoint point = {x, y};
|
||||
return SDL_PointInRectFloat(&point, &Defaults::Zones::PLAYAREA);
|
||||
}
|
||||
|
||||
inline void obtenir_limits_zona(float& min_x, float& max_x, float& min_y, float& max_y) {
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
namespace Effects {
|
||||
|
||||
// Debris: un segment de línia que vola perpendicular a sí mateix
|
||||
// Representa un fragment d'una forma destruïda (nau, enemic, bala)
|
||||
// Representa un fragment d'una shape destruïda (ship, enemy, bullet)
|
||||
struct Debris {
|
||||
// Geometria del segment (2 punts en coordenades mundials)
|
||||
// Geometria del segment (2 points en coordenades mundials)
|
||||
Vec2 p1; // Vec2 inicial del segment
|
||||
Vec2 p2; // Vec2 final del segment
|
||||
|
||||
// Física
|
||||
Vec2 velocitat; // Velocitat en px/s (components x, y)
|
||||
float acceleracio; // Acceleració negativa (fricció) en px/s²
|
||||
Vec2 velocity; // Velocitat en px/s (components x, y)
|
||||
float acceleration; // Acceleració negativa (fricció) en px/s²
|
||||
|
||||
// Rotació
|
||||
float angle_rotacio; // Angle de rotació acumulat (radians)
|
||||
@@ -25,13 +25,13 @@ struct Debris {
|
||||
// Estat de vida
|
||||
float temps_vida; // Temps transcorregut (segons)
|
||||
float temps_max; // Temps de vida màxim (segons)
|
||||
bool actiu; // Està actiu?
|
||||
bool active; // Està active?
|
||||
|
||||
// Shrinking (reducció de distància entre punts)
|
||||
// Shrinking (reducció de distància entre points)
|
||||
float factor_shrink; // Factor de reducció per segon (0.0-1.0)
|
||||
|
||||
// Rendering
|
||||
float brightness; // Factor de brillantor (0.0-1.0, heretat de l'objecte original)
|
||||
float brightness; // Factor de brightness (0.0-1.0, heretat de l'objecte original)
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
|
||||
namespace Effects {
|
||||
|
||||
// Helper: transformar punt amb rotació, escala i trasllació
|
||||
// Helper: transformar point amb rotació, scale i trasllació
|
||||
// (Copiat de shape_renderer.cpp:12-34)
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala) {
|
||||
// 1. Centrar el punt respecte al centre de la forma
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale) {
|
||||
// 1. Centrar el point respecte al centre de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
// 2. Aplicar escala al punt centrat
|
||||
float scaled_x = centered_x * escala;
|
||||
float scaled_y = centered_y * escala;
|
||||
// 2. Aplicar scale al point centrat
|
||||
float scaled_x = centered_x * scale;
|
||||
float scaled_y = centered_y * scale;
|
||||
|
||||
// 3. Aplicar rotació
|
||||
float cos_a = std::cos(angle);
|
||||
@@ -33,38 +33,38 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
|
||||
|
||||
// 4. Aplicar trasllació a posició mundial
|
||||
return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y};
|
||||
return {.x = rotated_x + position.x, .y = rotated_y + position.y};
|
||||
}
|
||||
|
||||
DebrisManager::DebrisManager(SDL_Renderer* renderer)
|
||||
: renderer_(renderer) {
|
||||
// Inicialitzar tots els debris com inactius
|
||||
for (auto& debris : debris_pool_) {
|
||||
debris.actiu = false;
|
||||
debris.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
void DebrisManager::explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& centre,
|
||||
float angle,
|
||||
float escala,
|
||||
float scale,
|
||||
float velocitat_base,
|
||||
float brightness,
|
||||
const Vec2& velocitat_objecte,
|
||||
float velocitat_angular,
|
||||
float factor_herencia_visual,
|
||||
const std::string& sound) {
|
||||
if (!shape || !shape->es_valida()) {
|
||||
if (!shape || !shape->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reproducir sonido de explosión
|
||||
Audio::get()->playSound(sound, Audio::Group::GAME);
|
||||
|
||||
// Obtenir centre de la forma per a transformacions
|
||||
// Obtenir centre de la shape per a transformacions
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
// Iterar sobre totes les primitives de la forma
|
||||
// Iterar sobre totes les primitives de la shape
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
// Processar cada segment de línia
|
||||
std::vector<std::pair<Vec2, Vec2>> segments;
|
||||
@@ -83,14 +83,14 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
|
||||
// Crear debris per a cada segment
|
||||
for (const auto& [local_p1, local_p2] : segments) {
|
||||
// 1. Transformar punts locals → coordenades mundials
|
||||
// 1. Transformar points locals → coordenades mundials
|
||||
Vec2 world_p1 =
|
||||
transform_point(local_p1, shape_centre, centre, angle, escala);
|
||||
transform_point(local_p1, shape_centre, centre, angle, scale);
|
||||
Vec2 world_p2 =
|
||||
transform_point(local_p2, shape_centre, centre, angle, escala);
|
||||
transform_point(local_p2, shape_centre, centre, angle, scale);
|
||||
|
||||
// 2. Trobar slot lliure
|
||||
Debris* debris = trobar_slot_lliure();
|
||||
Debris* debris = findFreeSlot();
|
||||
if (debris == nullptr) {
|
||||
std::cerr << "[DebrisManager] Warning: no debris slots disponibles\n";
|
||||
return; // Pool ple
|
||||
@@ -101,20 +101,20 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->p2 = world_p2;
|
||||
|
||||
// 4. Calcular direcció d'explosió (radial, des del centre cap a fora)
|
||||
Vec2 direccio = calcular_direccio_explosio(world_p1, world_p2, centre);
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centre);
|
||||
|
||||
// 5. Velocitat inicial (base ± variació aleatòria + velocitat heretada)
|
||||
// 5. Velocitat inicial (base ± variació aleatòria + velocity heretada)
|
||||
float speed =
|
||||
velocitat_base +
|
||||
(((std::rand() / static_cast<float>(RAND_MAX)) * 2.0F - 1.0F) *
|
||||
Defaults::Physics::Debris::VARIACIO_VELOCITAT);
|
||||
|
||||
// Heredar velocitat de l'objecte original (suma vectorial)
|
||||
debris->velocitat.x = (direccio.x * speed) + velocitat_objecte.x;
|
||||
debris->velocitat.y = (direccio.y * speed) + velocitat_objecte.y;
|
||||
debris->acceleracio = Defaults::Physics::Debris::ACCELERACIO;
|
||||
// Heredar velocity de l'objecte original (suma vectorial)
|
||||
debris->velocity.x = (direccio.x * speed) + velocitat_objecte.x;
|
||||
debris->velocity.y = (direccio.y * speed) + velocitat_objecte.y;
|
||||
debris->acceleration = Defaults::Physics::Debris::ACCELERACIO;
|
||||
|
||||
// 6. Herència de velocitat angular amb cap + conversió d'excés
|
||||
// 6. Herència de velocity angular amb cap + conversió d'excés
|
||||
|
||||
// 6a. Rotació de TRAYECTORIA amb cap + conversió tangencial
|
||||
if (std::abs(velocitat_angular) > 0.01F) {
|
||||
@@ -137,10 +137,10 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
float sign_ang = (velocitat_ang_heretada >= 0.0F) ? 1.0F : -1.0F;
|
||||
|
||||
if (abs_ang > CAP) {
|
||||
// Excés: convertir a velocitat tangencial
|
||||
// Excés: convertir a velocity tangencial
|
||||
float excess = abs_ang - CAP;
|
||||
|
||||
// Radi de la forma (enemics = 20 px)
|
||||
// Radi de la shape (enemics = 20 px)
|
||||
float radius = 20.0F;
|
||||
|
||||
// Velocitat tangencial = ω_excés × radi
|
||||
@@ -151,11 +151,11 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
float tangent_x = -direccio.y;
|
||||
float tangent_y = direccio.x;
|
||||
|
||||
// Afegir velocitat tangencial (suma vectorial)
|
||||
debris->velocitat.x += tangent_x * v_tangential;
|
||||
debris->velocitat.y += tangent_y * v_tangential;
|
||||
// Afegir velocity tangencial (suma vectorial)
|
||||
debris->velocity.x += tangent_x * v_tangential;
|
||||
debris->velocity.y += tangent_y * v_tangential;
|
||||
|
||||
// Aplicar cap a velocitat angular (preservar signe)
|
||||
// Aplicar cap a velocity angular (preservar signe)
|
||||
debris->velocitat_rot = sign_ang * CAP;
|
||||
} else {
|
||||
// Per sota del cap: comportament normal
|
||||
@@ -199,62 +199,62 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->brightness = brightness;
|
||||
|
||||
// 9. Activar
|
||||
debris->actiu = true;
|
||||
debris->active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebrisManager::update(float delta_time) {
|
||||
for (auto& debris : debris_pool_) {
|
||||
if (!debris.actiu) {
|
||||
if (!debris.active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Actualitzar temps de vida
|
||||
// 1. Actualitzar time de vida
|
||||
debris.temps_vida += delta_time;
|
||||
|
||||
// Desactivar si ha superat temps màxim
|
||||
// Desactivar si ha superat time màxim
|
||||
if (debris.temps_vida >= debris.temps_max) {
|
||||
debris.actiu = false;
|
||||
debris.active = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. Actualitzar velocitat (desacceleració)
|
||||
// 2. Actualitzar velocity (desacceleració)
|
||||
// Aplicar fricció en la direcció del moviment
|
||||
float speed = std::sqrt((debris.velocitat.x * debris.velocitat.x) +
|
||||
(debris.velocitat.y * debris.velocitat.y));
|
||||
float speed = std::sqrt((debris.velocity.x * debris.velocity.x) +
|
||||
(debris.velocity.y * debris.velocity.y));
|
||||
|
||||
if (speed > 1.0F) {
|
||||
// Calcular direcció normalitzada
|
||||
float dir_x = debris.velocitat.x / speed;
|
||||
float dir_y = debris.velocitat.y / speed;
|
||||
float dir_x = debris.velocity.x / speed;
|
||||
float dir_y = debris.velocity.y / speed;
|
||||
|
||||
// Aplicar acceleració negativa (fricció)
|
||||
float nova_speed = speed + (debris.acceleracio * delta_time);
|
||||
float nova_speed = speed + (debris.acceleration * delta_time);
|
||||
nova_speed = std::max(nova_speed, 0.0F);
|
||||
|
||||
debris.velocitat.x = dir_x * nova_speed;
|
||||
debris.velocitat.y = dir_y * nova_speed;
|
||||
debris.velocity.x = dir_x * nova_speed;
|
||||
debris.velocity.y = dir_y * nova_speed;
|
||||
} else {
|
||||
// Velocitat molt baixa, aturar
|
||||
debris.velocitat.x = 0.0F;
|
||||
debris.velocitat.y = 0.0F;
|
||||
debris.velocity.x = 0.0F;
|
||||
debris.velocity.y = 0.0F;
|
||||
}
|
||||
|
||||
// 2b. Rotar vector de velocitat (trayectoria curva)
|
||||
// 2b. Rotar vector de velocity (trayectoria curva)
|
||||
if (std::abs(debris.velocitat_rot) > 0.01F) {
|
||||
// Calcular angle de rotació aquest frame
|
||||
float dangle = debris.velocitat_rot * delta_time;
|
||||
|
||||
// Rotar vector de velocitat usant matriu de rotació 2D
|
||||
float vel_x_old = debris.velocitat.x;
|
||||
float vel_y_old = debris.velocitat.y;
|
||||
// Rotar vector de velocity usant matriu de rotació 2D
|
||||
float vel_x_old = debris.velocity.x;
|
||||
float vel_y_old = debris.velocity.y;
|
||||
|
||||
float cos_a = std::cos(dangle);
|
||||
float sin_a = std::sin(dangle);
|
||||
|
||||
debris.velocitat.x = (vel_x_old * cos_a) - (vel_y_old * sin_a);
|
||||
debris.velocitat.y = (vel_x_old * sin_a) + (vel_y_old * cos_a);
|
||||
debris.velocity.x = (vel_x_old * cos_a) - (vel_y_old * sin_a);
|
||||
debris.velocity.y = (vel_x_old * sin_a) + (vel_y_old * cos_a);
|
||||
}
|
||||
|
||||
// 2c. Aplicar fricció angular (desacceleració gradual)
|
||||
@@ -275,18 +275,18 @@ void DebrisManager::update(float delta_time) {
|
||||
.y = (debris.p1.y + debris.p2.y) / 2.0F};
|
||||
|
||||
// 4. Actualitzar posició del centre
|
||||
centre.x += debris.velocitat.x * delta_time;
|
||||
centre.y += debris.velocitat.y * delta_time;
|
||||
centre.x += debris.velocity.x * delta_time;
|
||||
centre.y += debris.velocity.y * delta_time;
|
||||
|
||||
// 5. Actualitzar rotació VISUAL
|
||||
debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;
|
||||
|
||||
// 6. Aplicar shrinking (reducció de distància entre punts)
|
||||
// 6. Aplicar shrinking (reducció de distància entre points)
|
||||
float shrink_factor =
|
||||
1.0F - (debris.factor_shrink * debris.temps_vida / debris.temps_max);
|
||||
shrink_factor = std::max(0.0F, shrink_factor); // No negatiu
|
||||
|
||||
// Calcular distància original entre punts
|
||||
// Calcular distància original entre points
|
||||
float dx = debris.p2.x - debris.p1.x;
|
||||
float dy = debris.p2.y - debris.p1.y;
|
||||
|
||||
@@ -304,7 +304,7 @@ void DebrisManager::update(float delta_time) {
|
||||
|
||||
void DebrisManager::draw() const {
|
||||
for (const auto& debris : debris_pool_) {
|
||||
if (!debris.actiu) {
|
||||
if (!debris.active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -318,16 +318,16 @@ void DebrisManager::draw() const {
|
||||
}
|
||||
}
|
||||
|
||||
Debris* DebrisManager::trobar_slot_lliure() {
|
||||
Debris* DebrisManager::findFreeSlot() {
|
||||
for (auto& debris : debris_pool_) {
|
||||
if (!debris.actiu) {
|
||||
if (!debris.active) {
|
||||
return &debris;
|
||||
}
|
||||
}
|
||||
return nullptr; // Pool ple
|
||||
}
|
||||
|
||||
Vec2 DebrisManager::calcular_direccio_explosio(const Vec2& p1,
|
||||
Vec2 DebrisManager::computeExplosionDirection(const Vec2& p1,
|
||||
const Vec2& p2,
|
||||
const Vec2& centre_objecte) const {
|
||||
// 1. Calcular centre del segment
|
||||
@@ -364,16 +364,16 @@ Vec2 DebrisManager::calcular_direccio_explosio(const Vec2& p1,
|
||||
return {.x = final_x, .y = final_y};
|
||||
}
|
||||
|
||||
void DebrisManager::reiniciar() {
|
||||
void DebrisManager::reset() {
|
||||
for (auto& debris : debris_pool_) {
|
||||
debris.actiu = false;
|
||||
debris.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
int DebrisManager::get_num_actius() const {
|
||||
int DebrisManager::getActiveCount() const {
|
||||
int count = 0;
|
||||
for (const auto& debris : debris_pool_) {
|
||||
if (debris.actiu) {
|
||||
if (debris.active) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,20 +20,20 @@ class DebrisManager {
|
||||
public:
|
||||
explicit DebrisManager(SDL_Renderer* renderer);
|
||||
|
||||
// Crear explosió a partir d'una forma
|
||||
// - shape: forma vectorial a explotar
|
||||
// Crear explosió a partir d'una shape
|
||||
// - shape: shape vectorial a explode
|
||||
// - centre: posició del centre de l'objecte
|
||||
// - angle: orientació de l'objecte (radians)
|
||||
// - escala: escala de l'objecte (1.0 = normal)
|
||||
// - velocitat_base: velocitat inicial dels fragments (px/s)
|
||||
// - brightness: factor de brillantor heretat (0.0-1.0, per defecte 1.0)
|
||||
// - velocitat_objecte: velocitat de l'objecte que explota (px/s, per defecte 0)
|
||||
// - velocitat_angular: velocitat angular heretada (rad/s, per defecte 0)
|
||||
// - scale: scale de l'objecte (1.0 = normal)
|
||||
// - velocitat_base: velocity inicial dels fragments (px/s)
|
||||
// - brightness: factor de brightness heretat (0.0-1.0, per defecte 1.0)
|
||||
// - velocitat_objecte: velocity de l'objecte que explota (px/s, per defecte 0)
|
||||
// - velocitat_angular: velocity angular heretada (rad/s, per defecte 0)
|
||||
// - factor_herencia_visual: factor de herència rotació visual (0.0-1.0, per defecte 0.0)
|
||||
void explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
void explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& centre,
|
||||
float angle,
|
||||
float escala,
|
||||
float scale,
|
||||
float velocitat_base,
|
||||
float brightness = 1.0F,
|
||||
const Vec2& velocitat_objecte = {.x = 0.0F, .y = 0.0F},
|
||||
@@ -41,33 +41,33 @@ class DebrisManager {
|
||||
float factor_herencia_visual = 0.0F,
|
||||
const std::string& sound = Defaults::Sound::EXPLOSION);
|
||||
|
||||
// Actualitzar tots els fragments actius
|
||||
// Actualitzar tots els fragments active
|
||||
void update(float delta_time);
|
||||
|
||||
// Dibuixar tots els fragments actius
|
||||
// Dibuixar tots els fragments active
|
||||
void draw() const;
|
||||
|
||||
// Reiniciar tots els fragments (neteja)
|
||||
void reiniciar();
|
||||
void reset();
|
||||
|
||||
// Obtenir número de fragments actius
|
||||
[[nodiscard]] int get_num_actius() const;
|
||||
// Obtenir número de fragments active
|
||||
[[nodiscard]] int getActiveCount() const;
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// Pool de fragments (màxim concurrent)
|
||||
// Un pentàgon té 5 línies, 15 enemics = 75 línies
|
||||
// + nau (3 línies) + bales (5 línies * 3) = 93 línies màxim
|
||||
// + ship (3 línies) + bales (5 línies * 3) = 93 línies màxim
|
||||
// Arrodonit a 100 per seguretat
|
||||
static constexpr int MAX_DEBRIS = 150;
|
||||
std::array<Debris, MAX_DEBRIS> debris_pool_;
|
||||
|
||||
// Trobar primer slot inactiu
|
||||
Debris* trobar_slot_lliure();
|
||||
Debris* findFreeSlot();
|
||||
|
||||
// Calcular direcció d'explosió (radial, des del centre cap al segment)
|
||||
[[nodiscard]] Vec2 calcular_direccio_explosio(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const;
|
||||
[[nodiscard]] Vec2 computeExplosionDirection(const Vec2& p1, const Vec2& p2, const Vec2& centre_objecte) const;
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
|
||||
@@ -9,17 +9,17 @@
|
||||
|
||||
namespace Effects {
|
||||
|
||||
// PuntuacioFlotant: text animat que mostra punts guanyats
|
||||
// S'activa quan es destrueix un enemic i s'esvaeix després d'un temps
|
||||
struct PuntuacioFlotant {
|
||||
// FloatingScore: text animat que mostra points guanyats
|
||||
// S'activa quan es destrueix un enemy i s'esvaeix després d'un time
|
||||
struct FloatingScore {
|
||||
// Text a mostrar (e.g., "100", "150", "200")
|
||||
std::string text;
|
||||
|
||||
// Posició actual (coordenades mundials)
|
||||
Vec2 posicio;
|
||||
Vec2 position;
|
||||
|
||||
// Animació de moviment
|
||||
Vec2 velocitat; // px/s (normalment cap amunt: {0.0f, -30.0f})
|
||||
Vec2 velocity; // px/s (normalment cap amunt: {0.0f, -30.0f})
|
||||
|
||||
// Animació de fade
|
||||
float temps_vida; // Temps transcorregut (segons)
|
||||
@@ -27,7 +27,7 @@ struct PuntuacioFlotant {
|
||||
float brightness; // Brillantor calculada (0.0-1.0)
|
||||
|
||||
// Estat
|
||||
bool actiu;
|
||||
bool active;
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
+26
-26
@@ -1,95 +1,95 @@
|
||||
// gestor_puntuacio_flotant.cpp - Implementació del gestor de números flotants
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
#include "gestor_puntuacio_flotant.hpp"
|
||||
#include "floating_score_manager.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Effects {
|
||||
|
||||
GestorPuntuacioFlotant::GestorPuntuacioFlotant(SDL_Renderer* renderer)
|
||||
FloatingScoreManager::FloatingScoreManager(SDL_Renderer* renderer)
|
||||
: text_(renderer) {
|
||||
// Inicialitzar tots els slots com inactius
|
||||
for (auto& pf : pool_) {
|
||||
pf.actiu = false;
|
||||
pf.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void GestorPuntuacioFlotant::crear(int punts, const Vec2& posicio) {
|
||||
void FloatingScoreManager::crear(int points, const Vec2& position) {
|
||||
// 1. Trobar slot lliure
|
||||
PuntuacioFlotant* pf = trobar_slot_lliure();
|
||||
FloatingScore* pf = findFreeSlot();
|
||||
if (pf == nullptr) {
|
||||
return; // Pool ple (improbable)
|
||||
}
|
||||
|
||||
// 2. Inicialitzar puntuació flotant
|
||||
pf->text = std::to_string(punts);
|
||||
pf->posicio = posicio;
|
||||
pf->velocitat = {.x = Defaults::FloatingScore::VELOCITY_X,
|
||||
pf->text = std::to_string(points);
|
||||
pf->position = position;
|
||||
pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X,
|
||||
.y = Defaults::FloatingScore::VELOCITY_Y};
|
||||
pf->temps_vida = 0.0F;
|
||||
pf->temps_max = Defaults::FloatingScore::LIFETIME;
|
||||
pf->brightness = 1.0F;
|
||||
pf->actiu = true;
|
||||
pf->active = true;
|
||||
}
|
||||
|
||||
void GestorPuntuacioFlotant::update(float delta_time) {
|
||||
void FloatingScoreManager::update(float delta_time) {
|
||||
for (auto& pf : pool_) {
|
||||
if (!pf.actiu) {
|
||||
if (!pf.active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Actualitzar posició (deriva cap amunt)
|
||||
pf.posicio.x += pf.velocitat.x * delta_time;
|
||||
pf.posicio.y += pf.velocitat.y * delta_time;
|
||||
pf.position.x += pf.velocity.x * delta_time;
|
||||
pf.position.y += pf.velocity.y * delta_time;
|
||||
|
||||
// 2. Actualitzar temps de vida
|
||||
// 2. Actualitzar time de vida
|
||||
pf.temps_vida += delta_time;
|
||||
|
||||
// 3. Calcular brightness (fade lineal)
|
||||
float progress = pf.temps_vida / pf.temps_max; // 0.0 → 1.0
|
||||
pf.brightness = 1.0F - progress; // 1.0 → 0.0
|
||||
|
||||
// 4. Desactivar quan acaba el temps
|
||||
// 4. Desactivar quan acaba el time
|
||||
if (pf.temps_vida >= pf.temps_max) {
|
||||
pf.actiu = false;
|
||||
pf.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GestorPuntuacioFlotant::draw() {
|
||||
void FloatingScoreManager::draw() {
|
||||
for (const auto& pf : pool_) {
|
||||
if (!pf.actiu) {
|
||||
if (!pf.active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Renderitzar centrat amb brightness (fade)
|
||||
constexpr float escala = Defaults::FloatingScore::SCALE;
|
||||
constexpr float scale = Defaults::FloatingScore::SCALE;
|
||||
constexpr float spacing = Defaults::FloatingScore::SPACING;
|
||||
|
||||
text_.render_centered(pf.text, pf.posicio, escala, spacing, pf.brightness);
|
||||
text_.renderCentered(pf.text, pf.position, scale, spacing, pf.brightness);
|
||||
}
|
||||
}
|
||||
|
||||
void GestorPuntuacioFlotant::reiniciar() {
|
||||
void FloatingScoreManager::reset() {
|
||||
for (auto& pf : pool_) {
|
||||
pf.actiu = false;
|
||||
pf.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
int GestorPuntuacioFlotant::get_num_actius() const {
|
||||
int FloatingScoreManager::getActiveCount() const {
|
||||
int count = 0;
|
||||
for (const auto& pf : pool_) {
|
||||
if (pf.actiu) {
|
||||
if (pf.active) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
PuntuacioFlotant* GestorPuntuacioFlotant::trobar_slot_lliure() {
|
||||
FloatingScore* FloatingScoreManager::findFreeSlot() {
|
||||
for (auto& pf : pool_) {
|
||||
if (!pf.actiu) {
|
||||
if (!pf.active) {
|
||||
return &pf;
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -10,32 +10,32 @@
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/graphics/vector_text.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "puntuacio_flotant.hpp"
|
||||
#include "floating_score.hpp"
|
||||
|
||||
namespace Effects {
|
||||
|
||||
// Gestor de números de puntuació flotants
|
||||
// Manté un pool de PuntuacioFlotant i gestiona el seu cicle de vida
|
||||
class GestorPuntuacioFlotant {
|
||||
// Manté un pool de FloatingScore i gestiona el seu cicle de vida
|
||||
class FloatingScoreManager {
|
||||
public:
|
||||
explicit GestorPuntuacioFlotant(SDL_Renderer* renderer);
|
||||
explicit FloatingScoreManager(SDL_Renderer* renderer);
|
||||
|
||||
// Crear número flotant
|
||||
// - punts: valor numèric (100, 150, 200)
|
||||
// - posicio: on apareix (normalment centre d'enemic destruït)
|
||||
void crear(int punts, const Vec2& posicio);
|
||||
// - points: valor numèric (100, 150, 200)
|
||||
// - position: on apareix (normalment centre d'enemy destruït)
|
||||
void crear(int points, const Vec2& position);
|
||||
|
||||
// Actualitzar tots els números actius
|
||||
// Actualitzar tots els números active
|
||||
void update(float delta_time);
|
||||
|
||||
// Dibuixar tots els números actius
|
||||
// Dibuixar tots els números active
|
||||
void draw();
|
||||
|
||||
// Reiniciar tots (neteja)
|
||||
void reiniciar();
|
||||
void reset();
|
||||
|
||||
// Obtenir número actius (debug)
|
||||
[[nodiscard]] int get_num_actius() const;
|
||||
// Obtenir número active (debug)
|
||||
[[nodiscard]] int getActiveCount() const;
|
||||
|
||||
private:
|
||||
Graphics::VectorText text_; // Sistema de text vectorial
|
||||
@@ -44,10 +44,10 @@ class GestorPuntuacioFlotant {
|
||||
// Màxim 15 enemics simultanis = màxim 15 números
|
||||
static constexpr int MAX_PUNTUACIONS =
|
||||
Defaults::FloatingScore::MAX_CONCURRENT;
|
||||
std::array<PuntuacioFlotant, MAX_PUNTUACIONS> pool_;
|
||||
std::array<FloatingScore, MAX_PUNTUACIONS> pool_;
|
||||
|
||||
// Trobar primer slot inactiu
|
||||
PuntuacioFlotant* trobar_slot_lliure();
|
||||
FloatingScore* findFreeSlot();
|
||||
};
|
||||
|
||||
} // namespace Effects
|
||||
@@ -1,4 +1,4 @@
|
||||
// bala.cpp - Implementació de projectils de la nau
|
||||
// bullet.cpp - Implementació de projectils de la ship
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
@@ -26,11 +26,11 @@ Bullet::Bullet(SDL_Renderer* renderer)
|
||||
// [NUEVO] Brightness específic per bales
|
||||
brightness_ = Defaults::Brightness::BALA;
|
||||
|
||||
// [NUEVO] Carregar forma compartida des de fitxer
|
||||
// [NUEVO] Carregar shape compartida des de fitxer
|
||||
shape_ = Graphics::ShapeLoader::load("bullet.shp");
|
||||
|
||||
if (!shape_ || !shape_->es_valida()) {
|
||||
std::cerr << "[Bullet] Error: no s'ha pogut carregar bullet.shp" << '\n';
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
std::cerr << "[Bullet] Error: no s'ha pogut load bullet.shp" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,18 +43,18 @@ void Bullet::init() {
|
||||
grace_timer_ = 0.0F;
|
||||
}
|
||||
|
||||
void Bullet::disparar(const Vec2& posicio, float angle, uint8_t owner_id) {
|
||||
// Activar bala i posicionar-la a la nau
|
||||
void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||||
// Activar bullet i posicionar-la a la ship
|
||||
// Basat en joc_asteroides.cpp línies 188-200
|
||||
|
||||
// Activar bala
|
||||
// Activar bullet
|
||||
esta_ = true;
|
||||
|
||||
// Posició inicial = centre de la nau
|
||||
center_.x = posicio.x;
|
||||
center_.y = posicio.y;
|
||||
// Posició inicial = centre de la ship
|
||||
center_.x = position.x;
|
||||
center_.y = position.y;
|
||||
|
||||
// Angle = angle de la nau (dispara en la direcció que apunta)
|
||||
// Angle = angle de la ship (dispara en la direcció que apunta)
|
||||
angle_ = angle;
|
||||
|
||||
// Almacenar propietario (0=P1, 1=P2)
|
||||
@@ -92,12 +92,12 @@ void Bullet::draw() const {
|
||||
}
|
||||
|
||||
void Bullet::mou(float delta_time) {
|
||||
// Moviment rectilini de la bala
|
||||
// Moviment rectilini de la bullet
|
||||
// Basat en el codi Pascal original: procedure mou_bales
|
||||
// Copiat EXACTAMENT de joc_asteroides.cpp línies 396-419
|
||||
|
||||
// Calcular nova posició (moviment polar time-based)
|
||||
// velocitat ja està en px/s (140 px/s), només cal multiplicar per delta_time
|
||||
// velocity ja està en px/s (140 px/s), només cal multiplicar per delta_time
|
||||
float velocitat_efectiva = velocity_ * delta_time;
|
||||
|
||||
// Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt)
|
||||
@@ -109,7 +109,7 @@ void Bullet::mou(float delta_time) {
|
||||
center_.x += dx;
|
||||
|
||||
// Desactivar si surt de la zona de joc (no rebota com els ORNIs)
|
||||
// CORRECCIÓ: Usar límits segurs amb radi de la bala
|
||||
// CORRECCIÓ: Usar límits segurs amb radi de la bullet
|
||||
float min_x;
|
||||
float max_x;
|
||||
float min_y;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// bala.hpp - Classe per a projectils de la nau
|
||||
// bullet.hpp - Classe per a projectils de la ship
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
@@ -18,7 +18,7 @@ class Bullet : public Entities::Entity {
|
||||
Bullet(SDL_Renderer* renderer);
|
||||
|
||||
void init() override;
|
||||
void disparar(const Vec2& posicio, float angle, uint8_t owner_id);
|
||||
void disparar(const Vec2& position, float angle, uint8_t owner_id);
|
||||
void update(float delta_time) override;
|
||||
void draw() const override;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// enemic.cpp - Implementació d'enemics (ORNIs)
|
||||
// enemy.cpp - Implementació d'enemics (ORNIs)
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
@@ -30,15 +30,15 @@ Enemy::Enemy(SDL_Renderer* renderer)
|
||||
// [NUEVO] Brightness específic per enemics
|
||||
brightness_ = Defaults::Brightness::ENEMIC;
|
||||
|
||||
// [NUEVO] Forma es carrega a init() segons el tipus
|
||||
// Constructor no carrega forma per permetre tipus diferents
|
||||
// [NUEVO] Forma es carrega a init() segons el type
|
||||
// Constructor no carrega shape per permetre type diferents
|
||||
}
|
||||
|
||||
void Enemy::init(EnemyType tipus, const Vec2* ship_pos) {
|
||||
// Guardar tipus
|
||||
type_ = tipus;
|
||||
void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
// Guardar type
|
||||
type_ = type;
|
||||
|
||||
// Carregar forma segons el tipus
|
||||
// Carregar shape segons el type
|
||||
const char* shape_file;
|
||||
float drotacio_min;
|
||||
float drotacio_max;
|
||||
@@ -68,7 +68,7 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) {
|
||||
|
||||
default:
|
||||
// Fallback segur: usar valors de PENTAGON
|
||||
std::cerr << "[Enemy] Error: tipus desconegut ("
|
||||
std::cerr << "[Enemy] Error: type desconegut ("
|
||||
<< static_cast<int>(type_) << "), utilitzant PENTAGON\n";
|
||||
shape_file = Defaults::Enemies::Pentagon::SHAPE_FILE;
|
||||
velocity_ = Defaults::Enemies::Pentagon::VELOCITAT;
|
||||
@@ -77,10 +77,10 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Carregar forma
|
||||
// Carregar shape
|
||||
shape_ = Graphics::ShapeLoader::load(shape_file);
|
||||
if (!shape_ || !shape_->es_valida()) {
|
||||
std::cerr << "[Enemy] Error: no s'ha pogut carregar " << shape_file << '\n';
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
std::cerr << "[Enemy] Error: no s'ha pogut load " << shape_file << '\n';
|
||||
}
|
||||
|
||||
// [MODIFIED] Posició aleatòria amb comprovació de seguretat
|
||||
@@ -131,12 +131,12 @@ void Enemy::init(EnemyType tipus, const Vec2* ship_pos) {
|
||||
// Angle aleatori de moviment
|
||||
angle_ = (std::rand() % 360) * Constants::PI / 180.0F;
|
||||
|
||||
// Rotació visual aleatòria (rad/s) dins del rang del tipus
|
||||
// Rotació visual aleatòria (rad/s) dins del rang del type
|
||||
float drotacio_range = drotacio_max - drotacio_min;
|
||||
drotacio_ = drotacio_min + ((static_cast<float>(std::rand()) / RAND_MAX) * drotacio_range);
|
||||
rotacio_ = 0.0F;
|
||||
|
||||
// Inicialitzar estat d'animació
|
||||
// Inicialitzar state d'animació
|
||||
animacio_ = EnemyAnimation(); // Reset to defaults
|
||||
animacio_.drotacio_base = drotacio_;
|
||||
animacio_.drotacio_objetivo = drotacio_;
|
||||
@@ -182,15 +182,15 @@ void Enemy::update(float delta_time) {
|
||||
void Enemy::draw() const {
|
||||
if (esta_ && shape_) {
|
||||
// Calculate animated scale (includes invulnerability LERP)
|
||||
float escala = calcular_escala_actual();
|
||||
float scale = calcular_escala_actual();
|
||||
|
||||
// brightness_ is already updated in update()
|
||||
Rendering::render_shape(renderer_, shape_, center_, rotacio_, escala, 1.0F, brightness_);
|
||||
Rendering::render_shape(renderer_, shape_, center_, rotacio_, scale, 1.0F, brightness_);
|
||||
}
|
||||
}
|
||||
|
||||
void Enemy::mou(float delta_time) {
|
||||
// Dispatcher: crida el comportament específic segons el tipus
|
||||
// Dispatcher: crida el comportament específic segons el type
|
||||
switch (type_) {
|
||||
case EnemyType::PENTAGON:
|
||||
comportament_pentagon(delta_time);
|
||||
@@ -472,7 +472,7 @@ void Enemy::actualitzar_rotacio_accelerada(float delta_time) {
|
||||
}
|
||||
|
||||
float Enemy::calcular_escala_actual() const {
|
||||
float escala = 1.0F;
|
||||
float scale = 1.0F;
|
||||
|
||||
// [NEW] Invulnerability LERP prioritza sobre palpitació
|
||||
if (timer_invulnerabilitat_ > 0.0F) {
|
||||
@@ -486,13 +486,13 @@ float Enemy::calcular_escala_actual() const {
|
||||
// LERP scale from 0.0 to 1.0
|
||||
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_START;
|
||||
constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_END;
|
||||
escala = START + ((END - START) * smooth_t);
|
||||
scale = START + ((END - START) * smooth_t);
|
||||
} else if (animacio_.palpitacio_activa) {
|
||||
// [EXISTING] Palpitació només quan no invulnerable
|
||||
escala += animacio_.palpitacio_amplitud * std::sin(animacio_.palpitacio_fase);
|
||||
scale += animacio_.palpitacio_amplitud * std::sin(animacio_.palpitacio_fase);
|
||||
}
|
||||
|
||||
return escala;
|
||||
return scale;
|
||||
}
|
||||
|
||||
// [NEW] Stage system API implementations
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// enemic.hpp - Classe per a enemics (ORNIs pentàgons)
|
||||
// enemy.hpp - Classe per a enemics (ORNIs pentàgons)
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
// Tipus d'enemic
|
||||
// Tipus d'enemy
|
||||
enum class EnemyType : uint8_t {
|
||||
PENTAGON = 0, // Pentàgon esquivador (zigzag)
|
||||
QUADRAT = 1, // Quadrat perseguidor (tracks ship)
|
||||
@@ -43,7 +43,7 @@ class Enemy : public Entities::Entity {
|
||||
Enemy(SDL_Renderer* renderer);
|
||||
|
||||
void init() override { init(EnemyType::PENTAGON, nullptr); }
|
||||
void init(EnemyType tipus, const Vec2* ship_pos = nullptr);
|
||||
void init(EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
void update(float delta_time) override;
|
||||
void draw() const override;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// nau.cpp - Implementació de la nave del jugador
|
||||
// ship.cpp - Implementació de la nave del player
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
@@ -28,21 +28,21 @@ Ship::Ship(SDL_Renderer* renderer, const char* shape_file)
|
||||
// [NUEVO] Brightness específic per naus
|
||||
brightness_ = Defaults::Brightness::NAU;
|
||||
|
||||
// [NUEVO] Carregar forma compartida des de fitxer
|
||||
// [NUEVO] Carregar shape compartida des de fitxer
|
||||
shape_ = Graphics::ShapeLoader::load(shape_file);
|
||||
|
||||
if (!shape_ || !shape_->es_valida()) {
|
||||
std::cerr << "[Ship] Error: no s'ha pogut carregar " << shape_file << '\n';
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
std::cerr << "[Ship] Error: no s'ha pogut load " << shape_file << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
// Inicialització de la nau (triangle)
|
||||
// Inicialització de la ship (triangle)
|
||||
// Basat en el codi Pascal original: lines 380-384
|
||||
// Copiat de joc_asteroides.cpp línies 30-44
|
||||
|
||||
// [NUEVO] Ja no cal configurar punts polars - la geometria es carrega del
|
||||
// fitxer Només inicialitzem l'estat de la instància
|
||||
// [NUEVO] Ja no cal configurar points polars - la geometria es carrega del
|
||||
// fitxer Només inicialitzem l'state de la instància
|
||||
|
||||
// Use custom spawn point if provided, otherwise use center
|
||||
if (spawn_point != nullptr) {
|
||||
@@ -74,14 +74,14 @@ void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
void Ship::processInput(float delta_time, uint8_t player_id) {
|
||||
// Processar input continu (com teclapuls() del Pascal original)
|
||||
// Basat en joc_asteroides.cpp línies 66-85
|
||||
// Només processa input si la nau està viva
|
||||
// Només processa input si la ship està viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* input = Input::get();
|
||||
|
||||
// Processar input segons el jugador
|
||||
// Processar input segons el player
|
||||
if (player_id == 0) {
|
||||
// Jugador 1
|
||||
if (input->checkActionPlayer1(InputAction::RIGHT, Input::ALLOW_REPEAT)) {
|
||||
@@ -118,7 +118,7 @@ void Ship::processInput(float delta_time, uint8_t player_id) {
|
||||
}
|
||||
|
||||
void Ship::update(float delta_time) {
|
||||
// Només update si la nau està viva
|
||||
// Només update si la ship està viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
@@ -134,7 +134,7 @@ void Ship::update(float delta_time) {
|
||||
}
|
||||
|
||||
void Ship::draw() const {
|
||||
// Només draw si la nau està viva
|
||||
// Només draw si la ship està viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
@@ -156,25 +156,25 @@ void Ship::draw() const {
|
||||
return;
|
||||
}
|
||||
|
||||
// Escalar velocitat per l'efecte visual (200 px/s → ~6 px d'efecte)
|
||||
// El codi Pascal original sumava velocitat (0-6) al radi per donar
|
||||
// sensació de "empenta". Ara velocitat està en px/s (0-200).
|
||||
// Escalar velocity per l'efecte visual (200 px/s → ~6 px d'efecte)
|
||||
// El codi Pascal original sumava velocity (0-6) al radi per donar
|
||||
// sensació de "empenta". Ara velocity està en px/s (0-200).
|
||||
// Basat en joc_asteroides.cpp línies 127-134
|
||||
//
|
||||
// [NUEVO] Convertir suma de velocitat_visual a escala multiplicativa
|
||||
// [NUEVO] Convertir suma de velocitat_visual a scale multiplicativa
|
||||
// Radio base del ship = 12 px
|
||||
// velocitat_visual = 0-6 → r = 12-18 → escala = 1.0-1.5
|
||||
// velocitat_visual = 0-6 → r = 12-18 → scale = 1.0-1.5
|
||||
float velocitat_visual = velocity_ / 33.33F;
|
||||
float escala = 1.0F + (velocitat_visual / 12.0F);
|
||||
float scale = 1.0F + (velocitat_visual / 12.0F);
|
||||
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, escala, 1.0F, brightness_);
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, scale, 1.0F, brightness_);
|
||||
}
|
||||
|
||||
void Ship::applyPhysics(float delta_time) {
|
||||
// Aplicar física de moviment
|
||||
// Basat en joc_asteroides.cpp línies 87-113
|
||||
|
||||
// Calcular nova posició basada en velocitat i angle
|
||||
// Calcular nova posició basada en velocity i angle
|
||||
// S'usa (angle - PI/2) perquè angle=0 apunta cap amunt, no cap a la dreta
|
||||
// velocity_ està en px/s, així que multipliquem per delta_time
|
||||
float dy =
|
||||
@@ -184,7 +184,7 @@ void Ship::applyPhysics(float delta_time) {
|
||||
((velocity_ * delta_time) * std::cos(angle_ - (Constants::PI / 2.0F))) +
|
||||
center_.x;
|
||||
|
||||
// Boundary checking amb radi de la nau
|
||||
// Boundary checking amb radi de la ship
|
||||
// CORRECCIÓ: Usar límits segurs i inequalitats inclusives
|
||||
float min_x;
|
||||
float max_x;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// nau.hpp - Classe per a la nave del jugador
|
||||
// ship.hpp - Classe per a la nave del player
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ void init() {
|
||||
// Establir la ruta del fitxer de configuració
|
||||
void setConfigFile(const std::string& path) { config_file_path = path; }
|
||||
|
||||
// Funcions auxiliars per carregar seccions del YAML
|
||||
// Funcions auxiliars per load seccions del YAML
|
||||
|
||||
static void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
|
||||
if (yaml.contains("window")) {
|
||||
@@ -446,7 +446,7 @@ static void loadAudioConfigFromYaml(const fkyaml::node& yaml) {
|
||||
}
|
||||
}
|
||||
|
||||
// Carregar controls del jugador 1 des de YAML
|
||||
// Carregar controls del player 1 des de YAML
|
||||
static void loadPlayer1ControlsFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("player1")) {
|
||||
return;
|
||||
@@ -494,7 +494,7 @@ static void loadPlayer1ControlsFromYaml(const fkyaml::node& yaml) {
|
||||
}
|
||||
}
|
||||
|
||||
// Carregar controls del jugador 2 des de YAML
|
||||
// Carregar controls del player 2 des de YAML
|
||||
static void loadPlayer2ControlsFromYaml(const fkyaml::node& yaml) {
|
||||
if (!yaml.contains("player2")) {
|
||||
return;
|
||||
@@ -611,7 +611,7 @@ auto loadFromFile() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
// Guardar controls del jugador 1 a YAML
|
||||
// Guardar controls del player 1 a YAML
|
||||
static void savePlayer1ControlsToYaml(std::ofstream& file) {
|
||||
file << "# CONTROLS JUGADOR 1\n";
|
||||
file << "player1:\n";
|
||||
@@ -628,7 +628,7 @@ static void savePlayer1ControlsToYaml(std::ofstream& file) {
|
||||
file << " gamepad_name: \"" << player1.gamepad_name << "\" # Buit = primer disponible\n\n";
|
||||
}
|
||||
|
||||
// Guardar controls del jugador 2 a YAML
|
||||
// Guardar controls del player 2 a YAML
|
||||
static void savePlayer2ControlsToYaml(std::ofstream& file) {
|
||||
file << "# CONTROLS JUGADOR 2\n";
|
||||
file << "player2:\n";
|
||||
|
||||
@@ -83,7 +83,7 @@ inline Gameplay gameplay{};
|
||||
inline Rendering rendering{};
|
||||
inline Audio audio{};
|
||||
|
||||
// Controles per jugador
|
||||
// Controles per player
|
||||
inline PlayerControls player1{
|
||||
.keyboard =
|
||||
{.key_left = SDL_SCANCODE_LEFT,
|
||||
|
||||
+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)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ SpawnController::SpawnController()
|
||||
index_spawn_actual_(0),
|
||||
ship_position_(nullptr) {}
|
||||
|
||||
void SpawnController::configurar(const ConfigStage* config) {
|
||||
void SpawnController::configurar(const StageConfig* config) {
|
||||
config_ = config;
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ void SpawnController::update(float delta_time, std::array<Enemy, 15>& orni_array
|
||||
|
||||
if (temps_transcorregut_ >= event.temps_spawn) {
|
||||
// Find first inactive enemy
|
||||
for (auto& enemic : orni_array) {
|
||||
if (!enemic.isActive()) {
|
||||
spawn_enemic(enemic, event.tipus, ship_position_);
|
||||
for (auto& enemy : orni_array) {
|
||||
if (!enemy.isActive()) {
|
||||
spawn_enemic(enemy, event.type, ship_position_);
|
||||
event.spawnejat = true;
|
||||
index_spawn_actual_++;
|
||||
break;
|
||||
@@ -94,8 +94,8 @@ bool SpawnController::tots_enemics_destruits(const std::array<Enemy, 15>& orni_a
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& enemic : orni_array) {
|
||||
if (enemic.isActive()) {
|
||||
for (const auto& enemy : orni_array) {
|
||||
if (enemy.isActive()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -105,8 +105,8 @@ bool SpawnController::tots_enemics_destruits(const std::array<Enemy, 15>& orni_a
|
||||
|
||||
uint8_t SpawnController::get_enemics_vius(const std::array<Enemy, 15>& orni_array) const {
|
||||
uint8_t count = 0;
|
||||
for (const auto& enemic : orni_array) {
|
||||
if (enemic.isActive()) {
|
||||
for (const auto& enemy : orni_array) {
|
||||
if (enemy.isActive()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -126,9 +126,9 @@ void SpawnController::generar_spawn_events() {
|
||||
float spawn_time = config_->config_spawn.delay_inicial +
|
||||
(i * config_->config_spawn.interval_spawn);
|
||||
|
||||
EnemyType tipus = seleccionar_tipus_aleatori();
|
||||
EnemyType type = seleccionar_tipus_aleatori();
|
||||
|
||||
spawn_queue_.push_back({spawn_time, tipus, false});
|
||||
spawn_queue_.push_back({spawn_time, type, false});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,29 +149,29 @@ EnemyType SpawnController::seleccionar_tipus_aleatori() const {
|
||||
return EnemyType::MOLINILLO;
|
||||
}
|
||||
|
||||
void SpawnController::spawn_enemic(Enemy& enemic, EnemyType tipus, const Vec2* ship_pos) {
|
||||
void SpawnController::spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos) {
|
||||
// Initialize enemy (with safe spawn if ship_pos provided)
|
||||
enemic.init(tipus, ship_pos);
|
||||
enemy.init(type, ship_pos);
|
||||
|
||||
// Apply difficulty multipliers
|
||||
aplicar_multiplicadors(enemic);
|
||||
aplicar_multiplicadors(enemy);
|
||||
}
|
||||
|
||||
void SpawnController::aplicar_multiplicadors(Enemy& enemic) const {
|
||||
void SpawnController::aplicar_multiplicadors(Enemy& enemy) const {
|
||||
if (config_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply velocity multiplier
|
||||
float base_vel = enemic.get_base_velocity();
|
||||
enemic.set_velocity(base_vel * config_->multiplicadors.velocitat);
|
||||
float base_vel = enemy.get_base_velocity();
|
||||
enemy.set_velocity(base_vel * config_->multiplicadors.velocity);
|
||||
|
||||
// Apply rotation multiplier
|
||||
float base_rot = enemic.get_base_rotation();
|
||||
enemic.set_rotation(base_rot * config_->multiplicadors.rotacio);
|
||||
float base_rot = enemy.get_base_rotation();
|
||||
enemy.set_rotation(base_rot * config_->multiplicadors.rotation);
|
||||
|
||||
// Apply tracking strength (only affects QUADRAT)
|
||||
enemic.set_tracking_strength(config_->multiplicadors.tracking_strength);
|
||||
enemy.set_tracking_strength(config_->multiplicadors.tracking_strength);
|
||||
}
|
||||
|
||||
} // namespace StageSystem
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace StageSystem {
|
||||
// Informació de spawn planificat
|
||||
struct SpawnEvent {
|
||||
float temps_spawn; // Temps absolut (segons) per spawnejar
|
||||
EnemyType tipus; // Tipus d'enemic
|
||||
EnemyType type; // Tipus d'enemy
|
||||
bool spawnejat; // Ja s'ha processat?
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ class SpawnController {
|
||||
SpawnController();
|
||||
|
||||
// Configuration
|
||||
void configurar(const ConfigStage* config); // Set stage config
|
||||
void configurar(const StageConfig* config); // Set stage config
|
||||
void iniciar(); // Generate spawn schedule
|
||||
void reset(); // Clear all pending spawns
|
||||
|
||||
@@ -42,7 +42,7 @@ class SpawnController {
|
||||
void set_ship_position(const Vec2* ship_pos) { ship_position_ = ship_pos; }
|
||||
|
||||
private:
|
||||
const ConfigStage* config_; // Non-owning pointer to current stage config
|
||||
const StageConfig* config_; // Non-owning pointer to current stage config
|
||||
std::vector<SpawnEvent> spawn_queue_;
|
||||
float temps_transcorregut_; // Elapsed time since stage start
|
||||
uint8_t index_spawn_actual_; // Next spawn to process
|
||||
@@ -50,8 +50,8 @@ class SpawnController {
|
||||
// Spawn generation
|
||||
void generar_spawn_events();
|
||||
[[nodiscard]] EnemyType seleccionar_tipus_aleatori() const;
|
||||
void spawn_enemic(Enemy& enemic, EnemyType tipus, const Vec2* ship_pos = nullptr);
|
||||
void aplicar_multiplicadors(Enemy& enemic) const;
|
||||
void spawn_enemic(Enemy& enemy, EnemyType type, const Vec2* ship_pos = nullptr);
|
||||
void aplicar_multiplicadors(Enemy& enemy) const;
|
||||
const Vec2* ship_position_; // [NEW] Non-owning pointer to ship position
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ struct ConfigSpawn {
|
||||
float interval_spawn; // Segons entre spawns consecutius
|
||||
};
|
||||
|
||||
// Distribució de tipus d'enemics (percentatges)
|
||||
// Distribució de type d'enemics (percentatges)
|
||||
struct DistribucioEnemics {
|
||||
uint8_t pentagon; // 0-100
|
||||
uint8_t quadrat; // 0-100
|
||||
@@ -34,8 +34,8 @@ struct DistribucioEnemics {
|
||||
|
||||
// Multiplicadors de dificultat
|
||||
struct MultiplicadorsDificultat {
|
||||
float velocitat; // 0.5-2.0 típic
|
||||
float rotacio; // 0.5-2.0 típic
|
||||
float velocity; // 0.5-2.0 típic
|
||||
float rotation; // 0.5-2.0 típic
|
||||
float tracking_strength; // 0.0-1.5 (aplicat a Quadrat)
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ struct MetadataStages {
|
||||
};
|
||||
|
||||
// Configuració completa d'un stage
|
||||
struct ConfigStage {
|
||||
struct StageConfig {
|
||||
uint8_t stage_id; // 1-10
|
||||
uint8_t total_enemics; // 5-15
|
||||
ConfigSpawn config_spawn;
|
||||
@@ -63,12 +63,12 @@ struct ConfigStage {
|
||||
};
|
||||
|
||||
// Configuració completa del sistema (carregada des de YAML)
|
||||
struct ConfigSistemaStages {
|
||||
struct StageSystemConfig {
|
||||
MetadataStages metadata;
|
||||
std::vector<ConfigStage> stages; // Índex [0] = stage 1
|
||||
std::vector<StageConfig> stages; // Índex [0] = stage 1
|
||||
|
||||
// Obtenir configuració d'un stage específic
|
||||
[[nodiscard]] const ConfigStage* obte_stage(uint8_t stage_id) const {
|
||||
[[nodiscard]] const StageConfig* obte_stage(uint8_t stage_id) const {
|
||||
if (stage_id < 1 || stage_id > stages.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace StageSystem {
|
||||
|
||||
std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& path) {
|
||||
std::unique_ptr<StageSystemConfig> StageLoader::load(const std::string& path) {
|
||||
try {
|
||||
// Normalize path: "data/stages/stages.yaml" → "stages/stages.yaml"
|
||||
std::string normalized = path;
|
||||
@@ -30,7 +30,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[StageLoader] Error: no es pot carregar " << normalized << '\n';
|
||||
std::cerr << "[StageLoader] Error: no es pot load " << normalized << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
||||
|
||||
// Parse YAML
|
||||
fkyaml::node yaml = fkyaml::node::deserialize(stream);
|
||||
auto config = std::make_unique<ConfigSistemaStages>();
|
||||
auto config = std::make_unique<StageSystemConfig>();
|
||||
|
||||
// Parse metadata
|
||||
if (!yaml.contains("metadata")) {
|
||||
@@ -63,7 +63,7 @@ std::unique_ptr<ConfigSistemaStages> StageLoader::carregar(const std::string& pa
|
||||
}
|
||||
|
||||
for (const auto& stage_yaml : yaml["stages"]) {
|
||||
ConfigStage stage;
|
||||
StageConfig stage;
|
||||
if (!parse_stage(stage_yaml, stage)) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ bool StageLoader::parse_metadata(const fkyaml::node& yaml, MetadataStages& meta)
|
||||
}
|
||||
}
|
||||
|
||||
bool StageLoader::parse_stage(const fkyaml::node& yaml, ConfigStage& stage) {
|
||||
bool StageLoader::parse_stage(const fkyaml::node& yaml, StageConfig& stage) {
|
||||
try {
|
||||
if (!yaml.contains("stage_id") || !yaml.contains("total_enemies") ||
|
||||
!yaml.contains("spawn_config") || !yaml.contains("enemy_distribution") ||
|
||||
@@ -194,15 +194,15 @@ bool StageLoader::parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDifi
|
||||
return false;
|
||||
}
|
||||
|
||||
mult.velocitat = yaml["speed_multiplier"].get_value<float>();
|
||||
mult.rotacio = yaml["rotation_multiplier"].get_value<float>();
|
||||
mult.velocity = yaml["speed_multiplier"].get_value<float>();
|
||||
mult.rotation = yaml["rotation_multiplier"].get_value<float>();
|
||||
mult.tracking_strength = yaml["tracking_strength"].get_value<float>();
|
||||
|
||||
// Validar rangs raonables
|
||||
if (mult.velocitat < 0.1F || mult.velocitat > 5.0F) {
|
||||
if (mult.velocity < 0.1F || mult.velocity > 5.0F) {
|
||||
std::cerr << "[StageLoader] Warning: speed_multiplier fora de rang (0.1-5.0)" << '\n';
|
||||
}
|
||||
if (mult.rotacio < 0.1F || mult.rotacio > 5.0F) {
|
||||
if (mult.rotation < 0.1F || mult.rotation > 5.0F) {
|
||||
std::cerr << "[StageLoader] Warning: rotation_multiplier fora de rang (0.1-5.0)" << '\n';
|
||||
}
|
||||
if (mult.tracking_strength < 0.0F || mult.tracking_strength > 2.0F) {
|
||||
@@ -231,7 +231,7 @@ ModeSpawn StageLoader::parse_spawn_mode(const std::string& mode_str) {
|
||||
return ModeSpawn::PROGRESSIVE;
|
||||
}
|
||||
|
||||
bool StageLoader::validar_config(const ConfigSistemaStages& config) {
|
||||
bool StageLoader::validar_config(const StageSystemConfig& config) {
|
||||
if (config.stages.empty()) {
|
||||
std::cerr << "[StageLoader] Error: cap stage carregat" << '\n';
|
||||
return false;
|
||||
|
||||
@@ -15,19 +15,19 @@ class StageLoader {
|
||||
public:
|
||||
// Carregar configuració des de fitxer YAML
|
||||
// Retorna nullptr si hi ha errors
|
||||
static std::unique_ptr<ConfigSistemaStages> carregar(const std::string& path);
|
||||
static std::unique_ptr<StageSystemConfig> load(const std::string& path);
|
||||
|
||||
private:
|
||||
// Parsing helpers (implementats en .cpp)
|
||||
static bool parse_metadata(const fkyaml::node& yaml, MetadataStages& meta);
|
||||
static bool parse_stage(const fkyaml::node& yaml, ConfigStage& stage);
|
||||
static bool parse_stage(const fkyaml::node& yaml, StageConfig& stage);
|
||||
static bool parse_spawn_config(const fkyaml::node& yaml, ConfigSpawn& config);
|
||||
static bool parse_distribution(const fkyaml::node& yaml, DistribucioEnemics& dist);
|
||||
static bool parse_multipliers(const fkyaml::node& yaml, MultiplicadorsDificultat& mult);
|
||||
static ModeSpawn parse_spawn_mode(const std::string& mode_str);
|
||||
|
||||
// Validació
|
||||
static bool validar_config(const ConfigSistemaStages& config);
|
||||
static bool validar_config(const StageSystemConfig& config);
|
||||
};
|
||||
|
||||
} // namespace StageSystem
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace StageSystem {
|
||||
|
||||
StageManager::StageManager(const ConfigSistemaStages* config)
|
||||
StageManager::StageManager(const StageSystemConfig* config)
|
||||
: config_(config),
|
||||
estat_(EstatStage::LEVEL_START),
|
||||
stage_actual_(1),
|
||||
@@ -65,7 +65,7 @@ bool StageManager::tot_completat() const {
|
||||
timer_transicio_ <= 0.0F;
|
||||
}
|
||||
|
||||
const ConfigStage* StageManager::get_config_actual() const {
|
||||
const StageConfig* StageManager::get_config_actual() const {
|
||||
return config_->obte_stage(stage_actual_);
|
||||
}
|
||||
|
||||
@@ -87,13 +87,13 @@ void StageManager::canviar_estat(EstatStage nou_estat) {
|
||||
missatge_level_start_actual_ = Constants::MISSATGES_LEVEL_START[index];
|
||||
|
||||
// [NOU] Iniciar música al entrar en LEVEL_START (després de INIT_HUD)
|
||||
// Només si no està sonant ja (per evitar reiniciar en loops posteriors)
|
||||
// Només si no està sonant ja (per evitar reset en loops posteriors)
|
||||
if (Audio::get()->getMusicState() != Audio::MusicState::PLAYING) {
|
||||
Audio::get()->playMusic("game.ogg");
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "[StageManager] Canvi d'estat: ";
|
||||
std::cout << "[StageManager] Canvi d'state: ";
|
||||
switch (nou_estat) {
|
||||
case EstatStage::INIT_HUD:
|
||||
std::cout << "INIT_HUD";
|
||||
@@ -156,7 +156,7 @@ void StageManager::processar_level_completed(float delta_time) {
|
||||
}
|
||||
|
||||
void StageManager::carregar_stage(uint8_t stage_id) {
|
||||
const ConfigStage* stage_config = config_->obte_stage(stage_id);
|
||||
const StageConfig* stage_config = config_->obte_stage(stage_id);
|
||||
if (stage_config == nullptr) {
|
||||
std::cerr << "[StageManager] Error: no es pot trobar stage " << static_cast<int>(stage_id)
|
||||
<< '\n';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// stage_manager.hpp - Gestor d'estat i progressió d'stages
|
||||
// stage_manager.hpp - Gestor d'state i progressió d'stages
|
||||
// © 2025 Orni Attack
|
||||
|
||||
#pragma once
|
||||
@@ -21,7 +21,7 @@ enum class EstatStage {
|
||||
|
||||
class StageManager {
|
||||
public:
|
||||
explicit StageManager(const ConfigSistemaStages* config);
|
||||
explicit StageManager(const StageSystemConfig* config);
|
||||
|
||||
// Lifecycle
|
||||
void init(); // Reset to stage 1
|
||||
@@ -34,7 +34,7 @@ class StageManager {
|
||||
// Current state queries
|
||||
[[nodiscard]] EstatStage get_estat() const { return estat_; }
|
||||
[[nodiscard]] uint8_t get_stage_actual() const { return stage_actual_; }
|
||||
[[nodiscard]] const ConfigStage* get_config_actual() const;
|
||||
[[nodiscard]] const StageConfig* get_config_actual() const;
|
||||
[[nodiscard]] float get_timer_transicio() const { return timer_transicio_; }
|
||||
[[nodiscard]] const std::string& get_missatge_level_start() const { return missatge_level_start_actual_; }
|
||||
|
||||
@@ -43,7 +43,7 @@ class StageManager {
|
||||
[[nodiscard]] const SpawnController& get_spawn_controller() const { return spawn_controller_; }
|
||||
|
||||
private:
|
||||
const ConfigSistemaStages* config_; // Non-owning pointer
|
||||
const StageSystemConfig* config_; // Non-owning pointer
|
||||
SpawnController spawn_controller_;
|
||||
|
||||
EstatStage estat_;
|
||||
|
||||
+136
-136
@@ -22,53 +22,53 @@ void ShipAnimator::init() {
|
||||
auto forma_p1 = Graphics::ShapeLoader::load("ship_perspective.shp"); // Perspectiva esquerra
|
||||
auto forma_p2 = Graphics::ShapeLoader::load("ship2_perspective.shp"); // Perspectiva dreta
|
||||
|
||||
// Configurar nau P1
|
||||
naus_[0].jugador_id = 1;
|
||||
naus_[0].forma = forma_p1;
|
||||
configurar_nau_p1(naus_[0]);
|
||||
// Configurar ship P1
|
||||
ships_[0].player_id = 1;
|
||||
ships_[0].shape = forma_p1;
|
||||
configurar_nau_p1(ships_[0]);
|
||||
|
||||
// Configurar nau P2
|
||||
naus_[1].jugador_id = 2;
|
||||
naus_[1].forma = forma_p2;
|
||||
configurar_nau_p2(naus_[1]);
|
||||
// Configurar ship P2
|
||||
ships_[1].player_id = 2;
|
||||
ships_[1].shape = forma_p2;
|
||||
configurar_nau_p2(ships_[1]);
|
||||
}
|
||||
|
||||
void ShipAnimator::update(float delta_time) {
|
||||
// Dispatcher segons estat de cada nau
|
||||
for (auto& nau : naus_) {
|
||||
if (!nau.visible) {
|
||||
// Dispatcher segons state de cada ship
|
||||
for (auto& ship : ships_) {
|
||||
if (!ship.visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (nau.estat) {
|
||||
case EstatNau::ENTERING:
|
||||
actualitzar_entering(nau, delta_time);
|
||||
switch (ship.state) {
|
||||
case ShipState::ENTERING:
|
||||
actualitzar_entering(ship, delta_time);
|
||||
break;
|
||||
case EstatNau::FLOATING:
|
||||
actualitzar_floating(nau, delta_time);
|
||||
case ShipState::FLOATING:
|
||||
actualitzar_floating(ship, delta_time);
|
||||
break;
|
||||
case EstatNau::EXITING:
|
||||
actualitzar_exiting(nau, delta_time);
|
||||
case ShipState::EXITING:
|
||||
actualitzar_exiting(ship, delta_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::draw() const {
|
||||
for (const auto& nau : naus_) {
|
||||
if (!nau.visible) {
|
||||
for (const auto& ship : ships_) {
|
||||
if (!ship.visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Renderitzar nau (perspectiva ja incorporada a la forma)
|
||||
// Renderitzar ship (perspectiva ja incorporada a la shape)
|
||||
Rendering::render_shape(
|
||||
renderer_,
|
||||
nau.forma,
|
||||
nau.posicio_actual,
|
||||
ship.shape,
|
||||
ship.current_position,
|
||||
0.0F, // angle (rotació 2D no utilitzada)
|
||||
nau.escala_actual,
|
||||
ship.current_scale,
|
||||
1.0F, // progress (sempre visible)
|
||||
1.0F // brightness (brillantor màxima)
|
||||
1.0F // brightness (brightness màxima)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -76,46 +76,46 @@ void ShipAnimator::draw() const {
|
||||
void ShipAnimator::start_entry_animation() {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Configurar nau P1 per a l'animació d'entrada
|
||||
naus_[0].estat = EstatNau::ENTERING;
|
||||
naus_[0].temps_estat = 0.0F;
|
||||
naus_[0].posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
naus_[0].posicio_actual = naus_[0].posicio_inicial;
|
||||
naus_[0].escala_actual = naus_[0].escala_inicial;
|
||||
// Configurar ship P1 per a l'animació d'entrada
|
||||
ships_[0].state = ShipState::ENTERING;
|
||||
ships_[0].state_time = 0.0F;
|
||||
ships_[0].initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
ships_[0].current_position = ships_[0].initial_position;
|
||||
ships_[0].current_scale = ships_[0].initial_scale;
|
||||
|
||||
// Configurar nau P2 per a l'animació d'entrada
|
||||
naus_[1].estat = EstatNau::ENTERING;
|
||||
naus_[1].temps_estat = 0.0F;
|
||||
naus_[1].posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
naus_[1].posicio_actual = naus_[1].posicio_inicial;
|
||||
naus_[1].escala_actual = naus_[1].escala_inicial;
|
||||
// Configurar ship P2 per a l'animació d'entrada
|
||||
ships_[1].state = ShipState::ENTERING;
|
||||
ships_[1].state_time = 0.0F;
|
||||
ships_[1].initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
ships_[1].current_position = ships_[1].initial_position;
|
||||
ships_[1].current_scale = ships_[1].initial_scale;
|
||||
}
|
||||
|
||||
void ShipAnimator::trigger_exit_animation() {
|
||||
// Configurar ambdues naus per a l'animació de sortida
|
||||
for (auto& nau : naus_) {
|
||||
// Canviar estat a EXITING
|
||||
nau.estat = EstatNau::EXITING;
|
||||
nau.temps_estat = 0.0F;
|
||||
for (auto& ship : ships_) {
|
||||
// Canviar state a EXITING
|
||||
ship.state = ShipState::EXITING;
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Preservar posició actual (pot estar a mig camí si START es prem durant ENTERING)
|
||||
nau.posicio_inicial = nau.posicio_actual;
|
||||
ship.initial_position = ship.current_position;
|
||||
|
||||
// La escala objectiu es preserva per a calcular la interpolació
|
||||
// (escala_actual pot ser diferent si està en ENTERING)
|
||||
// La scale objectiu es preserva per a calcular la interpolació
|
||||
// (current_scale pot ser diferent si està en ENTERING)
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::skip_to_floating_state() {
|
||||
// Posar ambdues naus directament en estat FLOATING
|
||||
for (auto& nau : naus_) {
|
||||
nau.estat = EstatNau::FLOATING;
|
||||
nau.temps_estat = 0.0F;
|
||||
nau.fase_oscilacio = 0.0F;
|
||||
// Posar ambdues naus directament en state FLOATING
|
||||
for (auto& ship : ships_) {
|
||||
ship.state = ShipState::FLOATING;
|
||||
ship.state_time = 0.0F;
|
||||
ship.oscillation_phase = 0.0F;
|
||||
|
||||
// Posar en posició objectiu (sense animació)
|
||||
nau.posicio_actual = nau.posicio_objectiu;
|
||||
nau.escala_actual = nau.escala_objectiu;
|
||||
ship.current_position = ship.target_position;
|
||||
ship.current_scale = ship.target_scale;
|
||||
|
||||
// NO establir visibilitat aquí - ja ho fa el caller
|
||||
// (evita fer visibles ambdues naus quan només una ha premut START)
|
||||
@@ -123,201 +123,201 @@ void ShipAnimator::skip_to_floating_state() {
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_visible() const {
|
||||
// Retorna true si almenys una nau és visible
|
||||
for (const auto& nau : naus_) {
|
||||
if (nau.visible) {
|
||||
// Retorna true si almenys una ship és visible
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ShipAnimator::trigger_exit_animation_for_player(int jugador_id) {
|
||||
// Trobar la nau del jugador especificat
|
||||
for (auto& nau : naus_) {
|
||||
if (nau.jugador_id == jugador_id) {
|
||||
// Canviar estat a EXITING només per aquesta nau
|
||||
nau.estat = EstatNau::EXITING;
|
||||
nau.temps_estat = 0.0F;
|
||||
void ShipAnimator::trigger_exit_animation_for_player(int player_id) {
|
||||
// Trobar la ship del player especificat
|
||||
for (auto& ship : ships_) {
|
||||
if (ship.player_id == player_id) {
|
||||
// Canviar state a EXITING només per aquesta ship
|
||||
ship.state = ShipState::EXITING;
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Preservar posició actual (pot estar a mig camí si START es prem durant ENTERING)
|
||||
nau.posicio_inicial = nau.posicio_actual;
|
||||
ship.initial_position = ship.current_position;
|
||||
|
||||
// La escala objectiu es preserva per a calcular la interpolació
|
||||
// (escala_actual pot ser diferent si està en ENTERING)
|
||||
break; // Només una nau per jugador
|
||||
// La scale objectiu es preserva per a calcular la interpolació
|
||||
// (current_scale pot ser diferent si està en ENTERING)
|
||||
break; // Només una ship per player
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::set_visible(bool visible) {
|
||||
for (auto& nau : naus_) {
|
||||
nau.visible = visible;
|
||||
for (auto& ship : ships_) {
|
||||
ship.visible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
bool ShipAnimator::is_animation_complete() const {
|
||||
// Comprovar si totes les naus són invisibles (han completat l'animació de sortida)
|
||||
for (const auto& nau : naus_) {
|
||||
if (nau.visible) {
|
||||
return false; // Encara hi ha alguna nau visible
|
||||
for (const auto& ship : ships_) {
|
||||
if (ship.visible) {
|
||||
return false; // Encara hi ha alguna ship visible
|
||||
}
|
||||
}
|
||||
return true; // Totes les naus són invisibles
|
||||
}
|
||||
|
||||
// Mètodes d'animació (stubs)
|
||||
void ShipAnimator::actualitzar_entering(NauTitol& nau, float delta_time) {
|
||||
void ShipAnimator::actualitzar_entering(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
nau.temps_estat += delta_time;
|
||||
ship.state_time += delta_time;
|
||||
|
||||
// Esperar al delay abans de començar l'animació
|
||||
if (nau.temps_estat < nau.entry_delay) {
|
||||
// Encara en delay: la nau es queda fora de pantalla (posició inicial)
|
||||
nau.posicio_actual = nau.posicio_inicial;
|
||||
nau.escala_actual = nau.escala_inicial;
|
||||
if (ship.state_time < ship.entry_delay) {
|
||||
// Encara en delay: la ship es queda fora de pantalla (posició inicial)
|
||||
ship.current_position = ship.initial_position;
|
||||
ship.current_scale = ship.initial_scale;
|
||||
return;
|
||||
}
|
||||
|
||||
// Càlcul del progrés (restant el delay)
|
||||
float elapsed = nau.temps_estat - nau.entry_delay;
|
||||
float elapsed = ship.state_time - ship.entry_delay;
|
||||
float progress = std::min(1.0F, elapsed / ENTRY_DURATION);
|
||||
|
||||
// Aplicar easing (ease_out_quad per arribada suau)
|
||||
float eased_progress = Easing::ease_out_quad(progress);
|
||||
|
||||
// Lerp posició (inicial → objectiu)
|
||||
nau.posicio_actual.x = Easing::lerp(nau.posicio_inicial.x, nau.posicio_objectiu.x, eased_progress);
|
||||
nau.posicio_actual.y = Easing::lerp(nau.posicio_inicial.y, nau.posicio_objectiu.y, eased_progress);
|
||||
ship.current_position.x = Easing::lerp(ship.initial_position.x, ship.target_position.x, eased_progress);
|
||||
ship.current_position.y = Easing::lerp(ship.initial_position.y, ship.target_position.y, eased_progress);
|
||||
|
||||
// Lerp escala (gran → normal)
|
||||
nau.escala_actual = Easing::lerp(nau.escala_inicial, nau.escala_objectiu, eased_progress);
|
||||
// Lerp scale (gran → normal)
|
||||
ship.current_scale = Easing::lerp(ship.initial_scale, ship.target_scale, eased_progress);
|
||||
|
||||
// Transicionar a FLOATING quan completi
|
||||
if (elapsed >= ENTRY_DURATION) {
|
||||
nau.estat = EstatNau::FLOATING;
|
||||
nau.temps_estat = 0.0F;
|
||||
nau.fase_oscilacio = 0.0F; // Reiniciar fase d'oscil·lació
|
||||
ship.state = ShipState::FLOATING;
|
||||
ship.state_time = 0.0F;
|
||||
ship.oscillation_phase = 0.0F; // Reiniciar fase d'oscil·lació
|
||||
}
|
||||
}
|
||||
|
||||
void ShipAnimator::actualitzar_floating(NauTitol& nau, float delta_time) {
|
||||
void ShipAnimator::actualitzar_floating(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Actualitzar temps i fase d'oscil·lació
|
||||
nau.temps_estat += delta_time;
|
||||
nau.fase_oscilacio += delta_time;
|
||||
// Actualitzar time i fase d'oscil·lació
|
||||
ship.state_time += delta_time;
|
||||
ship.oscillation_phase += delta_time;
|
||||
|
||||
// Oscil·lació sinusoïdal X/Y (paràmetres específics per nau)
|
||||
float offset_x = nau.amplitude_x * std::sin(2.0F * Defaults::Math::PI * nau.frequency_x * nau.fase_oscilacio);
|
||||
float offset_y = nau.amplitude_y * std::sin((2.0F * Defaults::Math::PI * nau.frequency_y * nau.fase_oscilacio) + FLOAT_PHASE_OFFSET);
|
||||
// Oscil·lació sinusoïdal X/Y (paràmetres específics per ship)
|
||||
float offset_x = ship.amplitude_x * std::sin(2.0F * Defaults::Math::PI * ship.frequency_x * ship.oscillation_phase);
|
||||
float offset_y = ship.amplitude_y * std::sin((2.0F * Defaults::Math::PI * ship.frequency_y * ship.oscillation_phase) + FLOAT_PHASE_OFFSET);
|
||||
|
||||
// Aplicar oscil·lació a la posició objectiu
|
||||
nau.posicio_actual.x = nau.posicio_objectiu.x + offset_x;
|
||||
nau.posicio_actual.y = nau.posicio_objectiu.y + offset_y;
|
||||
ship.current_position.x = ship.target_position.x + offset_x;
|
||||
ship.current_position.y = ship.target_position.y + offset_y;
|
||||
|
||||
// Escala constant (sense "breathing" per ara)
|
||||
nau.escala_actual = nau.escala_objectiu;
|
||||
ship.current_scale = ship.target_scale;
|
||||
}
|
||||
|
||||
void ShipAnimator::actualitzar_exiting(NauTitol& nau, float delta_time) {
|
||||
void ShipAnimator::actualitzar_exiting(TitleShip& ship, float delta_time) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
nau.temps_estat += delta_time;
|
||||
ship.state_time += delta_time;
|
||||
|
||||
// Calcular progrés (0.0 → 1.0)
|
||||
float progress = std::min(1.0F, nau.temps_estat / EXIT_DURATION);
|
||||
float progress = std::min(1.0F, ship.state_time / EXIT_DURATION);
|
||||
|
||||
// Aplicar easing (ease_in_quad per acceleració cap al punt de fuga)
|
||||
// Aplicar easing (ease_in_quad per acceleració cap al point de fuga)
|
||||
float eased_progress = Easing::ease_in_quad(progress);
|
||||
|
||||
// Vec2 de fuga (centre del starfield)
|
||||
constexpr Vec2 punt_fuga{.x = VANISHING_POINT_X, .y = VANISHING_POINT_Y};
|
||||
|
||||
// Lerp posició cap al punt de fuga (preservar posició inicial actual)
|
||||
// Nota: posicio_inicial conté la posició on estava quan es va activar EXITING
|
||||
nau.posicio_actual.x = Easing::lerp(nau.posicio_inicial.x, punt_fuga.x, eased_progress);
|
||||
nau.posicio_actual.y = Easing::lerp(nau.posicio_inicial.y, punt_fuga.y, eased_progress);
|
||||
// Lerp posició cap al point de fuga (preservar posició inicial actual)
|
||||
// Nota: initial_position conté la posició on estava quan es va activar EXITING
|
||||
ship.current_position.x = Easing::lerp(ship.initial_position.x, punt_fuga.x, eased_progress);
|
||||
ship.current_position.y = Easing::lerp(ship.initial_position.y, punt_fuga.y, eased_progress);
|
||||
|
||||
// Escala redueix a 0 (simula Z → infinit)
|
||||
nau.escala_actual = nau.escala_objectiu * (1.0F - eased_progress);
|
||||
ship.current_scale = ship.target_scale * (1.0F - eased_progress);
|
||||
|
||||
// Marcar invisible quan l'animació completi
|
||||
if (progress >= 1.0F) {
|
||||
nau.visible = false;
|
||||
ship.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Configuració
|
||||
void ShipAnimator::configurar_nau_p1(NauTitol& nau) {
|
||||
void ShipAnimator::configurar_nau_p1(TitleShip& ship) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Estat inicial: FLOATING (per test estàtic)
|
||||
nau.estat = EstatNau::FLOATING;
|
||||
nau.temps_estat = 0.0F;
|
||||
ship.state = ShipState::FLOATING;
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Posicions (clock 8, bottom-left)
|
||||
nau.posicio_objectiu = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()};
|
||||
ship.target_position = {.x = P1_TARGET_X(), .y = P1_TARGET_Y()};
|
||||
|
||||
// Calcular posició inicial (fora de pantalla)
|
||||
nau.posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
nau.posicio_actual = nau.posicio_inicial; // Començar fora de pantalla
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_8_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fora de pantalla
|
||||
|
||||
// Escales
|
||||
nau.escala_objectiu = FLOATING_SCALE;
|
||||
nau.escala_actual = FLOATING_SCALE;
|
||||
nau.escala_inicial = ENTRY_SCALE_START;
|
||||
ship.target_scale = FLOATING_SCALE;
|
||||
ship.current_scale = FLOATING_SCALE;
|
||||
ship.initial_scale = ENTRY_SCALE_START;
|
||||
|
||||
// Flotació
|
||||
nau.fase_oscilacio = 0.0F;
|
||||
ship.oscillation_phase = 0.0F;
|
||||
|
||||
// Paràmetres d'entrada
|
||||
nau.entry_delay = P1_ENTRY_DELAY;
|
||||
ship.entry_delay = P1_ENTRY_DELAY;
|
||||
|
||||
// Paràmetres d'oscil·lació específics P1
|
||||
nau.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
nau.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
nau.frequency_x = FLOAT_FREQUENCY_X_BASE * P1_FREQUENCY_MULTIPLIER;
|
||||
nau.frequency_y = FLOAT_FREQUENCY_Y_BASE * P1_FREQUENCY_MULTIPLIER;
|
||||
ship.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
ship.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P1_FREQUENCY_MULTIPLIER;
|
||||
ship.frequency_y = FLOAT_FREQUENCY_Y_BASE * P1_FREQUENCY_MULTIPLIER;
|
||||
|
||||
// Visibilitat
|
||||
nau.visible = true;
|
||||
ship.visible = true;
|
||||
}
|
||||
|
||||
void ShipAnimator::configurar_nau_p2(NauTitol& nau) {
|
||||
void ShipAnimator::configurar_nau_p2(TitleShip& ship) {
|
||||
using namespace Defaults::Title::Ships;
|
||||
|
||||
// Estat inicial: FLOATING (per test estàtic)
|
||||
nau.estat = EstatNau::FLOATING;
|
||||
nau.temps_estat = 0.0F;
|
||||
ship.state = ShipState::FLOATING;
|
||||
ship.state_time = 0.0F;
|
||||
|
||||
// Posicions (clock 4, bottom-right)
|
||||
nau.posicio_objectiu = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()};
|
||||
ship.target_position = {.x = P2_TARGET_X(), .y = P2_TARGET_Y()};
|
||||
|
||||
// Calcular posició inicial (fora de pantalla)
|
||||
nau.posicio_inicial = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
nau.posicio_actual = nau.posicio_inicial; // Començar fora de pantalla
|
||||
ship.initial_position = calcular_posicio_fora_pantalla(CLOCK_4_ANGLE);
|
||||
ship.current_position = ship.initial_position; // Començar fora de pantalla
|
||||
|
||||
// Escales
|
||||
nau.escala_objectiu = FLOATING_SCALE;
|
||||
nau.escala_actual = FLOATING_SCALE;
|
||||
nau.escala_inicial = ENTRY_SCALE_START;
|
||||
ship.target_scale = FLOATING_SCALE;
|
||||
ship.current_scale = FLOATING_SCALE;
|
||||
ship.initial_scale = ENTRY_SCALE_START;
|
||||
|
||||
// Flotació
|
||||
nau.fase_oscilacio = 0.0F;
|
||||
ship.oscillation_phase = 0.0F;
|
||||
|
||||
// Paràmetres d'entrada
|
||||
nau.entry_delay = P2_ENTRY_DELAY;
|
||||
ship.entry_delay = P2_ENTRY_DELAY;
|
||||
|
||||
// Paràmetres d'oscil·lació específics P2
|
||||
nau.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
nau.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
nau.frequency_x = FLOAT_FREQUENCY_X_BASE * P2_FREQUENCY_MULTIPLIER;
|
||||
nau.frequency_y = FLOAT_FREQUENCY_Y_BASE * P2_FREQUENCY_MULTIPLIER;
|
||||
ship.amplitude_x = FLOAT_AMPLITUDE_X;
|
||||
ship.amplitude_y = FLOAT_AMPLITUDE_Y;
|
||||
ship.frequency_x = FLOAT_FREQUENCY_X_BASE * P2_FREQUENCY_MULTIPLIER;
|
||||
ship.frequency_y = FLOAT_FREQUENCY_Y_BASE * P2_FREQUENCY_MULTIPLIER;
|
||||
|
||||
// Visibilitat
|
||||
nau.visible = true;
|
||||
ship.visible = true;
|
||||
}
|
||||
|
||||
Vec2 ShipAnimator::calcular_posicio_fora_pantalla(float angle_rellotge) const {
|
||||
|
||||
@@ -13,46 +13,46 @@
|
||||
|
||||
namespace Title {
|
||||
|
||||
// Estats de l'animació de la nau
|
||||
enum class EstatNau {
|
||||
// Estats de l'animació de la ship
|
||||
enum class ShipState {
|
||||
ENTERING, // Entrant des de fora de pantalla
|
||||
FLOATING, // Flotant en posició estàtica
|
||||
EXITING // Volant cap al punt de fuga
|
||||
EXITING // Volant cap al point de fuga
|
||||
};
|
||||
|
||||
// Dades d'una nau individual al títol
|
||||
struct NauTitol {
|
||||
// Dades d'una ship individual al títol
|
||||
struct TitleShip {
|
||||
// Identificació
|
||||
int jugador_id; // 1 o 2
|
||||
int player_id; // 1 o 2
|
||||
|
||||
// Estat
|
||||
EstatNau estat;
|
||||
float temps_estat; // Temps acumulat en l'estat actual
|
||||
ShipState state;
|
||||
float state_time; // Temps acumulat en l'state 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
|
||||
Vec2 initial_position; // Posició d'inici (fora de pantalla per ENTERING)
|
||||
Vec2 target_position; // Posició objectiu (rellotge 8 o 4)
|
||||
Vec2 current_position; // 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
|
||||
float initial_scale; // Escala d'inici (més gran = més a prop)
|
||||
float target_scale; // Escala objectiu (mida flotació)
|
||||
float current_scale; // Escala interpolada actual
|
||||
|
||||
// Flotació
|
||||
float fase_oscilacio; // Acumulador de fase per moviment sinusoïdal
|
||||
float oscillation_phase; // 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
|
||||
// Paràmetres d'oscil·lació per ship
|
||||
float amplitude_x;
|
||||
float amplitude_y;
|
||||
float frequency_x;
|
||||
float frequency_y;
|
||||
|
||||
// Forma
|
||||
std::shared_ptr<Graphics::Shape> forma;
|
||||
std::shared_ptr<Graphics::Shape> shape;
|
||||
|
||||
// Visibilitat
|
||||
bool visible;
|
||||
@@ -68,29 +68,29 @@ class ShipAnimator {
|
||||
void update(float delta_time);
|
||||
void draw() const;
|
||||
|
||||
// Control d'estat (cridat per TitleScene)
|
||||
// Control d'state (cridat per TitleScene)
|
||||
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 trigger_exit_animation_for_player(int player_id); // Anima només una ship (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
|
||||
[[nodiscard]] bool is_visible() const; // Comprova si alguna ship és visible
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
std::array<NauTitol, 2> naus_; // Naus P1 i P2
|
||||
std::array<TitleShip, 2> ships_; // 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);
|
||||
void actualitzar_entering(TitleShip& ship, float delta_time);
|
||||
void actualitzar_floating(TitleShip& ship, float delta_time);
|
||||
void actualitzar_exiting(TitleShip& ship, float delta_time);
|
||||
|
||||
// Configuració
|
||||
void configurar_nau_p1(NauTitol& nau);
|
||||
void configurar_nau_p2(NauTitol& nau);
|
||||
void configurar_nau_p1(TitleShip& ship);
|
||||
void configurar_nau_p2(TitleShip& ship);
|
||||
[[nodiscard]] Vec2 calcular_posicio_fora_pantalla(float angle_rellotge) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user