ae5cc1cfb4
Tots els tipus d'entitat passen del catala a l'angles seguint el
.clang-tidy del projecte (tipus en CamelCase, metodes en camelBack,
membres en lower_case amb sufix _).
Renames de tipus:
- Entitat -> Entity (core/entities/entity.hpp)
- Nau -> Ship (game/entities/ship.{hpp,cpp})
- Enemic -> Enemy (game/entities/enemy.{hpp,cpp})
- Bala -> Bullet (game/entities/bullet.{hpp,cpp})
- TipusEnemic -> EnemyType
- AnimacioEnemic -> EnemyAnimation
Metodes virtuals (s'aplica a tot el codi, no nomes a entitats):
- actualitzar -> update
- dibuixar -> draw
- inicialitzar -> init
- processar_input -> processInput
- esta_actiu -> isActive
- es_collidable -> isCollidable
- get_collision_radius -> getCollisionRadius
Getters comuns:
- get_centre -> getCenter
- get_angle -> getAngle
- get_brightness -> getBrightness
- get_forma -> getShape
Metodes especifics:
- esta_viva -> isAlive
- esta_tocada -> isHit
- es_invulnerable -> isInvulnerable
- get_velocitat_vector -> getVelocityVector
- set_centre -> setCenter
- marcar_tocada -> markHit
- aplicar_fisica -> applyPhysics
- get_tipus -> getType
Camps privats:
- centre_ -> center_
- velocitat_ -> velocity_
- forma_ -> shape_
- esta_tocada_ -> is_hit_
- tipus_ -> type_
L'import d'audio/input d'AEEA quedara coherent (mateix estil).
Diff net: 30 fitxers, +437/-437 (la majoria es renames simetrics).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
100 lines
2.6 KiB
C++
100 lines
2.6 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 Vec2& posicio) {
|
|
// 1. Trobar slot lliure
|
|
PuntuacioFlotant* pf = trobar_slot_lliure();
|
|
if (pf == nullptr) {
|
|
return; // Pool ple (improbable)
|
|
}
|
|
|
|
// 2. Inicialitzar puntuació flotant
|
|
pf->text = std::to_string(punts);
|
|
pf->posicio = posicio;
|
|
pf->velocitat = {.x = Defaults::FloatingScore::VELOCITY_X,
|
|
.y = Defaults::FloatingScore::VELOCITY_Y};
|
|
pf->temps_vida = 0.0F;
|
|
pf->temps_max = Defaults::FloatingScore::LIFETIME;
|
|
pf->brightness = 1.0F;
|
|
pf->actiu = true;
|
|
}
|
|
|
|
void GestorPuntuacioFlotant::update(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::draw() {
|
|
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
|