|
|
|
|
@@ -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;
|
|
|
|
|
|