tweak(collision): impuls extra a l'enemic en el moment que mata la nau (factor 0.3·mass·vel)
This commit is contained in:
@@ -18,6 +18,14 @@ namespace Defaults::Physics {
|
|||||||
constexpr float IMPACT_MOMENTUM_FACTOR = 3.0F; // Factor de transferència de moment bala→enemic
|
constexpr float IMPACT_MOMENTUM_FACTOR = 3.0F; // Factor de transferència de moment bala→enemic
|
||||||
} // namespace Bullet
|
} // namespace Bullet
|
||||||
|
|
||||||
|
// Ship → enemy: impuls explícit aplicat a l'enemic en el moment exacte
|
||||||
|
// que la nau mor per col·lisió amb ell (afegit per damunt del rebot
|
||||||
|
// natural de PhysicsWorld, que ja és present però subtil amb la
|
||||||
|
// damping de la nau).
|
||||||
|
namespace Ship {
|
||||||
|
constexpr float DEATH_IMPACT_MOMENTUM_FACTOR = 0.3F;
|
||||||
|
} // namespace Ship
|
||||||
|
|
||||||
// Explosions (debris physics)
|
// Explosions (debris physics)
|
||||||
namespace Debris {
|
namespace Debris {
|
||||||
constexpr float VELOCITAT_BASE = 80.0F; // Velocidad inicial (px/s)
|
constexpr float VELOCITAT_BASE = 80.0F; // Velocidad inicial (px/s)
|
||||||
|
|||||||
@@ -203,24 +203,29 @@ namespace Systems::Collision {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comprovem si la nau toca QUALSEVOL enemic vulnerable aquest frame.
|
// Comprovem si la nau toca QUALSEVOL enemic vulnerable aquest frame.
|
||||||
bool touching_now = false;
|
Enemy* touched_enemy = nullptr;
|
||||||
for (const auto& enemy : ctx.enemies) {
|
for (auto& enemy : ctx.enemies) {
|
||||||
if (enemy.isInvulnerable()) {
|
if (enemy.isInvulnerable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Physics::checkCollision(ctx.ships[i], enemy, AMPLIFIER)) {
|
if (Physics::checkCollision(ctx.ships[i], enemy, AMPLIFIER)) {
|
||||||
touching_now = true;
|
touched_enemy = &enemy;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const bool TOUCHING_NOW = touched_enemy != nullptr;
|
||||||
|
|
||||||
// Edge-trigger: només compta com a impacte la transició no-tocant → tocant.
|
// Edge-trigger: només compta com a impacte la transició no-tocant → tocant.
|
||||||
// Així el contacte continu durant el rebot frame-a-frame no dispara HURT i mort
|
// Així el contacte continu durant el rebot frame-a-frame no dispara HURT i mort
|
||||||
// en frames consecutius.
|
// en frames consecutius.
|
||||||
const bool RISING_EDGE = touching_now && !ctx.ships[i].wasTouchingEnemyPrevFrame();
|
const bool RISING_EDGE = TOUCHING_NOW && !ctx.ships[i].wasTouchingEnemyPrevFrame();
|
||||||
if (RISING_EDGE) {
|
if (RISING_EDGE) {
|
||||||
if (ctx.ships[i].isHurt()) {
|
if (ctx.ships[i].isHurt()) {
|
||||||
// Segon impacte durant HURT → mort definitiva (mateix flux que abans).
|
// Segon impacte durant HURT → mort. Aplica un impuls afegit
|
||||||
|
// perquè l'enemic surti disparat (feedback visible).
|
||||||
|
const Vec2 SHIP_VEL = ctx.ships[i].getVelocityVector();
|
||||||
|
const Vec2 IMPULSE = SHIP_VEL * (Defaults::Ship::MASS * Defaults::Physics::Ship::DEATH_IMPACT_MOMENTUM_FACTOR);
|
||||||
|
touched_enemy->applyImpulse(IMPULSE);
|
||||||
ctx.on_player_hit(i);
|
ctx.on_player_hit(i);
|
||||||
} else {
|
} else {
|
||||||
// Primer impacte → estat HURT (rebot físic ja resolt per PhysicsWorld;
|
// Primer impacte → estat HURT (rebot físic ja resolt per PhysicsWorld;
|
||||||
@@ -228,7 +233,7 @@ namespace Systems::Collision {
|
|||||||
ctx.ships[i].herir();
|
ctx.ships[i].herir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.ships[i].setTouchingEnemyPrevFrame(touching_now);
|
ctx.ships[i].setTouchingEnemyPrevFrame(TOUCHING_NOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user