Fase 1d: rename del codi restant (effects, stage_system, locals)
Sweep final del naming a CamelCase/camelBack/lower_case:
Fitxers renombrats:
- effects/gestor_puntuacio_flotant.{hpp,cpp} -> floating_score_manager.{hpp,cpp}
- effects/puntuacio_flotant.hpp -> floating_score.hpp
Tipus (CamelCase):
- GestorPuntuacioFlotant -> FloatingScoreManager
- PuntuacioFlotant -> FloatingScore
- ConfigStage -> StageConfig
- ConfigSistemaStages -> StageSystemConfig
- NauTitol -> TitleShip
- EstatNau -> ShipState
Metodes publics (camelBack):
- obte_renderer -> getRenderer
- get_num_actius -> getActiveCount
- calcular_direccio_explosio -> computeExplosionDirection
- trobar_slot_lliure -> findFreeSlot
- explotar -> explode
- reiniciar -> reset
- es_valida -> isValid
- parsejar_fitxer -> parseFile
- carregar -> load
- crear_explosio -> createExplosion
- registrar_puntuacio -> registerScore
- construir_marcador -> buildScoreboard
- render_centered -> renderCentered
Camps struct publics (snake_case):
- actiu/actius -> active
- rotacio -> rotation, rotacio_visual -> visual_rotation
- acceleracio -> acceleration
- velocitat -> velocity
- escala/escala_inicial/objectiu/actual -> scale/initial_scale/...
- posicio/posicio_inicial/objectiu/actual -> position/initial_position/...
- fase_oscilacio -> oscillation_phase
- temps_estat -> state_time
- jugador_id -> player_id
- estat -> state
- brillantor -> brightness
- tipus -> type
Camps privats (sufix _):
- naus_ -> ships_, orni_ -> enemies_, bales_ -> bullets_
- gestor_puntuacio_ -> floating_score_manager_
- punt_mort_ -> death_position_, punt_spawn_ -> spawn_position_
- itocado_per_jugador_ -> hit_timer_per_player_
- vides_per_jugador_ -> lives_per_player_
- puntuacio_per_jugador_ -> score_per_player_
- estat_game_over_ -> game_over_state_
- continues_usados_ -> continues_used_
Constants:
- MARGE_ESQ/DRET/DALT/BAIX -> MARGIN_LEFT/RIGHT/TOP/BOTTOM
Variables locals i parametres comuns (snake_case):
- nau -> ship, enemic -> enemy, bala -> bullet
- forma -> shape, punt(s) -> point(s)
- jugador -> player, partida -> match
- temps -> time, missatge -> message
Diff: 59 fitxers, +1000/-1000 (simetric). Compila i enllaça.
Pendents per a futures fases (no bloquejants):
- Comentaris de capçalera en catala -> castella
- Variables locals/parametres minoritaris en catala
- Include guards (queden alguns #ifndef en lloc de #pragma once)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ JA_Sound_t* AudioCache::getSound(const std::string& name) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ JA_Music_t* AudioCache::getMusic(const std::string& name) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut carregar " << normalized << std::endl;
|
||||
std::cerr << "[AudioCache] Error: no s'ha pogut load " << normalized << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -107,7 +107,7 @@ constexpr float ENEMY_RADIUS = 20.0F;
|
||||
constexpr float BULLET_RADIUS = 3.0F;
|
||||
} // namespace Entities
|
||||
|
||||
// Ship (nave del jugador)
|
||||
// Ship (nave del player)
|
||||
namespace Ship {
|
||||
// Invulnerabilidad post-respawn
|
||||
constexpr float INVULNERABILITY_DURATION = 3.0F; // Segundos de invulnerabilidad
|
||||
@@ -151,11 +151,11 @@ constexpr float INIT_HUD_RECT_RATIO_END = 0.85F;
|
||||
constexpr float INIT_HUD_SCORE_RATIO_INIT = 0.60F;
|
||||
constexpr float INIT_HUD_SCORE_RATIO_END = 0.90F;
|
||||
|
||||
// SHIP1 (nave jugador 1)
|
||||
// SHIP1 (nave player 1)
|
||||
constexpr float INIT_HUD_SHIP1_RATIO_INIT = 0.0F;
|
||||
constexpr float INIT_HUD_SHIP1_RATIO_END = 1.0F;
|
||||
|
||||
// SHIP2 (nave jugador 2)
|
||||
// SHIP2 (nave player 2)
|
||||
constexpr float INIT_HUD_SHIP2_RATIO_INIT = 0.20F;
|
||||
constexpr float INIT_HUD_SHIP2_RATIO_END = 1.0F;
|
||||
|
||||
@@ -220,7 +220,7 @@ constexpr float TEMPS_VIDA = 2.0F; // Duració màxima (segons) - enem
|
||||
constexpr float TEMPS_VIDA_NAU = 3.0F; // Ship debris lifetime (matches DEATH_DURATION)
|
||||
constexpr float SHRINK_RATE = 0.5F; // Reducció de mida (factor/s)
|
||||
|
||||
// Herència de velocitat angular (trayectorias curvas)
|
||||
// Herència de velocity angular (trayectorias curvas)
|
||||
constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat
|
||||
constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat
|
||||
constexpr float FRICCIO_ANGULAR = 0.5F; // Desacceleració angular (rad/s²)
|
||||
@@ -261,10 +261,10 @@ constexpr uint8_t BACKGROUND_MAX_G = 15;
|
||||
constexpr uint8_t BACKGROUND_MAX_B = 0;
|
||||
} // namespace Color
|
||||
|
||||
// Brillantor (control de intensitat per cada tipus d'entitat)
|
||||
// Brillantor (control de intensitat per cada type d'entitat)
|
||||
namespace Brightness {
|
||||
// Brillantor estàtica per entitats de joc (0.0-1.0)
|
||||
constexpr float NAU = 1.0F; // Màxima visibilitat (jugador)
|
||||
constexpr float NAU = 1.0F; // Màxima visibilitat (player)
|
||||
constexpr float ENEMIC = 0.7F; // 30% més tènue (destaca menys)
|
||||
constexpr float BALA = 1.0F; // Brillo a tope (màxima visibilitat)
|
||||
|
||||
@@ -306,7 +306,7 @@ constexpr const char* FRIENDLY_FIRE_HIT = "effects/friendly_fire.wav"; //
|
||||
constexpr const char* INIT_HUD = "effects/init_hud.wav"; // Para la animación del HUD
|
||||
constexpr const char* LASER = "effects/laser_shoot.wav"; // Disparo
|
||||
constexpr const char* LOGO = "effects/logo.wav"; // Logo
|
||||
constexpr const char* START = "effects/start.wav"; // El jugador pulsa START
|
||||
constexpr const char* START = "effects/start.wav"; // El player pulsa START
|
||||
constexpr const char* GOOD_JOB_COMMANDER = "voices/good_job_commander.wav"; // Voz: "Good job, commander"
|
||||
} // namespace Sound
|
||||
|
||||
@@ -327,7 +327,7 @@ constexpr SDL_Keycode SHOOT = SDLK_LSHIFT;
|
||||
} // namespace P2
|
||||
} // namespace Controls
|
||||
|
||||
// Enemy type configuration (tipus d'enemics)
|
||||
// Enemy type configuration (type d'enemics)
|
||||
namespace Enemies {
|
||||
// Pentagon (esquivador - zigzag evasion)
|
||||
namespace Pentagon {
|
||||
@@ -395,7 +395,7 @@ constexpr float INVULNERABILITY_SCALE_START = 0.0F; // Invisible
|
||||
constexpr float INVULNERABILITY_SCALE_END = 1.0F; // Full size
|
||||
} // namespace Spawn
|
||||
|
||||
// Scoring system (puntuació per tipus d'enemic)
|
||||
// Scoring system (puntuació per type d'enemy)
|
||||
namespace Scoring {
|
||||
constexpr int PENTAGON_SCORE = 100; // Pentàgon (esquivador, 35 px/s)
|
||||
constexpr int QUADRAT_SCORE = 150; // Quadrat (perseguidor, 40 px/s)
|
||||
@@ -426,7 +426,7 @@ constexpr float CLOCK_RADIUS = 150.0F; // Distància des del centre
|
||||
constexpr float CLOCK_8_ANGLE = 150.0F * Math::PI / 180.0F; // 8 o'clock (bottom-left)
|
||||
constexpr float CLOCK_4_ANGLE = 30.0F * Math::PI / 180.0F; // 4 o'clock (bottom-right)
|
||||
|
||||
// 5. Radio máximo de la forma de la nave (para calcular offset automáticamente)
|
||||
// 5. Radio máximo de la shape de la nave (para calcular offset automáticamente)
|
||||
constexpr float SHIP_MAX_RADIUS = 30.0F; // Radi del cercle circumscrit a ship_starfield.shp
|
||||
|
||||
// 6. Margen de seguridad para offset de entrada
|
||||
@@ -436,7 +436,7 @@ constexpr float ENTRY_OFFSET_MARGIN = 227.5F; // Para offset total de ~340px (a
|
||||
// VALORS DERIVATS (calculats automàticament - NO modificar)
|
||||
// ============================================================
|
||||
|
||||
// Centre de la pantalla (punt de referència)
|
||||
// Centre de la pantalla (point de referència)
|
||||
constexpr float CENTER_X = Game::WIDTH / 2.0F; // 320.0f
|
||||
constexpr float CENTER_Y = Game::HEIGHT / 2.0F; // 240.0f
|
||||
|
||||
@@ -458,10 +458,10 @@ inline float P2_TARGET_Y() {
|
||||
|
||||
// Escales d'animació (relatives a SHIP_BASE_SCALE)
|
||||
constexpr float ENTRY_SCALE_START = 1.5F * SHIP_BASE_SCALE; // Entrada: 50% més gran
|
||||
constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: escala base
|
||||
constexpr float FLOATING_SCALE = 1.0F * SHIP_BASE_SCALE; // Flotant: scale base
|
||||
|
||||
// Offset d'entrada (ajustat automàticament a l'escala)
|
||||
// Fórmula: (radi màxim de la nau * escala d'entrada) + marge
|
||||
// Offset d'entrada (ajustat automàticament a l'scale)
|
||||
// Fórmula: (radi màxim de la ship * scale d'entrada) + marge
|
||||
constexpr float ENTRY_OFFSET = (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN;
|
||||
|
||||
// Vec2 de fuga (centre per a l'animació de sortida)
|
||||
@@ -476,7 +476,7 @@ constexpr float VANISHING_POINT_Y = CENTER_Y; // 240.0f
|
||||
constexpr float ENTRY_DURATION = 2.0F; // Entrada (segons)
|
||||
constexpr float EXIT_DURATION = 1.0F; // Sortida (segons)
|
||||
|
||||
// Flotació (oscil·lació reduïda i diferenciada per nau)
|
||||
// Flotació (oscil·lació reduïda i diferenciada per ship)
|
||||
constexpr float FLOAT_AMPLITUDE_X = 4.0F; // Amplitud X (píxels)
|
||||
constexpr float FLOAT_AMPLITUDE_Y = 2.5F; // Amplitud Y (píxels)
|
||||
|
||||
@@ -489,10 +489,10 @@ constexpr float FLOAT_PHASE_OFFSET = 1.57F; // π/2 (90°)
|
||||
constexpr float P1_ENTRY_DELAY = 0.0F; // P1 entra immediatament
|
||||
constexpr float P2_ENTRY_DELAY = 0.5F; // P2 entra 0.5s després
|
||||
|
||||
// Delay global abans d'iniciar l'animació d'entrada al estat MAIN
|
||||
// Delay global abans d'iniciar l'animació d'entrada al state MAIN
|
||||
constexpr float ENTRANCE_DELAY = 5.0F; // Temps d'espera abans que les naus entrin
|
||||
|
||||
// Multiplicadors de freqüència per a cada nau (variació sutil ±12%)
|
||||
// Multiplicadors de freqüència per a cada ship (variació sutil ±12%)
|
||||
constexpr float P1_FREQUENCY_MULTIPLIER = 0.88F; // 12% més lenta
|
||||
constexpr float P2_FREQUENCY_MULTIPLIER = 1.12F; // 12% més ràpida
|
||||
|
||||
@@ -508,7 +508,7 @@ constexpr float COPYRIGHT1_POS = 0.90F; // Primera línia copyright
|
||||
constexpr float LOGO_LINE_SPACING = 0.02F; // Entre "ORNI" i "ATTACK!" (10px)
|
||||
constexpr float COPYRIGHT_LINE_SPACING = 0.0F; // Entre línies copyright (5px)
|
||||
|
||||
// Factors d'escala
|
||||
// Factors d'scale
|
||||
constexpr float LOGO_SCALE = 0.6F; // Escala "ORNI ATTACK!"
|
||||
constexpr float PRESS_START_SCALE = 1.0F; // Escala "PRESS START TO PLAY"
|
||||
constexpr float COPYRIGHT_SCALE = 0.5F; // Escala copyright
|
||||
|
||||
@@ -14,10 +14,10 @@ Shape::Shape(const std::string& filepath)
|
||||
: center_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
nom_("unnamed") {
|
||||
carregar(filepath);
|
||||
load(filepath);
|
||||
}
|
||||
|
||||
bool Shape::carregar(const std::string& filepath) {
|
||||
bool Shape::load(const std::string& filepath) {
|
||||
// Llegir fitxer
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
@@ -32,10 +32,10 @@ bool Shape::carregar(const std::string& filepath) {
|
||||
file.close();
|
||||
|
||||
// Parsejar
|
||||
return parsejar_fitxer(contingut);
|
||||
return parseFile(contingut);
|
||||
}
|
||||
|
||||
bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
bool Shape::parseFile(const std::string& contingut) {
|
||||
std::istringstream iss(contingut);
|
||||
std::string line;
|
||||
|
||||
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
try {
|
||||
escala_defecte_ = std::stof(extract_value(line));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n';
|
||||
std::cerr << "[Shape] Warning: scale invàlida, usant 1.0" << '\n';
|
||||
escala_defecte_ = 1.0F;
|
||||
}
|
||||
} else if (starts_with(line, "center:")) {
|
||||
@@ -65,7 +65,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() >= 2) {
|
||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 points ignorada"
|
||||
<< '\n';
|
||||
}
|
||||
} else if (starts_with(line, "line:")) {
|
||||
@@ -73,7 +73,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() == 2) {
|
||||
primitives_.push_back({PrimitiveType::LINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 points"
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
float y = std::stof(pair.substr(comma + 1));
|
||||
points.push_back({x, y});
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
||||
std::cerr << "[Shape] Warning: point invàlid ignorat: " << pair
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,30 @@
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
// Tipus de primitiva dins d'una forma
|
||||
// Tipus de primitiva dins d'una shape
|
||||
enum class PrimitiveType {
|
||||
POLYLINE, // Seqüència de punts connectats
|
||||
LINE // Línia individual (2 punts)
|
||||
POLYLINE, // Seqüència de points connectats
|
||||
LINE // Línia individual (2 points)
|
||||
};
|
||||
|
||||
// Primitiva individual (polyline o line)
|
||||
struct ShapePrimitive {
|
||||
PrimitiveType type;
|
||||
std::vector<Vec2> points; // 2+ punts per polyline, exactament 2 per line
|
||||
std::vector<Vec2> points; // 2+ points per polyline, exactament 2 per line
|
||||
};
|
||||
|
||||
// Classe Shape - representa una forma vectorial carregada des de .shp
|
||||
// Classe Shape - representa una shape vectorial carregada des de .shp
|
||||
class Shape {
|
||||
public:
|
||||
// Constructors
|
||||
Shape() = default;
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar forma des de fitxer .shp
|
||||
bool carregar(const std::string& filepath);
|
||||
// Carregar shape des de fitxer .shp
|
||||
bool load(const std::string& filepath);
|
||||
|
||||
// Parsejar forma des de buffer de memòria (per al sistema de recursos)
|
||||
bool parsejar_fitxer(const std::string& contingut);
|
||||
// Parsejar shape des de buffer de memòria (per al sistema de recursos)
|
||||
bool parseFile(const std::string& contingut);
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
@@ -41,7 +41,7 @@ class Shape {
|
||||
}
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool es_valida() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
@@ -49,9 +49,9 @@ class Shape {
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Vec2 center_; // Centre/origen de la forma
|
||||
Vec2 center_; // Centre/origen de la shape
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
[[nodiscard]] std::string trim(const std::string& str) const;
|
||||
|
||||
@@ -32,7 +32,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut load " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
@@ -40,15 +40,15 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Convert bytes to string and parse
|
||||
std::string file_content(data.begin(), data.end());
|
||||
auto shape = std::make_shared<Shape>();
|
||||
if (!shape->parsejar_fitxer(file_content)) {
|
||||
if (!shape->parseFile(file_content)) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Verify shape is valid
|
||||
if (!shape->es_valida()) {
|
||||
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n';
|
||||
if (!shape->isValid()) {
|
||||
std::cerr << "[ShapeLoader] Error: shape invàlida " << normalized << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class ShapeLoader {
|
||||
// No instanciable (tot estàtic)
|
||||
ShapeLoader() = delete;
|
||||
|
||||
// Carregar forma des de fitxer (amb caché)
|
||||
// Carregar shape des de fitxer (amb caché)
|
||||
// Retorna punter compartit (nullptr si error)
|
||||
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
||||
static std::shared_ptr<Shape> load(const std::string& filename);
|
||||
|
||||
@@ -22,11 +22,11 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
punt_fuga_(punt_fuga),
|
||||
area_(area),
|
||||
densitat_(densitat) {
|
||||
// Carregar forma d'estrella amb ShapeLoader
|
||||
// Carregar shape d'estrella amb ShapeLoader
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
|
||||
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n';
|
||||
if (!shape_estrella_ || !shape_estrella_->isValid()) {
|
||||
std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Calcular posició des de la distància
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
|
||||
estrelles_.push_back(estrella);
|
||||
}
|
||||
@@ -70,27 +70,27 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Inicialitzar una estrella (nova o regenerada)
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
// Angle aleatori des del punt de fuga cap a fora
|
||||
// Angle aleatori des del point de fuga cap a fora
|
||||
estrella.angle = (static_cast<float>(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI;
|
||||
|
||||
// Distància inicial petita (5% del radi màxim) - neix prop del centre
|
||||
estrella.distancia_centre = 0.05F;
|
||||
|
||||
// Posició inicial: molt prop del punt de fuga
|
||||
// Posició inicial: molt prop del point de fuga
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
}
|
||||
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
return (estrella.posicio.x < area_.x ||
|
||||
estrella.posicio.x > area_.x + area_.w ||
|
||||
estrella.posicio.y < area_.y ||
|
||||
estrella.posicio.y > area_.y + area_.h);
|
||||
return (estrella.position.x < area_.x ||
|
||||
estrella.position.x > area_.x + area_.w ||
|
||||
estrella.position.y < area_.y ||
|
||||
estrella.position.y > area_.y + area_.h);
|
||||
}
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
@@ -119,16 +119,16 @@ void Starfield::update(float delta_time) {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
// Moure cap a fora des del centre
|
||||
float velocitat = capa.velocitat_base;
|
||||
float dx = velocitat * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocitat * std::sin(estrella.angle) * delta_time;
|
||||
float velocity = capa.velocitat_base;
|
||||
float dx = velocity * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocity * std::sin(estrella.angle) * delta_time;
|
||||
|
||||
estrella.posicio.x += dx;
|
||||
estrella.posicio.y += dy;
|
||||
estrella.position.x += dx;
|
||||
estrella.position.y += dy;
|
||||
|
||||
// Actualitzar distància del centre
|
||||
float dx_centre = estrella.posicio.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.posicio.y - punt_fuga_.y;
|
||||
float dx_centre = estrella.position.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.position.y - punt_fuga_.y;
|
||||
float dist_px = std::sqrt((dx_centre * dx_centre) + (dy_centre * dy_centre));
|
||||
estrella.distancia_centre = dist_px / radi_max_;
|
||||
|
||||
@@ -146,22 +146,22 @@ void Starfield::set_brightness(float multiplier) {
|
||||
|
||||
// Dibuixar totes les estrelles
|
||||
void Starfield::draw() {
|
||||
if (!shape_estrella_->es_valida()) {
|
||||
if (!shape_estrella_->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& estrella : estrelles_) {
|
||||
// Calcular escala i brightness dinàmicament
|
||||
float escala = calcular_escala(estrella);
|
||||
// Calcular scale i brightness dinàmicament
|
||||
float scale = calcular_escala(estrella);
|
||||
float brightness = calcular_brightness(estrella);
|
||||
|
||||
// Renderitzar estrella sense rotació
|
||||
Rendering::render_shape(
|
||||
renderer_,
|
||||
shape_estrella_,
|
||||
estrella.posicio,
|
||||
estrella.position,
|
||||
0.0F, // angle (les estrelles no giren)
|
||||
escala, // escala dinàmica
|
||||
scale, // scale dinàmica
|
||||
1.0F, // progress (sempre visible)
|
||||
brightness // brightness dinàmica
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ class Starfield {
|
||||
public:
|
||||
// Constructor
|
||||
// - renderer: SDL renderer
|
||||
// - punt_fuga: punt d'origen/fuga des d'on surten les estrelles
|
||||
// - punt_fuga: point d'origen/fuga des d'on surten les estrelles
|
||||
// - area: rectangle on actuen les estrelles (SDL_FRect)
|
||||
// - densitat: nombre total d'estrelles (es divideix entre capes)
|
||||
Starfield(SDL_Renderer* renderer,
|
||||
@@ -40,14 +40,14 @@ class Starfield {
|
||||
// Dibuixar totes les estrelles
|
||||
void draw();
|
||||
|
||||
// Setters per ajustar paràmetres en temps real
|
||||
void set_punt_fuga(const Vec2& punt) { punt_fuga_ = punt; }
|
||||
// Setters per ajustar paràmetres en time real
|
||||
void set_punt_fuga(const Vec2& point) { punt_fuga_ = point; }
|
||||
void set_brightness(float multiplier);
|
||||
|
||||
private:
|
||||
// Estructura interna per cada estrella
|
||||
struct Estrella {
|
||||
Vec2 posicio; // Posició actual
|
||||
Vec2 position; // Posició actual
|
||||
float angle; // Angle de moviment (radians)
|
||||
float distancia_centre; // Distància normalitzada del centre (0.0-1.0)
|
||||
int capa; // Índex de capa (0=lluny, 1=mitjà, 2=prop)
|
||||
@@ -59,7 +59,7 @@ class Starfield {
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
|
||||
// Calcular brightness dinàmica segons distància del centre
|
||||
@@ -76,7 +76,7 @@ class Starfield {
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brillantor (1.0 = default)
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brightness (1.0 = default)
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -26,10 +26,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -54,10 +54,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
case '?':
|
||||
return "font/char_question.shp";
|
||||
case ' ':
|
||||
return ""; // Espai es maneja sense carregar shape
|
||||
return ""; // Espai es maneja sense load shape
|
||||
|
||||
case '\xA9': // Copyright symbol (©) - UTF-8 U+00A9
|
||||
return "font/char_copyright.shp";
|
||||
@@ -182,23 +182,23 @@ bool VectorText::is_supported(char c) const {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
void VectorText::render(const std::string& text, const Vec2& posicio, float escala, float spacing, float brightness) const {
|
||||
void VectorText::render(const std::string& text, const Vec2& position, float scale, float spacing, float brightness) const {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ancho de un carácter base (20 px a escala 1.0)
|
||||
const float char_width_scaled = char_width * escala;
|
||||
// Ancho de un carácter base (20 px a scale 1.0)
|
||||
const float char_width_scaled = char_width * scale;
|
||||
|
||||
// Spacing escalado
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Altura de un carácter escalado (necesario para ajustar Y)
|
||||
const float char_height_scaled = char_height * escala;
|
||||
const float char_height_scaled = char_height * scale;
|
||||
|
||||
// Posición X del borde izquierdo del carácter actual
|
||||
// (se ajustará +char_width/2 para obtener el centro al renderizar)
|
||||
float current_x = posicio.x;
|
||||
float current_x = position.x;
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
@@ -221,10 +221,10 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
auto it = chars_.find(c);
|
||||
if (it != chars_.end()) {
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// Ajustar X e Y para que position represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
@@ -237,28 +237,28 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::render_centered(const std::string& text, const Vec2& centre_punt, float escala, float spacing, float brightness) const {
|
||||
void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt, float scale, float spacing, float brightness) const {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, escala, spacing);
|
||||
float text_height = get_text_height(escala);
|
||||
float text_width = get_text_width(text, scale, spacing);
|
||||
float text_height = get_text_height(scale);
|
||||
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
// restant la meitat de les dimensions del point central
|
||||
Vec2 posicio_esquerra = {
|
||||
.x = centre_punt.x - (text_width / 2.0F),
|
||||
.y = centre_punt.y - (text_height / 2.0F)};
|
||||
|
||||
// Delegar al mètode render() existent
|
||||
render(text, posicio_esquerra, escala, spacing, brightness);
|
||||
render(text, posicio_esquerra, scale, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float escala, float spacing) const {
|
||||
float VectorText::get_text_width(const std::string& text, float scale, float spacing) const {
|
||||
if (text.empty()) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
const float char_width_scaled = char_width * escala;
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float char_width_scaled = char_width * scale;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
@@ -279,8 +279,8 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
|
||||
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float escala) const {
|
||||
return char_height * escala;
|
||||
float VectorText::get_text_height(float scale) const {
|
||||
return char_height * scale;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -21,25 +21,25 @@ class VectorText {
|
||||
// Renderizar string completo
|
||||
// - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':',
|
||||
// '!', '?', ' ')
|
||||
// - posicio: posición inicial (esquina superior izquierda)
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render(const std::string& text, const Vec2& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - position: posición inicial (esquina superior izquierda)
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render(const std::string& text, const Vec2& position, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Renderizar string centrado en un punto
|
||||
// - text: cadena a renderizar
|
||||
// - centre_punt: punto central del texto (no esquina superior izquierda)
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render_centered(const std::string& text, const Vec2& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
[[nodiscard]] float get_text_height(float escala = 1.0F) const;
|
||||
[[nodiscard]] float get_text_height(float scale = 1.0F) const;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
|
||||
@@ -30,7 +30,7 @@ Input::Input(std::string game_controller_db_path)
|
||||
// Inicializar bindings del teclado (valores por defecto)
|
||||
// Estos serán sobrescritos por applyPlayer1BindingsFromOptions()
|
||||
keyboard_.bindings = {
|
||||
// Movimiento del jugador
|
||||
// Movimiento del player
|
||||
{Action::LEFT, KeyState{.scancode = SDL_SCANCODE_LEFT}},
|
||||
{Action::RIGHT, KeyState{.scancode = SDL_SCANCODE_RIGHT}},
|
||||
{Action::THRUST, KeyState{.scancode = SDL_SCANCODE_UP}},
|
||||
@@ -188,7 +188,7 @@ auto Input::checkAnyButton(bool repeat) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Comprueba si algún jugador (P1 o P2) presionó alguna acción de una lista
|
||||
// Comprueba si algún player (P1 o P2) presionó alguna acción de una lista
|
||||
auto Input::checkAnyPlayerAction(const std::span<const InputAction>& actions, bool repeat) -> bool {
|
||||
for (const auto& action : actions) {
|
||||
if (checkActionPlayer1(action, repeat) || checkActionPlayer2(action, repeat)) {
|
||||
@@ -388,14 +388,14 @@ void Input::update() {
|
||||
binding.second.is_held = key_is_down_now;
|
||||
}
|
||||
|
||||
// Actualizar bindings de jugador 1
|
||||
// Actualizar bindings de player 1
|
||||
for (auto& binding : player1_keyboard_bindings_) {
|
||||
bool key_is_down_now = key_states[binding.second.scancode];
|
||||
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
||||
binding.second.is_held = key_is_down_now;
|
||||
}
|
||||
|
||||
// Actualizar bindings de jugador 2
|
||||
// Actualizar bindings de player 2
|
||||
for (auto& binding : player2_keyboard_bindings_) {
|
||||
bool key_is_down_now = key_states[binding.second.scancode];
|
||||
binding.second.just_pressed = key_is_down_now && !binding.second.is_held;
|
||||
@@ -493,7 +493,7 @@ auto Input::findAvailableGamepadByName(const std::string& gamepad_name) -> std::
|
||||
|
||||
// ========== MÉTODOS ESPECÍFICOS POR JUGADOR (ORNI) ==========
|
||||
|
||||
// Aplica configuración de controles del jugador 1
|
||||
// Aplica configuración de controles del player 1
|
||||
void Input::applyPlayer1BindingsFromOptions() {
|
||||
// 1. Aplicar bindings de teclado (NO usar bindKey, llenar mapa específico)
|
||||
player1_keyboard_bindings_[Action::LEFT].scancode = Options::player1.keyboard.key_left;
|
||||
@@ -527,7 +527,7 @@ void Input::applyPlayer1BindingsFromOptions() {
|
||||
player1_gamepad_ = gamepad;
|
||||
}
|
||||
|
||||
// Aplica configuración de controles del jugador 2
|
||||
// Aplica configuración de controles del player 2
|
||||
void Input::applyPlayer2BindingsFromOptions() {
|
||||
// 1. Aplicar bindings de teclado (mapa específico de P2, no sobrescribe P1)
|
||||
player2_keyboard_bindings_[Action::LEFT].scancode = Options::player2.keyboard.key_left;
|
||||
@@ -561,7 +561,7 @@ void Input::applyPlayer2BindingsFromOptions() {
|
||||
player2_gamepad_ = gamepad;
|
||||
}
|
||||
|
||||
// Consulta de input para jugador 1
|
||||
// Consulta de input para player 1
|
||||
auto Input::checkActionPlayer1(Action action, bool repeat) -> bool {
|
||||
// Comprobar teclado con el mapa específico de P1
|
||||
bool keyboard_active = false;
|
||||
@@ -583,7 +583,7 @@ auto Input::checkActionPlayer1(Action action, bool repeat) -> bool {
|
||||
return keyboard_active || gamepad_active;
|
||||
}
|
||||
|
||||
// Consulta de input para jugador 2
|
||||
// Consulta de input para player 2
|
||||
auto Input::checkActionPlayer2(Action action, bool repeat) -> bool {
|
||||
// Comprobar teclado con el mapa específico de P2
|
||||
bool keyboard_active = false;
|
||||
|
||||
@@ -58,7 +58,7 @@ class Input {
|
||||
name(std::string(SDL_GetGamepadName(gamepad))),
|
||||
path(std::string(SDL_GetGamepadPath(pad))),
|
||||
bindings{
|
||||
// Movimiento y acciones del jugador
|
||||
// Movimiento y acciones del player
|
||||
{Action::LEFT, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}},
|
||||
{Action::RIGHT, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}},
|
||||
{Action::THRUST, ButtonState{.button = static_cast<int>(SDL_GAMEPAD_BUTTON_WEST)}},
|
||||
@@ -92,7 +92,7 @@ class Input {
|
||||
void applyKeyboardBindingsFromOptions();
|
||||
void applyGamepadBindingsFromOptions();
|
||||
|
||||
// Configuración por jugador (Orni - dos jugadores)
|
||||
// Configuración por player (Orni - dos jugadores)
|
||||
void applyPlayer1BindingsFromOptions();
|
||||
void applyPlayer2BindingsFromOptions();
|
||||
|
||||
@@ -105,7 +105,7 @@ class Input {
|
||||
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool;
|
||||
void resetInputStates();
|
||||
|
||||
// Consulta por jugador (Orni - dos jugadores)
|
||||
// Consulta por player (Orni - dos jugadores)
|
||||
auto checkActionPlayer1(Action action, bool repeat = true) -> bool;
|
||||
auto checkActionPlayer2(Action action, bool repeat = true) -> bool;
|
||||
|
||||
@@ -152,11 +152,11 @@ class Input {
|
||||
Keyboard keyboard_{}; // Estado del teclado (solo acciones globales)
|
||||
std::string gamepad_mappings_file_; // Ruta al archivo de mappings
|
||||
|
||||
// Referencias cacheadas a gamepads por jugador (Orni)
|
||||
// Referencias cacheadas a gamepads por player (Orni)
|
||||
std::shared_ptr<Gamepad> player1_gamepad_;
|
||||
std::shared_ptr<Gamepad> player2_gamepad_;
|
||||
|
||||
// Mapas de bindings separados por jugador (Orni - dos jugadores)
|
||||
// Mapas de bindings separados por player (Orni - dos jugadores)
|
||||
std::unordered_map<Action, KeyState> player1_keyboard_bindings_;
|
||||
std::unordered_map<Action, KeyState> player2_keyboard_bindings_;
|
||||
};
|
||||
@@ -13,7 +13,7 @@ enum class InputAction : int { // Acciones de entrada posibles en el juego
|
||||
RIGHT, // Rotar derecha
|
||||
THRUST, // Acelerar
|
||||
SHOOT, // Disparar
|
||||
START, // Empezar partida
|
||||
START, // Empezar match
|
||||
|
||||
// Inputs de sistema (globales)
|
||||
WINDOW_INC_ZOOM, // F2
|
||||
|
||||
@@ -17,13 +17,13 @@ Uint32 initialization_time = 0;
|
||||
constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms
|
||||
|
||||
void forceHide() {
|
||||
// Forçar ocultació sincronitzant estat SDL i estat intern
|
||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
|
||||
// Forçar ocultació sincronitzant state SDL i state intern
|
||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant state. cursor_visible=" << cursor_visible
|
||||
<< " -> false" << '\n';
|
||||
SDL_HideCursor();
|
||||
cursor_visible = false;
|
||||
last_mouse_move_time = 0;
|
||||
initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials
|
||||
initialization_time = SDL_GetTicks(); // Marcar time per ignorar esdeveniments inicials
|
||||
std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << '\n';
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el c
|
||||
extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió
|
||||
extern bool cursor_visible; // Estado del cursor
|
||||
|
||||
void forceHide(); // Forçar ocultació del cursor (sincronitza estat intern)
|
||||
void forceHide(); // Forçar ocultació del cursor (sincronitza state intern)
|
||||
void handleEvent(const SDL_Event& event);
|
||||
void updateCursorVisibility();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Factor d'escala global (inicialitzat a 1.0 per defecte)
|
||||
// Factor d'scale global (inicialitzat a 1.0 per defecte)
|
||||
float g_current_scale_factor = 1.0F;
|
||||
|
||||
} // namespace Rendering
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Factor d'escala global (actualitzat cada frame per SDLManager)
|
||||
// Factor d'scale global (actualitzat cada frame per SDLManager)
|
||||
extern float g_current_scale_factor;
|
||||
|
||||
// Transforma coordenada lògica a física amb arrodoniment
|
||||
@@ -19,7 +19,7 @@ inline int transform_y(int logical_y, float scale) {
|
||||
return static_cast<int>(std::round(logical_y * scale));
|
||||
}
|
||||
|
||||
// Variant que usa el factor d'escala global
|
||||
// Variant que usa el factor d'scale global
|
||||
inline int transform_x(int logical_x) {
|
||||
return transform_x(logical_x, g_current_scale_factor);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Dibuixa una línia entre dos punts en coordenades lògiques (640x480).
|
||||
// brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor).
|
||||
// Dibuixa una línia entre dos points en coordenades lògiques (640x480).
|
||||
// brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness).
|
||||
void linea(SDL_Renderer* renderer, int x1, int y1, int x2, int y2, float brightness = 1.0F);
|
||||
|
||||
// Estableix el color global de les línies (utilitzat per ColorOscillator).
|
||||
|
||||
@@ -283,7 +283,7 @@ void SDLManager::updateViewport() {
|
||||
}
|
||||
|
||||
void SDLManager::updateRenderingContext() const {
|
||||
// Actualitzar el factor d'escala global per a totes les funcions de renderitzat
|
||||
// Actualitzar el factor d'scale global per a totes les funcions de renderitzat
|
||||
Rendering::g_current_scale_factor = zoom_factor_;
|
||||
}
|
||||
|
||||
@@ -430,7 +430,7 @@ void SDLManager::updateColors(float delta_time) {
|
||||
|
||||
// [NUEVO] Actualitzar comptador de FPS
|
||||
void SDLManager::updateFPS(float delta_time) {
|
||||
// Acumular temps i frames
|
||||
// Acumular time i frames
|
||||
fps_accumulator_ += delta_time;
|
||||
fps_frame_count_++;
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ class SDLManager {
|
||||
void updateFPS(float delta_time);
|
||||
|
||||
// Getters
|
||||
SDL_Renderer* obte_renderer() { return renderer_; }
|
||||
SDL_Renderer* getRenderer() { return renderer_; }
|
||||
[[nodiscard]] float getScaleFactor() const { return zoom_factor_; }
|
||||
|
||||
// [NUEVO] Actualitzar títol de la finestra
|
||||
void setWindowTitle(const std::string& title);
|
||||
|
||||
// [NUEVO] Actualitzar context de renderitzat (factor d'escala global)
|
||||
// [NUEVO] Actualitzar context de renderitzat (factor d'scale global)
|
||||
void updateRenderingContext() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Helper: aplicar rotació 3D a un punt 2D (assumeix Z=0)
|
||||
// Helper: aplicar rotació 3D a un point 2D (assumeix Z=0)
|
||||
static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
float z = 0.0F; // Tots els punts 2D comencen a Z=0
|
||||
float z = 0.0F; // Tots els points 2D comencen a Z=0
|
||||
|
||||
// Pitch (rotació eix X): cabeceo arriba/baix
|
||||
float cos_pitch = std::cos(rot.pitch);
|
||||
@@ -33,7 +33,7 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
float y3 = (x2 * sin_roll) + (y1 * cos_roll);
|
||||
|
||||
// Proyecció perspectiva (Z-divide simple)
|
||||
// Naus volen cap al punt de fuga (320, 240) a "infinit" (Z → +∞)
|
||||
// Naus volen cap al point de fuga (320, 240) a "infinit" (Z → +∞)
|
||||
// Z més gran = més lluny = més petit a pantalla
|
||||
constexpr float perspective_factor = 500.0F;
|
||||
float scale_factor = perspective_factor / (perspective_factor + z2);
|
||||
@@ -41,9 +41,9 @@ static Vec2 apply_3d_rotation(float x, float y, const Rotation3D& rot) {
|
||||
return {.x = x3 * scale_factor, .y = y3 * scale_factor};
|
||||
}
|
||||
|
||||
// Helper: transformar un punt amb rotació, escala i trasllació
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& posicio, float angle, float escala, const Rotation3D* rotation_3d) {
|
||||
// 1. Centrar el punt respecte al centre de la forma
|
||||
// Helper: transformar un point amb rotació, scale i trasllació
|
||||
static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const Vec2& position, float angle, float scale, const Rotation3D* rotation_3d) {
|
||||
// 1. Centrar el point respecte al centre de la shape
|
||||
float centered_x = point.x - shape_centre.x;
|
||||
float centered_y = point.y - shape_centre.y;
|
||||
|
||||
@@ -54,9 +54,9 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
centered_y = rotated_3d.y;
|
||||
}
|
||||
|
||||
// 3. Aplicar escala al punt (després de rotació 3D)
|
||||
float scaled_x = centered_x * escala;
|
||||
float scaled_y = centered_y * escala;
|
||||
// 3. Aplicar scale al point (després de rotació 3D)
|
||||
float scaled_x = centered_x * scale;
|
||||
float scaled_y = centered_y * scale;
|
||||
|
||||
// 4. Aplicar rotació 2D (Z-axis, tradicional)
|
||||
// IMPORTANT: En el sistema original, angle=0 apunta AMUNT (no dreta)
|
||||
@@ -69,19 +69,19 @@ static Vec2 transform_point(const Vec2& point, const Vec2& shape_centre, const V
|
||||
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
|
||||
|
||||
// 5. Aplicar trasllació a posició mundial
|
||||
return {.x = rotated_x + posicio.x, .y = rotated_y + posicio.y};
|
||||
return {.x = rotated_x + position.x, .y = rotated_y + position.y};
|
||||
}
|
||||
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& posicio,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
float escala,
|
||||
float scale,
|
||||
float progress,
|
||||
float brightness,
|
||||
const Rotation3D* rotation_3d) {
|
||||
// Verificar que la forma és vàlida
|
||||
if (!shape || !shape->es_valida()) {
|
||||
// Verificar que la shape és vàlida
|
||||
if (!shape || !shape->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,25 +90,25 @@ void render_shape(SDL_Renderer* renderer,
|
||||
return;
|
||||
}
|
||||
|
||||
// Obtenir el centre de la forma per a transformacions
|
||||
// Obtenir el centre de la shape per a transformacions
|
||||
const Vec2& shape_centre = shape->getCenter();
|
||||
|
||||
// Iterar sobre totes les primitives
|
||||
for (const auto& primitive : shape->get_primitives()) {
|
||||
if (primitive.type == Graphics::PrimitiveType::POLYLINE) {
|
||||
// POLYLINE: connectar punts consecutius
|
||||
// POLYLINE: connectar points consecutius
|
||||
for (size_t i = 0; i < primitive.points.size() - 1; i++) {
|
||||
Vec2 p1 = transform_point(primitive.points[i], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p1 = transform_point(primitive.points[i], shape_centre, position, angle, scale, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[i + 1], shape_centre, position, angle, scale, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
}
|
||||
} else { // PrimitiveType::LINE
|
||||
// LINE: exactament 2 punts
|
||||
// LINE: exactament 2 points
|
||||
if (primitive.points.size() >= 2) {
|
||||
Vec2 p1 = transform_point(primitive.points[0], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[1], shape_centre, posicio, angle, escala, rotation_3d);
|
||||
Vec2 p1 = transform_point(primitive.points[0], shape_centre, position, angle, scale, rotation_3d);
|
||||
Vec2 p2 = transform_point(primitive.points[1], shape_centre, position, angle, scale, rotation_3d);
|
||||
|
||||
linea(renderer, static_cast<int>(p1.x), static_cast<int>(p1.y),
|
||||
static_cast<int>(p2.x), static_cast<int>(p2.y), brightness);
|
||||
|
||||
@@ -32,19 +32,19 @@ struct Rotation3D {
|
||||
}
|
||||
};
|
||||
|
||||
// Renderitzar forma amb transformacions
|
||||
// Renderitzar shape amb transformacions
|
||||
// - renderer: SDL renderer
|
||||
// - shape: forma vectorial a draw
|
||||
// - posicio: posició del centre en coordenades mundials
|
||||
// - shape: shape vectorial a draw
|
||||
// - position: posició del centre en coordenades mundials
|
||||
// - angle: rotació en radians (0 = amunt, sentit horari)
|
||||
// - escala: factor d'escala (1.0 = mida original)
|
||||
// - scale: factor d'scale (1.0 = mida original)
|
||||
// - progress: progrés de l'animació (0.0-1.0, default 1.0 = tot visible)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render_shape(SDL_Renderer* renderer,
|
||||
const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& posicio,
|
||||
const Vec2& position,
|
||||
float angle,
|
||||
float escala = 1.0F,
|
||||
float scale = 1.0F,
|
||||
float progress = 1.0F,
|
||||
float brightness = 1.0F,
|
||||
const Rotation3D* rotation_3d = nullptr);
|
||||
|
||||
@@ -19,12 +19,12 @@ Loader& Loader::get() {
|
||||
bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
fallback_enabled_ = enable_fallback;
|
||||
|
||||
// Intentar carregar el paquet
|
||||
// Intentar load el paquet
|
||||
pack_ = std::make_unique<Pack>();
|
||||
|
||||
if (!pack_->loadPack(pack_file)) {
|
||||
if (!fallback_enabled_) {
|
||||
std::cerr << "[ResourceLoader] ERROR FATAL: No es pot carregar " << pack_file
|
||||
std::cerr << "[ResourceLoader] ERROR FATAL: No es pot load " << pack_file
|
||||
<< " i el fallback està desactivat\n";
|
||||
return false;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ bool Loader::initialize(const std::string& pack_file, bool enable_fallback) {
|
||||
|
||||
// Carregar un recurs
|
||||
std::vector<uint8_t> Loader::loadResource(const std::string& filename) {
|
||||
// Intentar carregar del paquet primer
|
||||
// Intentar load del paquet primer
|
||||
if (pack_) {
|
||||
if (pack_->hasResource(filename)) {
|
||||
auto data = pack_->getResource(filename);
|
||||
|
||||
@@ -35,7 +35,7 @@ class Pack {
|
||||
bool addFile(const std::string& filepath, const std::string& pack_name);
|
||||
bool addDirectory(const std::string& dir_path, const std::string& base_path = "");
|
||||
|
||||
// Guardar i carregar paquets
|
||||
// Guardar i load paquets
|
||||
bool savePack(const std::string& pack_file);
|
||||
bool loadPack(const std::string& pack_file);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Director::Director(std::vector<std::string> const& args) {
|
||||
// Mode release: paquet obligatori, sense fallback
|
||||
std::string pack_path = resource_base + "/resources.pack";
|
||||
if (!Resource::Helper::initializeResourceSystem(pack_path, false)) {
|
||||
std::cerr << "ERROR FATAL: No es pot carregar " << pack_path << "\n";
|
||||
std::cerr << "ERROR FATAL: No es pot load " << pack_path << "\n";
|
||||
std::cerr << "El joc no pot continuar sense els recursos.\n";
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
@@ -10,36 +10,36 @@ enum class Mode {
|
||||
DEMO // Mode demostració (futur)
|
||||
};
|
||||
|
||||
// Configuració d'una partida
|
||||
// Configuració d'una match
|
||||
struct MatchConfig {
|
||||
bool jugador1_actiu{false}; // És actiu el jugador 1?
|
||||
bool jugador2_actiu{false}; // És actiu el jugador 2?
|
||||
bool jugador1_actiu{false}; // És active el player 1?
|
||||
bool jugador2_actiu{false}; // És active el player 2?
|
||||
Mode mode{Mode::NORMAL}; // Mode de joc
|
||||
|
||||
// Mètodes auxiliars
|
||||
|
||||
// Retorna true si només hi ha un jugador actiu
|
||||
// Retorna true si només hi ha un player active
|
||||
[[nodiscard]] bool es_un_jugador() const {
|
||||
return (jugador1_actiu && !jugador2_actiu) ||
|
||||
(!jugador1_actiu && jugador2_actiu);
|
||||
}
|
||||
|
||||
// Retorna true si hi ha dos jugadors actius
|
||||
// Retorna true si hi ha dos jugadors active
|
||||
[[nodiscard]] bool son_dos_jugadors() const {
|
||||
return jugador1_actiu && jugador2_actiu;
|
||||
}
|
||||
|
||||
// Retorna true si no hi ha cap jugador actiu
|
||||
// Retorna true si no hi ha cap player active
|
||||
[[nodiscard]] bool cap_jugador() const {
|
||||
return !jugador1_actiu && !jugador2_actiu;
|
||||
}
|
||||
|
||||
// Compte de jugadors actius (0, 1 o 2)
|
||||
// Compte de jugadors active (0, 1 o 2)
|
||||
[[nodiscard]] uint8_t compte_jugadors() const {
|
||||
return (jugador1_actiu ? 1 : 0) + (jugador2_actiu ? 1 : 0);
|
||||
}
|
||||
|
||||
// Retorna l'ID de l'únic jugador actiu (0 o 1)
|
||||
// Retorna l'ID de l'únic player active (0 o 1)
|
||||
// Només vàlid si es_un_jugador() retorna true
|
||||
[[nodiscard]] uint8_t id_unic_jugador() const {
|
||||
if (jugador1_actiu && !jugador2_actiu) {
|
||||
|
||||
@@ -14,6 +14,6 @@ class SceneContext;
|
||||
|
||||
namespace GlobalEvents {
|
||||
// Processa events globals (F1/F2/F3/ESC/QUIT)
|
||||
// Retorna true si l'event ha estat processat i no cal seguir processant-lo
|
||||
// Retorna true si l'event ha state processat i no cal seguir processant-lo
|
||||
bool handle(const SDL_Event& event, SDLManager& sdl, SceneManager::SceneContext& context);
|
||||
} // namespace GlobalEvents
|
||||
|
||||
@@ -58,12 +58,12 @@ class SceneContext {
|
||||
option_ = Option::NONE;
|
||||
}
|
||||
|
||||
// Configurar partida abans de transicionar a GAME
|
||||
// Configurar match abans de transicionar a GAME
|
||||
void setMatchConfig(const GameConfig::MatchConfig& config) {
|
||||
match_config_ = config;
|
||||
}
|
||||
|
||||
// Obtenir configuració de partida (consumit per GameScene)
|
||||
// Obtenir configuració de match (consumit per GameScene)
|
||||
[[nodiscard]] const GameConfig::MatchConfig& getMatchConfig() const {
|
||||
return match_config_;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class SceneContext {
|
||||
private:
|
||||
SceneType next_scene_{SceneType::LOGO}; // SceneType a la qual transicionar
|
||||
Option option_{Option::NONE}; // Opció específica per l'escena
|
||||
GameConfig::MatchConfig match_config_; // Configuració de partida (jugadors actius, mode)
|
||||
GameConfig::MatchConfig match_config_; // Configuració de match (jugadors active, mode)
|
||||
};
|
||||
|
||||
// Variable global inline per gestionar l'escena actual (backward compatibility)
|
||||
|
||||
@@ -50,7 +50,7 @@ bool isMacOSBundle() {
|
||||
#ifdef MACOS_BUNDLE
|
||||
return true;
|
||||
#else
|
||||
// Detecció en temps d'execució
|
||||
// Detecció en time d'execució
|
||||
// Cercar ".app/Contents/MacOS" a la ruta de l'executable
|
||||
std::string exe_dir = getExecutableDirectory();
|
||||
return exe_dir.find(".app/Contents/MacOS") != std::string::npos;
|
||||
|
||||
Reference in New Issue
Block a user