Files
orni_attack/source/game/effects/gestor_puntuacio_flotant.cpp
Sergio Valor bc94eff176 style: aplicar readability-uppercase-literal-suffix
- Cambiar todos los literales float de minúscula a mayúscula (1.0f → 1.0F)
- 657 correcciones aplicadas automáticamente con clang-tidy
- Check 1/N completado

🤖 Generated with Claude Code
2025-12-18 13:06:48 +01:00

95 lines
2.5 KiB
C++

// gestor_puntuacio_flotant.cpp - Implementació del gestor de números flotants
// © 2025 Port a C++20 amb SDL3
#include "gestor_puntuacio_flotant.hpp"
#include <string>
namespace Effects {
GestorPuntuacioFlotant::GestorPuntuacioFlotant(SDL_Renderer* renderer)
: text_(renderer) {
// Inicialitzar tots els slots com inactius
for (auto& pf : pool_) {
pf.actiu = false;
}
}
void GestorPuntuacioFlotant::crear(int punts, const Punt& posicio) {
// 1. Trobar slot lliure
PuntuacioFlotant* pf = trobar_slot_lliure();
if (!pf)
return; // Pool ple (improbable)
// 2. Inicialitzar puntuació flotant
pf->text = std::to_string(punts);
pf->posicio = posicio;
pf->velocitat = {Defaults::FloatingScore::VELOCITY_X,
Defaults::FloatingScore::VELOCITY_Y};
pf->temps_vida = 0.0F;
pf->temps_max = Defaults::FloatingScore::LIFETIME;
pf->brightness = 1.0F;
pf->actiu = true;
}
void GestorPuntuacioFlotant::actualitzar(float delta_time) {
for (auto& pf : pool_) {
if (!pf.actiu)
continue;
// 1. Actualitzar posició (deriva cap amunt)
pf.posicio.x += pf.velocitat.x * delta_time;
pf.posicio.y += pf.velocitat.y * delta_time;
// 2. Actualitzar temps de vida
pf.temps_vida += delta_time;
// 3. Calcular brightness (fade lineal)
float progress = pf.temps_vida / pf.temps_max; // 0.0 → 1.0
pf.brightness = 1.0F - progress; // 1.0 → 0.0
// 4. Desactivar quan acaba el temps
if (pf.temps_vida >= pf.temps_max) {
pf.actiu = false;
}
}
}
void GestorPuntuacioFlotant::dibuixar() {
for (const auto& pf : pool_) {
if (!pf.actiu)
continue;
// Renderitzar centrat amb brightness (fade)
constexpr float escala = Defaults::FloatingScore::SCALE;
constexpr float spacing = Defaults::FloatingScore::SPACING;
text_.render_centered(pf.text, pf.posicio, escala, spacing, pf.brightness);
}
}
void GestorPuntuacioFlotant::reiniciar() {
for (auto& pf : pool_) {
pf.actiu = false;
}
}
int GestorPuntuacioFlotant::get_num_actius() const {
int count = 0;
for (const auto& pf : pool_) {
if (pf.actiu)
count++;
}
return count;
}
PuntuacioFlotant* GestorPuntuacioFlotant::trobar_slot_lliure() {
for (auto& pf : pool_) {
if (!pf.actiu)
return &pf;
}
return nullptr; // Pool ple
}
} // namespace Effects