refactor(effects): renombra temps_vida/temps_max a elapsed_time/max_lifetime
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Effects {
|
|||||||
// Política: viu sempre durant min_lifetime, després mor quan
|
// Política: viu sempre durant min_lifetime, després mor quan
|
||||||
// |velocity| < MIN_SPEED_TO_DIE (definit en Defaults). Així els
|
// |velocity| < MIN_SPEED_TO_DIE (definit en Defaults). Així els
|
||||||
// fragments ràpids no "popen" en moviment.
|
// fragments ràpids no "popen" en moviment.
|
||||||
float temps_vida; // Temps transcorregut (segons)
|
float elapsed_time; // Temps transcorregut (segons)
|
||||||
float min_lifetime; // Temps mínim garantit (segons)
|
float min_lifetime; // Temps mínim garantit (segons)
|
||||||
bool active; // Està actiu?
|
bool active; // Està actiu?
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ namespace Effects {
|
|||||||
|
|
||||||
// Vida i shrinking — min_lifetime és el temps mínim garantit; després
|
// Vida i shrinking — min_lifetime és el temps mínim garantit; després
|
||||||
// el fragment mor quan |velocity| < MIN_SPEED_TO_DIE.
|
// el fragment mor quan |velocity| < MIN_SPEED_TO_DIE.
|
||||||
debris->temps_vida = 0.0F;
|
debris->elapsed_time = 0.0F;
|
||||||
debris->min_lifetime = lifetime;
|
debris->min_lifetime = lifetime;
|
||||||
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
|
debris->factor_shrink = Defaults::Physics::Debris::SHRINK_RATE;
|
||||||
|
|
||||||
@@ -266,12 +266,12 @@ namespace Effects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. Actualitzar time de vida
|
// 1. Actualitzar time de vida
|
||||||
debris.temps_vida += delta_time;
|
debris.elapsed_time += delta_time;
|
||||||
|
|
||||||
// Política de mort: viu sí o sí durant min_lifetime; després mor
|
// Política de mort: viu sí o sí durant min_lifetime; després mor
|
||||||
// quan la velocity cau per sota d'un llindar. Així els fragments
|
// quan la velocity cau per sota d'un llindar. Així els fragments
|
||||||
// ràpids no desapareixen en moviment.
|
// ràpids no desapareixen en moviment.
|
||||||
if (debris.temps_vida >= debris.min_lifetime) {
|
if (debris.elapsed_time >= debris.min_lifetime) {
|
||||||
const float SPEED_SQ = (debris.velocity.x * debris.velocity.x) +
|
const float SPEED_SQ = (debris.velocity.x * debris.velocity.x) +
|
||||||
(debris.velocity.y * debris.velocity.y);
|
(debris.velocity.y * debris.velocity.y);
|
||||||
if (SPEED_SQ < Defaults::Physics::Debris::MIN_SPEED_TO_DIE_SQ) {
|
if (SPEED_SQ < Defaults::Physics::Debris::MIN_SPEED_TO_DIE_SQ) {
|
||||||
@@ -344,7 +344,7 @@ namespace Effects {
|
|||||||
// 6. Shrink lineal sobre la longitud ORIGINAL (no iteratiu).
|
// 6. Shrink lineal sobre la longitud ORIGINAL (no iteratiu).
|
||||||
// SHRINK_T va de 0 a 1 al llarg de min_lifetime; després queda
|
// SHRINK_T va de 0 a 1 al llarg de min_lifetime; després queda
|
||||||
// a 1 i el shrink_factor manté el valor mínim (1 - factor_shrink).
|
// a 1 i el shrink_factor manté el valor mínim (1 - factor_shrink).
|
||||||
const float SHRINK_T = std::min(debris.temps_vida / debris.min_lifetime, 1.0F);
|
const float SHRINK_T = std::min(debris.elapsed_time / debris.min_lifetime, 1.0F);
|
||||||
const float SHRINK_FACTOR = std::max(0.0F, 1.0F - (debris.factor_shrink * SHRINK_T));
|
const float SHRINK_FACTOR = std::max(0.0F, 1.0F - (debris.factor_shrink * SHRINK_T));
|
||||||
|
|
||||||
// 7. Reconstruir p1/p2 des de la geometria autoritaritzada:
|
// 7. Reconstruir p1/p2 des de la geometria autoritaritzada:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Effects {
|
|||||||
// tail = head − velocity_normalitzada × current_length.
|
// tail = head − velocity_normalitzada × current_length.
|
||||||
//
|
//
|
||||||
// Cicle de vida:
|
// Cicle de vida:
|
||||||
// Fase 1 (temps_vida < grow_duration): current_length creix linealment
|
// Fase 1 (elapsed_time < grow_duration): current_length creix linealment
|
||||||
// de 0 a max_length. Brillor al màxim.
|
// de 0 a max_length. Brillor al màxim.
|
||||||
// Fase 2: current_length = max_length × (speed/initial_speed) i brillor
|
// Fase 2: current_length = max_length × (speed/initial_speed) i brillor
|
||||||
// amb la mateixa proporció. Mor quan length o brightness cauen sota
|
// amb la mateixa proporció. Mor quan length o brightness cauen sota
|
||||||
@@ -30,7 +30,7 @@ namespace Effects {
|
|||||||
float max_length; // Longitud màxima (final de la fase de creixement)
|
float max_length; // Longitud màxima (final de la fase de creixement)
|
||||||
float grow_duration; // Temps de creixement de 0 a max_length (s)
|
float grow_duration; // Temps de creixement de 0 a max_length (s)
|
||||||
|
|
||||||
float temps_vida; // Acumulador (s)
|
float elapsed_time; // Acumulador (s)
|
||||||
float initial_speed; // Speed inicial per a la proporció de fase 2
|
float initial_speed; // Speed inicial per a la proporció de fase 2
|
||||||
|
|
||||||
float brightness; // 0..1
|
float brightness; // 0..1
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace Effects {
|
|||||||
fw->max_length = Defaults::FX::Firework::MAX_LENGTH;
|
fw->max_length = Defaults::FX::Firework::MAX_LENGTH;
|
||||||
fw->grow_duration = Defaults::FX::Firework::GROW_DURATION;
|
fw->grow_duration = Defaults::FX::Firework::GROW_DURATION;
|
||||||
|
|
||||||
fw->temps_vida = 0.0F;
|
fw->elapsed_time = 0.0F;
|
||||||
fw->initial_speed = SPEED;
|
fw->initial_speed = SPEED;
|
||||||
|
|
||||||
fw->brightness = initial_brightness;
|
fw->brightness = initial_brightness;
|
||||||
@@ -119,7 +119,7 @@ namespace Effects {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
fw.temps_vida += delta_time;
|
fw.elapsed_time += delta_time;
|
||||||
|
|
||||||
// 1. Fricció lineal (aplicar en la direcció del movement).
|
// 1. Fricció lineal (aplicar en la direcció del movement).
|
||||||
const float SPEED = std::sqrt(
|
const float SPEED = std::sqrt(
|
||||||
@@ -144,9 +144,9 @@ namespace Effects {
|
|||||||
bounceOffPlayArea(fw.head, fw.velocity);
|
bounceOffPlayArea(fw.head, fw.velocity);
|
||||||
|
|
||||||
// 4. Calcular longitud i brillor segons fase.
|
// 4. Calcular longitud i brillor segons fase.
|
||||||
if (fw.temps_vida < fw.grow_duration) {
|
if (fw.elapsed_time < fw.grow_duration) {
|
||||||
// Fase 1: creixement lineal de 0 a max_length.
|
// Fase 1: creixement lineal de 0 a max_length.
|
||||||
const float T = fw.temps_vida / fw.grow_duration;
|
const float T = fw.elapsed_time / fw.grow_duration;
|
||||||
fw.current_length = fw.max_length * T;
|
fw.current_length = fw.max_length * T;
|
||||||
fw.brightness = Defaults::FX::Firework::INITIAL_BRIGHTNESS;
|
fw.brightness = Defaults::FX::Firework::INITIAL_BRIGHTNESS;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
|
|
||||||
namespace Effects {
|
namespace Effects {
|
||||||
|
|
||||||
// FloatingScore: text animat que muestra points guanyats
|
// FloatingScore: text animat que muestra points guanyats
|
||||||
// S'activa cuando es destrueix un enemy i s'esvaeix después de un time
|
// S'activa cuando es destrueix un enemy i s'esvaeix después de un time
|
||||||
struct FloatingScore {
|
struct FloatingScore {
|
||||||
// Text a mostrar (e.g., "100", "150", "200")
|
// Text a mostrar (e.g., "100", "150", "200")
|
||||||
std::string text;
|
std::string text;
|
||||||
|
|
||||||
@@ -22,12 +22,12 @@ struct FloatingScore {
|
|||||||
Vec2 velocity; // px/s (normalment sin amunt: {0.0f, -30.0f})
|
Vec2 velocity; // px/s (normalment sin amunt: {0.0f, -30.0f})
|
||||||
|
|
||||||
// Animación de fade
|
// Animación de fade
|
||||||
float temps_vida; // Temps transcorregut (segons)
|
float elapsed_time; // Temps transcorregut (segons)
|
||||||
float temps_max; // Temps de vida màxim (segons)
|
float max_lifetime; // Temps de vida màxim (segons)
|
||||||
float brightness; // Brillantor calculada (0.0-1.0)
|
float brightness; // Brillantor calculada (0.0-1.0)
|
||||||
|
|
||||||
// Estat
|
// Estat
|
||||||
bool active;
|
bool active;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Effects
|
} // namespace Effects
|
||||||
|
|||||||
@@ -7,15 +7,15 @@
|
|||||||
|
|
||||||
namespace Effects {
|
namespace Effects {
|
||||||
|
|
||||||
FloatingScoreManager::FloatingScoreManager(Rendering::Renderer* renderer)
|
FloatingScoreManager::FloatingScoreManager(Rendering::Renderer* renderer)
|
||||||
: text_(renderer) {
|
: text_(renderer) {
|
||||||
// Inicialitzar todos los slots como inactius
|
// Inicialitzar todos los slots como inactius
|
||||||
for (auto& pf : pool_) {
|
for (auto& pf : pool_) {
|
||||||
pf.active = false;
|
pf.active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingScoreManager::crear(int points, const Vec2& position) {
|
void FloatingScoreManager::crear(int points, const Vec2& position) {
|
||||||
// 1. Trobar slot lliure
|
// 1. Trobar slot lliure
|
||||||
FloatingScore* pf = findFreeSlot();
|
FloatingScore* pf = findFreeSlot();
|
||||||
if (pf == nullptr) {
|
if (pf == nullptr) {
|
||||||
@@ -27,13 +27,13 @@ void FloatingScoreManager::crear(int points, const Vec2& position) {
|
|||||||
pf->position = position;
|
pf->position = position;
|
||||||
pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X,
|
pf->velocity = {.x = Defaults::FloatingScore::VELOCITY_X,
|
||||||
.y = Defaults::FloatingScore::VELOCITY_Y};
|
.y = Defaults::FloatingScore::VELOCITY_Y};
|
||||||
pf->temps_vida = 0.0F;
|
pf->elapsed_time = 0.0F;
|
||||||
pf->temps_max = Defaults::FloatingScore::LIFETIME;
|
pf->max_lifetime = Defaults::FloatingScore::LIFETIME;
|
||||||
pf->brightness = 1.0F;
|
pf->brightness = 1.0F;
|
||||||
pf->active = true;
|
pf->active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingScoreManager::update(float delta_time) {
|
void FloatingScoreManager::update(float delta_time) {
|
||||||
for (auto& pf : pool_) {
|
for (auto& pf : pool_) {
|
||||||
if (!pf.active) {
|
if (!pf.active) {
|
||||||
continue;
|
continue;
|
||||||
@@ -44,20 +44,20 @@ void FloatingScoreManager::update(float delta_time) {
|
|||||||
pf.position.y += pf.velocity.y * delta_time;
|
pf.position.y += pf.velocity.y * delta_time;
|
||||||
|
|
||||||
// 2. Actualitzar time de vida
|
// 2. Actualitzar time de vida
|
||||||
pf.temps_vida += delta_time;
|
pf.elapsed_time += delta_time;
|
||||||
|
|
||||||
// 3. Calcular brightness (fade lineal)
|
// 3. Calcular brightness (fade lineal)
|
||||||
float progress = pf.temps_vida / pf.temps_max; // 0.0 → 1.0
|
float progress = pf.elapsed_time / pf.max_lifetime; // 0.0 → 1.0
|
||||||
pf.brightness = 1.0F - progress; // 1.0 → 0.0
|
pf.brightness = 1.0F - progress; // 1.0 → 0.0
|
||||||
|
|
||||||
// 4. Desactivar cuando acaba el time
|
// 4. Desactivar cuando acaba el time
|
||||||
if (pf.temps_vida >= pf.temps_max) {
|
if (pf.elapsed_time >= pf.max_lifetime) {
|
||||||
pf.active = false;
|
pf.active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingScoreManager::draw() {
|
void FloatingScoreManager::draw() {
|
||||||
for (const auto& pf : pool_) {
|
for (const auto& pf : pool_) {
|
||||||
if (!pf.active) {
|
if (!pf.active) {
|
||||||
continue;
|
continue;
|
||||||
@@ -69,15 +69,15 @@ void FloatingScoreManager::draw() {
|
|||||||
|
|
||||||
text_.renderCentered(pf.text, pf.position, SCALE, SPACING, pf.brightness);
|
text_.renderCentered(pf.text, pf.position, SCALE, SPACING, pf.brightness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloatingScoreManager::reset() {
|
void FloatingScoreManager::reset() {
|
||||||
for (auto& pf : pool_) {
|
for (auto& pf : pool_) {
|
||||||
pf.active = false;
|
pf.active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FloatingScoreManager::getActiveCount() const -> int {
|
auto FloatingScoreManager::getActiveCount() const -> int {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (const auto& pf : pool_) {
|
for (const auto& pf : pool_) {
|
||||||
if (pf.active) {
|
if (pf.active) {
|
||||||
@@ -85,15 +85,15 @@ auto FloatingScoreManager::getActiveCount() const -> int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FloatingScoreManager::findFreeSlot() -> FloatingScore* {
|
auto FloatingScoreManager::findFreeSlot() -> FloatingScore* {
|
||||||
for (auto& pf : pool_) {
|
for (auto& pf : pool_) {
|
||||||
if (!pf.active) {
|
if (!pf.active) {
|
||||||
return &pf;
|
return &pf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr; // Pool ple
|
return nullptr; // Pool ple
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Effects
|
} // namespace Effects
|
||||||
|
|||||||
Reference in New Issue
Block a user