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:
@@ -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