style: aplicar readability-math-missing-parentheses

- Agregar paréntesis explícitos en operaciones matemáticas para claridad
- Ejemplos: '1.0F - a * b' → '1.0F - (a * b)'
- 291 correcciones aplicadas automáticamente con clang-tidy
- Check 2/N completado

🤖 Generated with Claude Code
This commit is contained in:
2025-12-18 13:09:35 +01:00
parent bc94eff176
commit 76786203a0
20 changed files with 123 additions and 121 deletions

View File

@@ -75,10 +75,10 @@ constexpr SDL_FRect MAIN_PLAYAREA = {
// Ocupa: dins de MAIN_PLAYAREA, amb marges laterals
// S'utilitza per a límits del joc, col·lisions, spawn
constexpr SDL_FRect PLAYAREA = {
PLAYAREA_PADDING_H, // x = 32.0
MAIN_PLAYAREA_Y, // y = 48.0 (igual que MAIN_PLAYAREA)
Game::WIDTH - 2.0F * PLAYAREA_PADDING_H, // w = 576.0
MAIN_PLAYAREA_H // h = 384.0 (igual que MAIN_PLAYAREA)
PLAYAREA_PADDING_H, // x = 32.0
MAIN_PLAYAREA_Y, // y = 48.0 (igual que MAIN_PLAYAREA)
Game::WIDTH - (2.0F * PLAYAREA_PADDING_H), // w = 576.0
MAIN_PLAYAREA_H // h = 384.0 (igual que MAIN_PLAYAREA)
};
// Marcador inferior (marcador actual)
@@ -444,13 +444,13 @@ inline float P1_TARGET_X() {
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_8_ANGLE);
}
inline float P1_TARGET_Y() {
return CENTER_Y + (Game::HEIGHT / 2.0F) * TARGET_Y_RATIO;
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
}
inline float P2_TARGET_X() {
return CENTER_X + CLOCK_RADIUS * std::cos(CLOCK_4_ANGLE);
}
inline float P2_TARGET_Y() {
return CENTER_Y + (Game::HEIGHT / 2.0F) * TARGET_Y_RATIO;
return CENTER_Y + ((Game::HEIGHT / 2.0F) * TARGET_Y_RATIO);
}
// Escales d'animació (relatives a SHIP_BASE_SCALE)

View File

