tweak(collision): impuls extra a l'enemic en el moment que mata la nau (factor 0.3·mass·vel)
This commit is contained in:
@@ -203,24 +203,29 @@ namespace Systems::Collision {
|
||||
}
|
||||
|
||||
// Comprovem si la nau toca QUALSEVOL enemic vulnerable aquest frame.
|
||||
bool touching_now = false;
|
||||
for (const auto& enemy : ctx.enemies) {
|
||||
Enemy* touched_enemy = nullptr;
|
||||
for (auto& enemy : ctx.enemies) {
|
||||
if (enemy.isInvulnerable()) {
|
||||
continue;
|
||||
}
|
||||
if (Physics::checkCollision(ctx.ships[i], enemy, AMPLIFIER)) {
|
||||
touching_now = true;
|
||||
touched_enemy = &enemy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const bool TOUCHING_NOW = touched_enemy != nullptr;
|
||||
|
||||
// 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
|
||||
// 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 (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);
|
||||
} else {
|
||||
// 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].setTouchingEnemyPrevFrame(touching_now);
|
||||
ctx.ships[i].setTouchingEnemyPrevFrame(TOUCHING_NOW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user