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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user