@@ -43,7 +43,7 @@ Starfield::Starfield(SDL_Renderer* renderer,
// Calcular radi màxim (distància del centre al racó més llunyà)
float dx = std::max(punt_fuga_.x, area_.w - punt_fuga_.x);
float dy = std::max(punt_fuga_.y, area_.h - punt_fuga_.y);
radi_max_ = std::sqrt(dx * dx + dy * dy);
radi_max_ = std::sqrt((dx * dx) + (dy * dy));
// Inicialitzar estrelles amb posicions distribuïdes (pre-omplir pantalla)
for (int capa_idx = 0; capa_idx < 3; capa_idx++) {
@@ -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.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
estrelles_.push_back(estrella);
}
@@ -78,8 +78,8 @@ void Starfield::inicialitzar_estrella(Estrella& estrella) {
// Posició inicial: molt prop del punt 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.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
}
// Verificar si una estrella està fora de l'àrea
@@ -97,7 +97,7 @@ float Starfield::calcular_escala(const Estrella& estrella) const {
// Interpolació lineal basada en distància del centre
// distancia_centre: 0.0 (centre) → 1.0 (vora)
return capa.escala_min +
(capa.escala_max - capa.escala_min) * estrella.distancia_centre;
((capa.escala_max - capa.escala_min) * estrella.distancia_centre);
}
// Calcular brightness dinàmica segons distància del centre
@@ -105,8 +105,8 @@ float Starfield::calcular_brightness(const Estrella& estrella) const {
// Interpolació lineal: estrelles properes (vora) més brillants
// distancia_centre: 0.0 (centre, llunyanes) → 1.0 (vora, properes)
float brightness_base = Defaults::Brightness::STARFIELD_MIN +
(Defaults::Brightness::STARFIELD_MAX - Defaults::Brightness::STARFIELD_MIN) *
estrella.distancia_centre;
((Defaults::Brightness::STARFIELD_MAX - Defaults::Brightness::STARFIELD_MIN) *
estrella.distancia_centre);
// Aplicar multiplicador i limitar a 1.0
return std::min(1.0F, brightness_base * multiplicador_brightness_);
@@ -129,7 +129,7 @@ void Starfield::actualitzar(float delta_time) {
// Actualitzar distància del centre
float dx_centre = estrella.posicio.x - punt_fuga_.x;
float dy_centre = estrella.posicio.y - punt_fuga_.y;
float dist_px = std::sqrt(dx_centre * dx_centre + dy_centre * dy_centre);
float dist_px = std::sqrt((dx_centre * dx_centre) + (dy_centre * dy_centre));
estrella.distancia_centre = dist_px / radi_max_;
// Si ha sortit de l'àrea, regenerar-la

View File

@@ -222,7 +222,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
// Renderizar carácter
// Ajustar X e Y para que posicio represente esquina superior izquierda
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
Punt char_pos = {current_x + char_width_scaled / 2.0F, posicio.y + char_height_scaled / 2.0F};
Punt char_pos = {current_x + (char_width_scaled / 2.0F), posicio.y + (char_height_scaled / 2.0F)};
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, true, 1.0F, brightness);
// Avanzar posición
@@ -275,7 +275,7 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
}
// Ancho total = todos los caracteres VISUALES + spacing entre ellos
return visual_chars * char_width_scaled + (visual_chars - 1) * spacing_scaled;
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
}
float VectorText::get_text_height(float escala) const {

View File

@@ -9,7 +9,7 @@ namespace Easing {
// t = progreso normalizado [0.0 - 1.0]
// retorna valor interpolado [0.0 - 1.0]
inline float ease_out_quad(float t) {
return 1.0F - (1.0F - t) * (1.0F - t);
return 1.0F - ((1.0F - t) * (1.0F - t));
}
// Ease-in quadratic: empieza lento, acelera
@@ -25,7 +25,7 @@ inline float ease_in_quad(float t) {
inline float ease_in_out_quad(float t) {
return (t < 0.5F)
? 2.0F * t * t
: 1.0F - (-2.0F * t + 2.0F) * (-2.0F * t + 2.0F) / 2.0F;
: 1.0F - ((-2.0F * t + 2.0F) * (-2.0F * t + 2.0F) / 2.0F);
}
// Ease-out cubic: desaceleración más suave que quadratic
@@ -33,12 +33,12 @@ inline float ease_in_out_quad(float t) {
// retorna valor interpolado [0.0 - 1.0]
inline float ease_out_cubic(float t) {
float t1 = 1.0F - t;
return 1.0F - t1 * t1 * t1;
return 1.0F - (t1 * t1 * t1);
}
// Interpolación lineal básica (para referencia)
inline float lerp(float start, float end, float t) {
return start + (end - start) * t;
return start + ((end - start) * t);
}
} // namespace Easing

View File

@@ -59,9 +59,9 @@ float ColorOscillator::calculateOscillationFactor(float time, float frequency) {
}
SDL_Color ColorOscillator::interpolateColor(SDL_Color min, SDL_Color max, float factor) {
return {static_cast<uint8_t>(min.r + (max.r - min.r) * factor),
static_cast<uint8_t>(min.g + (max.g - min.g) * factor),
static_cast<uint8_t>(min.b + (max.b - min.b) * factor),
return {static_cast<uint8_t>(min.r + ((max.r - min.r) * factor)),
static_cast<uint8_t>(min.g + ((max.g - min.g) * factor)),
static_cast<uint8_t>(min.b + ((max.b - min.b) * factor)),
255};
}

View File

@@ -14,7 +14,7 @@
float modul(const Punt& p) {
// Càlcul de la magnitud d'un vector: sqrt(x² + y²)
return std::sqrt(p.x * p.x + p.y * p.y);
return std::sqrt((p.x * p.x) + (p.y * p.y));
}
void diferencia(const Punt& o, const Punt& d, Punt& p) {

View File

@@ -17,20 +17,20 @@ static Punt apply_3d_rotation(float x, float y, const Rotation3D& rot) {
// Pitch (rotació eix X): cabeceo arriba/baix
float cos_pitch = std::cos(rot.pitch);
float sin_pitch = std::sin(rot.pitch);
float y1 = y * cos_pitch - z * sin_pitch;
float z1 = y * sin_pitch + z * cos_pitch;
float y1 = (y * cos_pitch) - (z * sin_pitch);
float z1 = (y * sin_pitch) + (z * cos_pitch);
// Yaw (rotació eix Y): guiñada esquerra/dreta
float cos_yaw = std::cos(rot.yaw);
float sin_yaw = std::sin(rot.yaw);
float x2 = x * cos_yaw + z1 * sin_yaw;
float z2 = -x * sin_yaw + z1 * cos_yaw;
float x2 = (x * cos_yaw) + (z1 * sin_yaw);
float z2 = (-x * sin_yaw) + (z1 * cos_yaw);
// Roll (rotació eix Z): alabeo lateral
float cos_roll = std::cos(rot.roll);
float sin_roll = std::sin(rot.roll);
float x3 = x2 * cos_roll - y1 * sin_roll;
float y3 = x2 * sin_roll + y1 * cos_roll;
float x3 = (x2 * cos_roll) - (y1 * sin_roll);
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 → +∞)
@@ -65,8 +65,8 @@ static Punt transform_point(const Punt& point, const Punt& shape_centre, const P
float cos_a = std::cos(angle);
float sin_a = std::sin(angle);
float rotated_x = scaled_x * cos_a - scaled_y * sin_a;
float rotated_y = scaled_x * sin_a + scaled_y * cos_a;
float rotated_x = (scaled_x * cos_a) - (scaled_y * sin_a);
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
// 5. Aplicar trasllació a posició mundial
return {rotated_x + posicio.x, rotated_y + posicio.y};

View File

@@ -54,7 +54,7 @@ inline void obtenir_limits_zona_segurs(float radi, float& min_x, float& max_x, f
// Obtenir centre de l'àrea de joc
inline void obtenir_centre_zona(float& centre_x, float& centre_y) {
const auto& zona = Defaults::Zones::PLAYAREA;
centre_x = zona.x + zona.w / 2.0F;
centre_y = zona.y + zona.h / 2.0F;
centre_x = zona.x + (zona.w / 2.0F);
centre_y = zona.y + (zona.h / 2.0F);
}
} // namespace Constants

View File

@@ -28,8 +28,8 @@ static Punt transform_point(const Punt& point, const Punt& shape_centre, const P
float cos_a = std::cos(angle);
float sin_a = std::sin(angle);
float rotated_x = scaled_x * cos_a - scaled_y * sin_a;
float rotated_y = scaled_x * sin_a + scaled_y * cos_a;
float rotated_x = (scaled_x * cos_a) - (scaled_y * sin_a);
float rotated_y = (scaled_x * sin_a) + (scaled_y * cos_a);
// 4. Aplicar trasllació a posició mundial
return {rotated_x + posicio.x, rotated_y + posicio.y};
@@ -105,12 +105,12 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
// 5. Velocitat inicial (base ± variació aleatòria + velocitat heretada)
float speed =
velocitat_base +
((std::rand() / static_cast<float>(RAND_MAX)) * 2.0F - 1.0F) *
Defaults::Physics::Debris::VARIACIO_VELOCITAT;
(((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->velocitat.x = (direccio.x * speed) + velocitat_objecte.x;
debris->velocitat.y = (direccio.y * speed) + velocitat_objecte.y;
debris->acceleracio = Defaults::Physics::Debris::ACCELERACIO;
// 6. Herència de velocitat angular amb cap + conversió d'excés
@@ -120,14 +120,14 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
// FASE 1: Aplicar herència i variació (igual que abans)
float factor_herencia =
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN +
(std::rand() / static_cast<float>(RAND_MAX)) *
((std::rand() / static_cast<float>(RAND_MAX)) *
(Defaults::Physics::Debris::FACTOR_HERENCIA_MAX -
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN);
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN));
float velocitat_ang_heretada = velocitat_angular * factor_herencia;
float variacio =
(std::rand() / static_cast<float>(RAND_MAX)) * 0.2F - 0.1F;
((std::rand() / static_cast<float>(RAND_MAX)) * 0.2F) - 0.1F;
velocitat_ang_heretada *= (1.0F + variacio);
// FASE 2: Aplicar cap i calcular excés
@@ -171,15 +171,15 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
// Variació aleatòria petita (±5%) per naturalitat
float variacio_visual =
(std::rand() / static_cast<float>(RAND_MAX)) * 0.1F - 0.05F;
((std::rand() / static_cast<float>(RAND_MAX)) * 0.1F) - 0.05F;
debris->velocitat_rot_visual *= (1.0F + variacio_visual);
} else {
// Rotació visual aleatòria (factor = 0.0 o sin velocidad angular)
debris->velocitat_rot_visual =
Defaults::Physics::Debris::ROTACIO_MIN +
(std::rand() / static_cast<float>(RAND_MAX)) *
((std::rand() / static_cast<float>(RAND_MAX)) *
(Defaults::Physics::Debris::ROTACIO_MAX -
Defaults::Physics::Debris::ROTACIO_MIN);
Defaults::Physics::Debris::ROTACIO_MIN));
// 50% probabilitat de rotació en sentit contrari
if (std::rand() % 2 == 0) {
@@ -219,8 +219,8 @@ void DebrisManager::actualitzar(float delta_time) {
// 2. Actualitzar velocitat (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.velocitat.x * debris.velocitat.x) +
(debris.velocitat.y * debris.velocitat.y));
if (speed > 1.0F) {
// Calcular direcció normalitzada
@@ -228,7 +228,7 @@ void DebrisManager::actualitzar(float delta_time) {
float dir_y = debris.velocitat.y / speed;
// Aplicar acceleració negativa (fricció)
float nova_speed = speed + debris.acceleracio * delta_time;
float nova_speed = speed + (debris.acceleracio * delta_time);
if (nova_speed < 0.0F)
nova_speed = 0.0F;
@@ -252,8 +252,8 @@ void DebrisManager::actualitzar(float delta_time) {
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.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);
}
// 2c. Aplicar fricció angular (desacceleració gradual)
@@ -290,14 +290,14 @@ void DebrisManager::actualitzar(float delta_time) {
float dy = debris.p2.y - debris.p1.y;
// 7. Reconstruir segment amb nova mida i rotació
float half_length = std::sqrt(dx * dx + dy * dy) * shrink_factor / 2.0F;
float half_length = std::sqrt((dx * dx) + (dy * dy)) * shrink_factor / 2.0F;
float original_angle = std::atan2(dy, dx);
float new_angle = original_angle + debris.angle_rotacio;
debris.p1.x = centre.x - half_length * std::cos(new_angle);
debris.p1.y = centre.y - half_length * std::sin(new_angle);
debris.p2.x = centre.x + half_length * std::cos(new_angle);
debris.p2.y = centre.y + half_length * std::sin(new_angle);
debris.p1.x = centre.x - (half_length * std::cos(new_angle));
debris.p1.y = centre.y - (half_length * std::sin(new_angle));
debris.p2.x = centre.x + (half_length * std::cos(new_angle));
debris.p2.y = centre.y + (half_length * std::sin(new_angle));
}
}
@@ -339,7 +339,7 @@ Punt DebrisManager::calcular_direccio_explosio(const Punt& p1,
float dy = centro_seg_y - centre_objecte.y;
// 3. Normalitzar (obtenir vector unitari)
float length = std::sqrt(dx * dx + dy * dy);
float length = std::sqrt((dx * dx) + (dy * dy));
if (length < 0.001F) {
// Segment al centre (cas extrem molt improbable), retornar direcció aleatòria
float angle_rand =
@@ -357,8 +357,8 @@ Punt DebrisManager::calcular_direccio_explosio(const Punt& p1,
float cos_v = std::cos(angle_variacio);
float sin_v = std::sin(angle_variacio);
float final_x = dx * cos_v - dy * sin_v;
float final_y = dx * sin_v + dy * cos_v;
float final_x = (dx * cos_v) - (dy * sin_v);
float final_y = (dx * sin_v) + (dy * cos_v);
return {final_x, final_y};
}

View File

@@ -98,8 +98,8 @@ void Bala::mou(float delta_time) {
float velocitat_efectiva = velocitat_ * delta_time;
// Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt)
float dy = velocitat_efectiva * std::sin(angle_ - Constants::PI / 2.0F);
float dx = velocitat_efectiva * std::cos(angle_ - Constants::PI / 2.0F);
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
// Acumulació directa amb precisió subpíxel
centre_.y += dy;

View File

@@ -115,7 +115,7 @@ void Enemic::inicialitzar(TipusEnemic tipus, const Punt* ship_pos) {
// Rotació visual aleatòria (rad/s) dins del rang del tipus
float drotacio_range = drotacio_max - drotacio_min;
drotacio_ = drotacio_min + (static_cast<float>(std::rand()) / RAND_MAX) * drotacio_range;
drotacio_ = drotacio_min + ((static_cast<float>(std::rand()) / RAND_MAX) * drotacio_range);
rotacio_ = 0.0F;
// Inicialitzar estat d'animació
@@ -149,7 +149,7 @@ void Enemic::actualitzar(float delta_time) {
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_START;
constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_END;
brightness_ = START + (END - START) * smooth_t;
brightness_ = START + ((END - START) * smooth_t);
}
// Moviment autònom
@@ -195,8 +195,8 @@ void Enemic::comportament_pentagon(float delta_time) {
float velocitat_efectiva = velocitat_ * delta_time;
// Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt)
float dy = velocitat_efectiva * std::sin(angle_ - Constants::PI / 2.0F);
float dx = velocitat_efectiva * std::cos(angle_ - Constants::PI / 2.0F);
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
float new_y = centre_.y + dy;
float new_x = centre_.x + dx;
@@ -246,7 +246,7 @@ void Enemic::comportament_quadrat(float delta_time) {
// Calculate angle to ship
float dx = ship_position_->x - centre_.x;
float dy = ship_position_->y - centre_.y;
float target_angle = std::atan2(dy, dx) + Constants::PI / 2.0F;
float target_angle = std::atan2(dy, dx) + (Constants::PI / 2.0F);
// Interpolate toward target angle
float angle_diff = target_angle - angle_;
@@ -262,8 +262,8 @@ void Enemic::comportament_quadrat(float delta_time) {
// Move in current direction
float velocitat_efectiva = velocitat_ * delta_time;
float dy = velocitat_efectiva * std::sin(angle_ - Constants::PI / 2.0F);
float dx = velocitat_efectiva * std::cos(angle_ - Constants::PI / 2.0F);
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
float new_y = centre_.y + dy;
float new_x = centre_.x + dx;
@@ -297,7 +297,7 @@ void Enemic::comportament_molinillo(float delta_time) {
if (ship_position_) {
float dx = ship_position_->x - centre_.x;
float dy = ship_position_->y - centre_.y;
float distance = std::sqrt(dx * dx + dy * dy);
float distance = std::sqrt((dx * dx) + (dy * dy));
if (distance < Defaults::Enemies::Molinillo::PROXIMITY_DISTANCE) {
// Temporarily boost rotation speed when near ship
@@ -311,8 +311,8 @@ void Enemic::comportament_molinillo(float delta_time) {
// Fast straight-line movement
float velocitat_efectiva = velocitat_ * delta_time;
float dy = velocitat_efectiva * std::sin(angle_ - Constants::PI / 2.0F);
float dx = velocitat_efectiva * std::cos(angle_ - Constants::PI / 2.0F);
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
float new_y = centre_.y + dy;
float new_x = centre_.x + dx;
@@ -378,17 +378,17 @@ void Enemic::actualitzar_palpitacio(float delta_time) {
float freq_range = Defaults::Enemies::Animation::PALPITACIO_FREQ_MAX -
Defaults::Enemies::Animation::PALPITACIO_FREQ_MIN;
animacio_.palpitacio_frequencia = Defaults::Enemies::Animation::PALPITACIO_FREQ_MIN +
(static_cast<float>(std::rand()) / RAND_MAX) * freq_range;
((static_cast<float>(std::rand()) / RAND_MAX) * freq_range);
float amp_range = Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MAX -
Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MIN;
animacio_.palpitacio_amplitud = Defaults::Enemies::Animation::PALPITACIO_AMPLITUD_MIN +
(static_cast<float>(std::rand()) / RAND_MAX) * amp_range;
((static_cast<float>(std::rand()) / RAND_MAX) * amp_range);
float dur_range = Defaults::Enemies::Animation::PALPITACIO_DURACIO_MAX -
Defaults::Enemies::Animation::PALPITACIO_DURACIO_MIN;
animacio_.palpitacio_temps_restant = Defaults::Enemies::Animation::PALPITACIO_DURACIO_MIN +
(static_cast<float>(std::rand()) / RAND_MAX) * dur_range;
((static_cast<float>(std::rand()) / RAND_MAX) * dur_range);
}
}
}
@@ -410,7 +410,7 @@ void Enemic::actualitzar_rotacio_accelerada(float delta_time) {
// Interpolate between base and target
float initial = animacio_.drotacio_base;
float target = animacio_.drotacio_objetivo;
drotacio_ = initial + (target - initial) * smooth_t;
drotacio_ = initial + ((target - initial) * smooth_t);
}
} else {
// Random trigger for new acceleration
@@ -425,7 +425,7 @@ void Enemic::actualitzar_rotacio_accelerada(float delta_time) {
float mult_range = Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MAX -
Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MIN;
float multiplier = Defaults::Enemies::Animation::ROTACIO_ACCEL_MULTIPLIER_MIN +
(static_cast<float>(std::rand()) / RAND_MAX) * mult_range;
((static_cast<float>(std::rand()) / RAND_MAX) * mult_range);
animacio_.drotacio_objetivo = animacio_.drotacio_base * multiplier;
@@ -433,7 +433,7 @@ void Enemic::actualitzar_rotacio_accelerada(float delta_time) {
float dur_range = Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MAX -
Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MIN;
animacio_.drotacio_duracio = Defaults::Enemies::Animation::ROTACIO_ACCEL_DURACIO_MIN +
(static_cast<float>(std::rand()) / RAND_MAX) * dur_range;
((static_cast<float>(std::rand()) / RAND_MAX) * dur_range);
}
}
}
@@ -453,7 +453,7 @@ float Enemic::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;
escala = 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);
@@ -507,7 +507,7 @@ bool Enemic::intent_spawn_safe(const Punt& ship_pos, float& out_x, float& out_y)
// Check Euclidean distance to ship
float dx = out_x - ship_pos.x;
float dy = out_y - ship_pos.y;
float distancia = std::sqrt(dx * dx + dy * dy);
float distancia = std::sqrt((dx * dx) + (dy * dy));
// Return true if position is safe (>= 36px from ship)
return distancia >= Defaults::Enemies::Spawn::SAFETY_DISTANCE;

View File

@@ -53,8 +53,8 @@ class Enemic {
float get_drotacio() const { return drotacio_; }
Punt get_velocitat_vector() const {
return {
velocitat_ * std::cos(angle_ - Constants::PI / 2.0F),
velocitat_ * std::sin(angle_ - Constants::PI / 2.0F)};
velocitat_ * std::cos(angle_ - (Constants::PI / 2.0F)),
velocitat_ * std::sin(angle_ - (Constants::PI / 2.0F))};
}
// Set ship position reference for tracking behavior

View File

@@ -174,10 +174,10 @@ void Nau::aplicar_fisica(float delta_time) {
// S'usa (angle - PI/2) perquè angle=0 apunta cap amunt, no cap a la dreta
// velocitat_ està en px/s, així que multipliquem per delta_time
float dy =
(velocitat_ * delta_time) * std::sin(angle_ - Constants::PI / 2.0F) +
((velocitat_ * delta_time) * std::sin(angle_ - (Constants::PI / 2.0F))) +
centre_.y;
float dx =
(velocitat_ * delta_time) * std::cos(angle_ - Constants::PI / 2.0F) +
((velocitat_ * delta_time) * std::cos(angle_ - (Constants::PI / 2.0F))) +
centre_.x;
// Boundary checking amb radi de la nau

View File

@@ -32,8 +32,8 @@ class Nau {
float get_brightness() const { return brightness_; }
Punt get_velocitat_vector() const {
return {
velocitat_ * std::cos(angle_ - Constants::PI / 2.0F),
velocitat_ * std::sin(angle_ - Constants::PI / 2.0F)};
velocitat_ * std::cos(angle_ - (Constants::PI / 2.0F)),
velocitat_ * std::sin(angle_ - (Constants::PI / 2.0F))};
}
// Setters

View File

@@ -553,8 +553,8 @@ void EscenaJoc::dibuixar() {
// Calcular centre de l'àrea de joc usant constants
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
float centre_x = play_area.x + play_area.w / 2.0F;
float centre_y = play_area.y + play_area.h / 2.0F;
float centre_x = play_area.x + (play_area.w / 2.0F);
float centre_y = play_area.y + (play_area.h / 2.0F);
text_.render_centered(game_over_text, {centre_x, centre_y}, escala, spacing);
@@ -761,7 +761,7 @@ void EscenaJoc::dibuixar_marcador() {
// Calcular centre de la zona del marcador
const SDL_FRect& scoreboard = Defaults::Zones::SCOREBOARD;
float centre_x = scoreboard.w / 2.0F;
float centre_y = scoreboard.y + scoreboard.h / 2.0F;
float centre_y = scoreboard.y + (scoreboard.h / 2.0F);
// Renderitzar centrat
text_.render_centered(text, {centre_x, centre_y}, escala, spacing);
@@ -792,11 +792,11 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
float phase1_progress = std::min(eased_progress / PHASE_1_END, 1.0F);
// Línia esquerra: creix des del centre cap a l'esquerra
int x1_phase1 = static_cast<int>(cx - (cx - x1) * phase1_progress);
int x1_phase1 = static_cast<int>(cx - ((cx - x1) * phase1_progress));
Rendering::linea(sdl_.obte_renderer(), cx, y1, x1_phase1, y1, true);
// Línia dreta: creix des del centre cap a la dreta
int x2_phase1 = static_cast<int>(cx + (x2 - cx) * phase1_progress);
int x2_phase1 = static_cast<int>(cx + ((x2 - cx) * phase1_progress));
Rendering::linea(sdl_.obte_renderer(), cx, y1, x2_phase1, y1, true);
}
@@ -805,7 +805,7 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
float phase2_progress = std::min((eased_progress - PHASE_1_END) / (PHASE_2_END - PHASE_1_END), 1.0F);
// Línia esquerra: creix des de dalt cap a baix
int y2_phase2 = static_cast<int>(y1 + (y2 - y1) * phase2_progress);
int y2_phase2 = static_cast<int>(y1 + ((y2 - y1) * phase2_progress));
Rendering::linea(sdl_.obte_renderer(), x1, y1, x1, y2_phase2, true);
// Línia dreta: creix des de dalt cap a baix
@@ -817,11 +817,11 @@ void EscenaJoc::dibuixar_marges_animat(float progress) const {
float phase3_progress = (eased_progress - PHASE_2_END) / (1.0F - PHASE_2_END);
// Línia esquerra: creix des de l'esquerra cap al centre
int x_left_phase3 = static_cast<int>(x1 + (cx - x1) * phase3_progress);
int x_left_phase3 = static_cast<int>(x1 + ((cx - x1) * phase3_progress));
Rendering::linea(sdl_.obte_renderer(), x1, y2, x_left_phase3, y2, true);
// Línia dreta: creix des de la dreta cap al centre
int x_right_phase3 = static_cast<int>(x2 - (x2 - cx) * phase3_progress);
int x_right_phase3 = static_cast<int>(x2 - ((x2 - cx) * phase3_progress));
Rendering::linea(sdl_.obte_renderer(), x2, y2, x_right_phase3, y2, true);
}
}
@@ -842,13 +842,13 @@ void EscenaJoc::dibuixar_marcador_animat(float progress) {
// Calcular centre de la zona del marcador
const SDL_FRect& scoreboard = Defaults::Zones::SCOREBOARD;
float centre_x = scoreboard.w / 2.0F;
float centre_y_final = scoreboard.y + scoreboard.h / 2.0F;
float centre_y_final = scoreboard.y + (scoreboard.h / 2.0F);
// Posició Y inicial (offscreen, sota de la pantalla)
float centre_y_inicial = static_cast<float>(Defaults::Game::HEIGHT);
// Interpolació amb easing
float centre_y_animada = centre_y_inicial + (centre_y_final - centre_y_inicial) * eased_progress;
float centre_y_animada = centre_y_inicial + ((centre_y_final - centre_y_inicial) * eased_progress);
// Renderitzar centrat en posició animada
text_.render_centered(text, {centre_x, centre_y_animada}, escala, spacing);
@@ -873,7 +873,7 @@ Punt EscenaJoc::calcular_posicio_nau_init_hud(float progress, uint8_t player_id)
// X no canvia (destí segons player_id)
// Y interpola amb easing
float y_animada = y_inicial + (y_final - y_inicial) * eased_progress;
float y_animada = y_inicial + ((y_final - y_inicial) * eased_progress);
return {x_final, y_animada};
}
@@ -971,7 +971,7 @@ void EscenaJoc::detectar_col·lisions_bales_enemics() {
// Calcular distància quadrada (evita sqrt)
float dx = pos_bala.x - pos_enemic.x;
float dy = pos_bala.y - pos_enemic.y;
float distancia_quadrada = dx * dx + dy * dy;
float distancia_quadrada = (dx * dx) + (dy * dy);
// Comprovar col·lisió
if (distancia_quadrada <= SUMA_RADIS_QUADRAT) {
@@ -1058,7 +1058,7 @@ void EscenaJoc::detectar_col·lisio_naus_enemics() {
// Calculate squared distance (avoid sqrt)
float dx = static_cast<float>(pos_nau.x - pos_enemic.x);
float dy = static_cast<float>(pos_nau.y - pos_enemic.y);
float distancia_quadrada = dx * dx + dy * dy;
float distancia_quadrada = (dx * dx) + (dy * dy);
// Check collision
if (distancia_quadrada <= SUMA_RADIS_QUADRAT) {
@@ -1113,7 +1113,7 @@ void EscenaJoc::detectar_col·lisions_bales_jugadors() {
// Calculate squared distance (avoid sqrt)
float dx = pos_bala.x - pos_nau.x;
float dy = pos_bala.y - pos_nau.y;
float distancia_quadrada = dx * dx + dy * dy;
float distancia_quadrada = (dx * dx) + (dy * dy);
// Check collision
if (distancia_quadrada <= SUMA_RADIS_QUADRAT) {
@@ -1203,7 +1203,7 @@ void EscenaJoc::dibuixar_missatge_stage(const std::string& missatge) {
float text_height = text_.get_text_height(escala);
// Calculate position as if FULL text was there (for fixed position typewriter)
float x = play_area.x + (play_area.w - full_text_width) / 2.0F;
float x = play_area.x + ((play_area.w - full_text_width) / 2.0F);
float y = play_area.y + (play_area.h * Defaults::Game::STAGE_MESSAGE_Y_RATIO) - (text_height / 2.0F);
// Render only the partial message (typewriter effect)
@@ -1230,8 +1230,8 @@ Punt EscenaJoc::obtenir_punt_spawn(uint8_t player_id) const {
}
return {
zona.x + zona.w * x_ratio,
zona.y + zona.h * Defaults::Game::SPAWN_Y_RATIO};
zona.x + (zona.w * x_ratio),
zona.y + (zona.h * Defaults::Game::SPAWN_Y_RATIO)};
}
void EscenaJoc::disparar_bala(uint8_t player_id) {
@@ -1247,8 +1247,8 @@ void EscenaJoc::disparar_bala(uint8_t player_id) {
constexpr float LOCAL_TIP_Y = -12.0F;
float cos_a = std::cos(ship_angle);
float sin_a = std::sin(ship_angle);
float tip_x = LOCAL_TIP_X * cos_a - LOCAL_TIP_Y * sin_a + ship_centre.x;
float tip_y = LOCAL_TIP_X * sin_a + LOCAL_TIP_Y * cos_a + ship_centre.y;
float tip_x = (LOCAL_TIP_X * cos_a) - (LOCAL_TIP_Y * sin_a) + ship_centre.x;
float tip_y = (LOCAL_TIP_X * sin_a) + (LOCAL_TIP_Y * cos_a) + ship_centre.y;
Punt posicio_dispar = {tip_x, tip_y};
// Buscar primera bala inactiva en el pool del jugador
@@ -1380,8 +1380,8 @@ void EscenaJoc::dibuixar_continue() {
float escala_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_SCALE;
float y_ratio_continue = Defaults::Game::ContinueScreen::CONTINUE_TEXT_Y_RATIO;
float centre_x = play_area.x + play_area.w / 2.0F;
float centre_y_continue = play_area.y + play_area.h * y_ratio_continue;
float centre_x = play_area.x + (play_area.w / 2.0F);
float centre_y_continue = play_area.y + (play_area.h * y_ratio_continue);
text_.render_centered(continue_text, {centre_x, centre_y_continue}, escala_continue, spacing);
@@ -1390,7 +1390,7 @@ void EscenaJoc::dibuixar_continue() {
float escala_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_SCALE;
float y_ratio_counter = Defaults::Game::ContinueScreen::COUNTER_TEXT_Y_RATIO;
float centre_y_counter = play_area.y + play_area.h * y_ratio_counter;
float centre_y_counter = play_area.y + (play_area.h * y_ratio_counter);
text_.render_centered(counter_str, {centre_x, centre_y_counter}, escala_counter, spacing);
@@ -1400,7 +1400,7 @@ void EscenaJoc::dibuixar_continue() {
float escala_info = Defaults::Game::ContinueScreen::INFO_TEXT_SCALE;
float y_ratio_info = Defaults::Game::ContinueScreen::INFO_TEXT_Y_RATIO;
float centre_y_info = play_area.y + play_area.h * y_ratio_info;
float centre_y_info = play_area.y + (play_area.h * y_ratio_info);
text_.render_centered(continues_text, {centre_x, centre_y_info}, escala_info, spacing);
}

View File

@@ -365,14 +365,14 @@ void EscenaLogo::dibuixar() {
Punt pos_actual;
pos_actual.x =
ORIGEN_ZOOM.x + (lletra.posicio.x - ORIGEN_ZOOM.x) * letra_progress;
ORIGEN_ZOOM.x + ((lletra.posicio.x - ORIGEN_ZOOM.x) * letra_progress);
pos_actual.y =
ORIGEN_ZOOM.y + (lletra.posicio.y - ORIGEN_ZOOM.y) * letra_progress;
ORIGEN_ZOOM.y + ((lletra.posicio.y - ORIGEN_ZOOM.y) * letra_progress);
float t = letra_progress;
float ease_factor = 1.0F - (1.0F - t) * (1.0F - t);
float ease_factor = 1.0F - ((1.0F - t) * (1.0F - t));
float escala_actual =
ESCALA_INICIAL + (ESCALA_FINAL - ESCALA_INICIAL) * ease_factor;
ESCALA_INICIAL + ((ESCALA_FINAL - ESCALA_INICIAL) * ease_factor);
Rendering::render_shape(
sdl_.obte_renderer(),

View File

@@ -525,7 +525,7 @@ void EscenaTitol::actualitzar_animacio_logo(float delta_time) {
// Calcular offset orbital
float offset_x = amplitude_x_actual * std::sin(2.0F * Defaults::Math::PI * frequency_x_actual * temps_animacio_);
float offset_y = amplitude_y_actual * std::sin(2.0F * Defaults::Math::PI * frequency_y_actual * temps_animacio_ + ORBIT_PHASE_OFFSET);
float offset_y = amplitude_y_actual * std::sin((2.0F * Defaults::Math::PI * frequency_y_actual * temps_animacio_) + ORBIT_PHASE_OFFSET);
// Aplicar offset a totes les lletres de "ORNI"
for (size_t i = 0; i < lletres_orni_.size(); ++i) {
@@ -576,8 +576,8 @@ void EscenaTitol::dibuixar() {
float frequency_y_shadow = ORBIT_FREQUENCY_Y;
// Calcular offset de l'ombra
float shadow_offset_x = amplitude_x_shadow * std::sin(2.0F * Defaults::Math::PI * frequency_x_shadow * temps_shadow) + SHADOW_OFFSET_X;
float shadow_offset_y = amplitude_y_shadow * std::sin(2.0F * Defaults::Math::PI * frequency_y_shadow * temps_shadow + ORBIT_PHASE_OFFSET) + SHADOW_OFFSET_Y;
float shadow_offset_x = (amplitude_x_shadow * std::sin(2.0F * Defaults::Math::PI * frequency_x_shadow * temps_shadow)) + SHADOW_OFFSET_X;
float shadow_offset_y = (amplitude_y_shadow * std::sin((2.0F * Defaults::Math::PI * frequency_y_shadow * temps_shadow) + ORBIT_PHASE_OFFSET)) + SHADOW_OFFSET_Y;
// === RENDERITZAR OMBRA PRIMER (darrera del logo principal) ===

View File

@@ -206,7 +206,7 @@ void ShipAnimator::actualitzar_floating(NauTitol& nau, float 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);
float offset_y = nau.amplitude_y * std::sin((2.0F * Defaults::Math::PI * nau.frequency_y * nau.fase_oscilacio) + FLOAT_PHASE_OFFSET);
// Aplicar oscil·lació a la posició objectiu
nau.posicio_actual.x = nau.posicio_objectiu.x + offset_x;
@@ -323,8 +323,8 @@ Punt ShipAnimator::calcular_posicio_fora_pantalla(float angle_rellotge) const {
// ENTRY_OFFSET es calcula automàticament: (SHIP_MAX_RADIUS * ENTRY_SCALE_START) + ENTRY_OFFSET_MARGIN
float extended_radius = CLOCK_RADIUS + ENTRY_OFFSET;
float x = Defaults::Game::WIDTH / 2.0F + extended_radius * std::cos(angle_rellotge);
float y = Defaults::Game::HEIGHT / 2.0F + extended_radius * std::sin(angle_rellotge);
float x = (Defaults::Game::WIDTH / 2.0F) + (extended_radius * std::cos(angle_rellotge));
float y = (Defaults::Game::HEIGHT / 2.0F) + (extended_radius * std::sin(angle_rellotge));
return {x, y};
}

View File

@@ -66,7 +66,7 @@ end;
procedure crear_poligon_regular(var pol : poligon; n : byte; r : real);
var i ; word;
act, interval : real;
act, interval ; real;
aux : ipunt;
begin {getmem(pol.ipunts,{n*464000);}
interval:=2*pi/n;