refactor(enemy): renombra esta_/animacio_/timer_invulnerabilitat_ a anglès
This commit is contained in:
@@ -157,23 +157,23 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
|||||||
rotation_ = 0.0F;
|
rotation_ = 0.0F;
|
||||||
|
|
||||||
// Estado de animación
|
// Estado de animación
|
||||||
animacio_ = EnemyAnimation();
|
animation_ = EnemyAnimation();
|
||||||
animacio_.rotation_delta_base = rotation_delta_;
|
animation_.rotation_delta_base = rotation_delta_;
|
||||||
animacio_.rotation_delta_target = rotation_delta_;
|
animation_.rotation_delta_target = rotation_delta_;
|
||||||
animacio_.rotation_delta_t = 1.0F;
|
animation_.rotation_delta_t = 1.0F;
|
||||||
|
|
||||||
// Invulnerabilidad post-spawn
|
// Invulnerabilidad post-spawn
|
||||||
timer_invulnerabilitat_ = Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
invulnerability_timer_ = Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
||||||
brightness_ = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_START;
|
brightness_ = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_START;
|
||||||
|
|
||||||
// Timer para próximo cambio de dirección (Pentagon)
|
// Timer para próximo cambio de dirección (Pentagon)
|
||||||
direction_change_timer_ = 0.0F;
|
direction_change_timer_ = 0.0F;
|
||||||
|
|
||||||
esta_ = true;
|
is_active_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::update(float delta_time) {
|
void Enemy::update(float delta_time) {
|
||||||
if (!esta_) {
|
if (!is_active_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,11 +189,11 @@ void Enemy::update(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decremento de invulnerabilidad + LERP de brightness
|
// Decremento de invulnerabilidad + LERP de brightness
|
||||||
if (timer_invulnerabilitat_ > 0.0F) {
|
if (invulnerability_timer_ > 0.0F) {
|
||||||
timer_invulnerabilitat_ -= delta_time;
|
invulnerability_timer_ -= delta_time;
|
||||||
timer_invulnerabilitat_ = std::max(timer_invulnerabilitat_, 0.0F);
|
invulnerability_timer_ = std::max(invulnerability_timer_, 0.0F);
|
||||||
|
|
||||||
const float T_INV = timer_invulnerabilitat_ / Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
const float T_INV = invulnerability_timer_ / Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
||||||
const float T = 1.0F - T_INV;
|
const float T = 1.0F - T_INV;
|
||||||
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
||||||
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_START;
|
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_BRIGHTNESS_START;
|
||||||
@@ -227,13 +227,13 @@ void Enemy::update(float delta_time) {
|
|||||||
|
|
||||||
void Enemy::postUpdate(float /*delta_time*/) {
|
void Enemy::postUpdate(float /*delta_time*/) {
|
||||||
// Sincronizar mirror tras la integración del world.
|
// Sincronizar mirror tras la integración del world.
|
||||||
if (esta_) {
|
if (is_active_) {
|
||||||
center_ = body_.position;
|
center_ = body_.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::draw() const {
|
void Enemy::draw() const {
|
||||||
if (!esta_ || !shape_) {
|
if (!is_active_ || !shape_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const float SCALE = computeCurrentScale();
|
const float SCALE = computeCurrentScale();
|
||||||
@@ -264,7 +264,7 @@ void Enemy::draw() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::destroy() {
|
void Enemy::destroy() {
|
||||||
esta_ = false;
|
is_active_ = false;
|
||||||
body_.velocity = Vec2{};
|
body_.velocity = Vec2{};
|
||||||
body_.angular_velocity = 0.0F;
|
body_.angular_velocity = 0.0F;
|
||||||
body_.radius = 0.0F; // No colisiona mientras está inactivo
|
body_.radius = 0.0F; // No colisiona mientras está inactivo
|
||||||
@@ -357,9 +357,9 @@ void Enemy::behaviorPinwheel(float /*delta_time*/) {
|
|||||||
const Vec2 TO_SHIP = *ship_position_ - center_;
|
const Vec2 TO_SHIP = *ship_position_ - center_;
|
||||||
const float DIST = TO_SHIP.length();
|
const float DIST = TO_SHIP.length();
|
||||||
if (DIST < Defaults::Enemies::Pinwheel::PROXIMITY_DISTANCE) {
|
if (DIST < Defaults::Enemies::Pinwheel::PROXIMITY_DISTANCE) {
|
||||||
rotation_delta_ = animacio_.rotation_delta_base * Defaults::Enemies::Pinwheel::ROTATION_DELTA_PROXIMITY_MULTIPLIER;
|
rotation_delta_ = animation_.rotation_delta_base * Defaults::Enemies::Pinwheel::ROTATION_DELTA_PROXIMITY_MULTIPLIER;
|
||||||
} else {
|
} else {
|
||||||
rotation_delta_ = animacio_.rotation_delta_base;
|
rotation_delta_ = animation_.rotation_delta_base;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Movimiento lineal puro: el world se encarga de integrar y rebotar.
|
// Movimiento lineal puro: el world se encarga de integrar y rebotar.
|
||||||
@@ -371,66 +371,66 @@ void Enemy::updateAnimation(float delta_time) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::updatePulse(float delta_time) {
|
void Enemy::updatePulse(float delta_time) {
|
||||||
if (animacio_.pulse_active) {
|
if (animation_.pulse_active) {
|
||||||
animacio_.pulse_phase += 2.0F * Constants::PI * animacio_.pulse_frequency * delta_time;
|
animation_.pulse_phase += 2.0F * Constants::PI * animation_.pulse_frequency * delta_time;
|
||||||
animacio_.pulse_time_remaining -= delta_time;
|
animation_.pulse_time_remaining -= delta_time;
|
||||||
if (animacio_.pulse_time_remaining <= 0.0F) {
|
if (animation_.pulse_time_remaining <= 0.0F) {
|
||||||
animacio_.pulse_active = false;
|
animation_.pulse_active = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const float RAND_VAL = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
const float RAND_VAL = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
||||||
const float TRIGGER_PROB = Defaults::Enemies::Animation::PULSE_TRIGGER_PROB * delta_time;
|
const float TRIGGER_PROB = Defaults::Enemies::Animation::PULSE_TRIGGER_PROB * delta_time;
|
||||||
if (RAND_VAL < TRIGGER_PROB) {
|
if (RAND_VAL < TRIGGER_PROB) {
|
||||||
animacio_.pulse_active = true;
|
animation_.pulse_active = true;
|
||||||
animacio_.pulse_phase = 0.0F;
|
animation_.pulse_phase = 0.0F;
|
||||||
|
|
||||||
const float FREQ_RANGE = Defaults::Enemies::Animation::PULSE_FREQ_MAX -
|
const float FREQ_RANGE = Defaults::Enemies::Animation::PULSE_FREQ_MAX -
|
||||||
Defaults::Enemies::Animation::PULSE_FREQ_MIN;
|
Defaults::Enemies::Animation::PULSE_FREQ_MIN;
|
||||||
animacio_.pulse_frequency = Defaults::Enemies::Animation::PULSE_FREQ_MIN +
|
animation_.pulse_frequency = Defaults::Enemies::Animation::PULSE_FREQ_MIN +
|
||||||
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * FREQ_RANGE);
|
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * FREQ_RANGE);
|
||||||
|
|
||||||
const float AMP_RANGE = Defaults::Enemies::Animation::PULSE_AMPLITUD_MAX -
|
const float AMP_RANGE = Defaults::Enemies::Animation::PULSE_AMPLITUD_MAX -
|
||||||
Defaults::Enemies::Animation::PULSE_AMPLITUD_MIN;
|
Defaults::Enemies::Animation::PULSE_AMPLITUD_MIN;
|
||||||
animacio_.pulse_amplitude = Defaults::Enemies::Animation::PULSE_AMPLITUD_MIN +
|
animation_.pulse_amplitude = Defaults::Enemies::Animation::PULSE_AMPLITUD_MIN +
|
||||||
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * AMP_RANGE);
|
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * AMP_RANGE);
|
||||||
|
|
||||||
const float DUR_RANGE = Defaults::Enemies::Animation::PULSE_DURACIO_MAX -
|
const float DUR_RANGE = Defaults::Enemies::Animation::PULSE_DURACIO_MAX -
|
||||||
Defaults::Enemies::Animation::PULSE_DURACIO_MIN;
|
Defaults::Enemies::Animation::PULSE_DURACIO_MIN;
|
||||||
animacio_.pulse_time_remaining = Defaults::Enemies::Animation::PULSE_DURACIO_MIN +
|
animation_.pulse_time_remaining = Defaults::Enemies::Animation::PULSE_DURACIO_MIN +
|
||||||
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * DUR_RANGE);
|
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * DUR_RANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::updateRotationAcceleration(float delta_time) {
|
void Enemy::updateRotationAcceleration(float delta_time) {
|
||||||
if (animacio_.rotation_delta_t < 1.0F) {
|
if (animation_.rotation_delta_t < 1.0F) {
|
||||||
animacio_.rotation_delta_t += delta_time / animacio_.rotation_delta_duration;
|
animation_.rotation_delta_t += delta_time / animation_.rotation_delta_duration;
|
||||||
if (animacio_.rotation_delta_t >= 1.0F) {
|
if (animation_.rotation_delta_t >= 1.0F) {
|
||||||
animacio_.rotation_delta_t = 1.0F;
|
animation_.rotation_delta_t = 1.0F;
|
||||||
animacio_.rotation_delta_base = animacio_.rotation_delta_target;
|
animation_.rotation_delta_base = animation_.rotation_delta_target;
|
||||||
rotation_delta_ = animacio_.rotation_delta_base;
|
rotation_delta_ = animation_.rotation_delta_base;
|
||||||
} else {
|
} else {
|
||||||
const float T = animacio_.rotation_delta_t;
|
const float T = animation_.rotation_delta_t;
|
||||||
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
||||||
const float INITIAL = animacio_.rotation_delta_base;
|
const float INITIAL = animation_.rotation_delta_base;
|
||||||
const float TARGET = animacio_.rotation_delta_target;
|
const float TARGET = animation_.rotation_delta_target;
|
||||||
rotation_delta_ = INITIAL + ((TARGET - INITIAL) * SMOOTH_T);
|
rotation_delta_ = INITIAL + ((TARGET - INITIAL) * SMOOTH_T);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const float RAND_VAL = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
const float RAND_VAL = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
|
||||||
const float TRIGGER_PROB = Defaults::Enemies::Animation::ROTATION_ACCEL_TRIGGER_PROB * delta_time;
|
const float TRIGGER_PROB = Defaults::Enemies::Animation::ROTATION_ACCEL_TRIGGER_PROB * delta_time;
|
||||||
if (RAND_VAL < TRIGGER_PROB) {
|
if (RAND_VAL < TRIGGER_PROB) {
|
||||||
animacio_.rotation_delta_t = 0.0F;
|
animation_.rotation_delta_t = 0.0F;
|
||||||
|
|
||||||
const float MULT_RANGE = Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MAX -
|
const float MULT_RANGE = Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MAX -
|
||||||
Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MIN;
|
Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MIN;
|
||||||
const float MULTIPLIER = Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MIN +
|
const float MULTIPLIER = Defaults::Enemies::Animation::ROTATION_ACCEL_MULTIPLIER_MIN +
|
||||||
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * MULT_RANGE);
|
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * MULT_RANGE);
|
||||||
animacio_.rotation_delta_target = animacio_.rotation_delta_base * MULTIPLIER;
|
animation_.rotation_delta_target = animation_.rotation_delta_base * MULTIPLIER;
|
||||||
|
|
||||||
const float DUR_RANGE = Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MAX -
|
const float DUR_RANGE = Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MAX -
|
||||||
Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MIN;
|
Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MIN;
|
||||||
animacio_.rotation_delta_duration = Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MIN +
|
animation_.rotation_delta_duration = Defaults::Enemies::Animation::ROTATION_ACCEL_DURACIO_MIN +
|
||||||
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * DUR_RANGE);
|
((static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX)) * DUR_RANGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -438,15 +438,15 @@ void Enemy::updateRotationAcceleration(float delta_time) {
|
|||||||
|
|
||||||
auto Enemy::computeCurrentScale() const -> float {
|
auto Enemy::computeCurrentScale() const -> float {
|
||||||
float scale = 1.0F;
|
float scale = 1.0F;
|
||||||
if (timer_invulnerabilitat_ > 0.0F) {
|
if (invulnerability_timer_ > 0.0F) {
|
||||||
const float T_INV = timer_invulnerabilitat_ / Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
const float T_INV = invulnerability_timer_ / Defaults::Enemies::Spawn::INVULNERABILITY_DURATION;
|
||||||
const float T = 1.0F - T_INV;
|
const float T = 1.0F - T_INV;
|
||||||
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
const float SMOOTH_T = T * T * (3.0F - (2.0F * T));
|
||||||
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_START;
|
constexpr float START = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_START;
|
||||||
constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_END;
|
constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_END;
|
||||||
scale = START + ((END - START) * SMOOTH_T);
|
scale = START + ((END - START) * SMOOTH_T);
|
||||||
} else if (animacio_.pulse_active) {
|
} else if (animation_.pulse_active) {
|
||||||
scale += animacio_.pulse_amplitude * std::sin(animacio_.pulse_phase);
|
scale += animation_.pulse_amplitude * std::sin(animation_.pulse_phase);
|
||||||
}
|
}
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
@@ -465,7 +465,7 @@ auto Enemy::getBaseVelocity() const -> float {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto Enemy::getBaseRotation() const -> float {
|
auto Enemy::getBaseRotation() const -> float {
|
||||||
return animacio_.rotation_delta_base != 0.0F ? animacio_.rotation_delta_base : rotation_delta_;
|
return animation_.rotation_delta_base != 0.0F ? animation_.rotation_delta_base : rotation_delta_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Enemy::setTrackingStrength(float strength) {
|
void Enemy::setTrackingStrength(float strength) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Enemy : public Entities::Entity {
|
|||||||
void draw() const override;
|
void draw() const override;
|
||||||
|
|
||||||
// Override: Interfaz de Entity
|
// Override: Interfaz de Entity
|
||||||
[[nodiscard]] auto isActive() const -> bool override { return esta_; }
|
[[nodiscard]] auto isActive() const -> bool override { return is_active_; }
|
||||||
|
|
||||||
// Override: Interfaz de colisión
|
// Override: Interfaz de colisión
|
||||||
[[nodiscard]] auto getCollisionRadius() const -> float override {
|
[[nodiscard]] auto getCollisionRadius() const -> float override {
|
||||||
@@ -56,7 +56,7 @@ class Enemy : public Entities::Entity {
|
|||||||
// poden abatre i el cos físic rebota amb la nau. El damage a la nau
|
// poden abatre i el cos físic rebota amb la nau. El damage a la nau
|
||||||
// segueix filtrat per `isInvulnerable()` al detectShipEnemy.
|
// segueix filtrat per `isInvulnerable()` al detectShipEnemy.
|
||||||
[[nodiscard]] auto isCollidable() const -> bool override {
|
[[nodiscard]] auto isCollidable() const -> bool override {
|
||||||
return esta_;
|
return is_active_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marcar destruido (desactiva el cuerpo físicamente: radius=0)
|
// Marcar destruido (desactiva el cuerpo físicamente: radius=0)
|
||||||
@@ -80,13 +80,13 @@ class Enemy : public Entities::Entity {
|
|||||||
void setVelocity(float speed);
|
void setVelocity(float speed);
|
||||||
void setRotation(float rot) {
|
void setRotation(float rot) {
|
||||||
rotation_delta_ = rot;
|
rotation_delta_ = rot;
|
||||||
animacio_.rotation_delta_base = rot;
|
animation_.rotation_delta_base = rot;
|
||||||
}
|
}
|
||||||
void setTrackingStrength(float strength);
|
void setTrackingStrength(float strength);
|
||||||
|
|
||||||
// Invulnerabilidad
|
// Invulnerabilidad
|
||||||
[[nodiscard]] auto isInvulnerable() const -> bool { return timer_invulnerabilitat_ > 0.0F; }
|
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerability_timer_ > 0.0F; }
|
||||||
[[nodiscard]] auto getInvulnerabilityTime() const -> float { return timer_invulnerabilitat_; }
|
[[nodiscard]] auto getInvulnerabilityTime() const -> float { return invulnerability_timer_; }
|
||||||
|
|
||||||
// Estado "herido": entre primer impacto de bala y explosión diferida.
|
// Estado "herido": entre primer impacto de bala y explosión diferida.
|
||||||
// shooter_id: id del jugador que herí; 0xFF = sin atribución (cadena, etc.).
|
// shooter_id: id del jugador que herí; 0xFF = sin atribución (cadena, etc.).
|
||||||
@@ -106,10 +106,10 @@ class Enemy : public Entities::Entity {
|
|||||||
// como pentágono", coherente con lo que harán init() o el ctor con renderer al activarlo.
|
// como pentágono", coherente con lo que harán init() o el ctor con renderer al activarlo.
|
||||||
float rotation_delta_{0.0F}; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
float rotation_delta_{0.0F}; // Velocidad angular visual (rad/s) — solo decoración, separada de body_.angular_velocity
|
||||||
float rotation_{0.0F}; // Rotación visual acumulada (no afecta movimiento)
|
float rotation_{0.0F}; // Rotación visual acumulada (no afecta movimiento)
|
||||||
bool esta_{false};
|
bool is_active_{false};
|
||||||
|
|
||||||
EnemyType type_{EnemyType::PENTAGON};
|
EnemyType type_{EnemyType::PENTAGON};
|
||||||
EnemyAnimation animacio_;
|
EnemyAnimation animation_;
|
||||||
|
|
||||||
// Comportamiento type-specific
|
// Comportamiento type-specific
|
||||||
float tracking_timer_{0.0F}; // Quadrat: tiempo desde último update de dirección
|
float tracking_timer_{0.0F}; // Quadrat: tiempo desde último update de dirección
|
||||||
@@ -118,7 +118,7 @@ class Enemy : public Entities::Entity {
|
|||||||
float direction_change_timer_{0.0F}; // Pentagon: tiempo para próximo cambio de dirección
|
float direction_change_timer_{0.0F}; // Pentagon: tiempo para próximo cambio de dirección
|
||||||
|
|
||||||
// Invulnerabilidad post-spawn
|
// Invulnerabilidad post-spawn
|
||||||
float timer_invulnerabilitat_{0.0F};
|
float invulnerability_timer_{0.0F};
|
||||||
|
|
||||||
// Estado "herido": timer cuenta atrás; al cruzar 0 se marca expiración.
|
// Estado "herido": timer cuenta atrás; al cruzar 0 se marca expiración.
|
||||||
float wounded_timer_{0.0F};
|
float wounded_timer_{0.0F};
|
||||||
|
|||||||
Reference in New Issue
Block a user