fix(ship-death): debris hereten inèrcia (captura velocitat abans del markHit) i comparteixen dispersió amb enemics

This commit is contained in:
2026-05-22 22:47:02 +02:00
parent 26bd5a9efa
commit 1ea38d4f6a
+25 -19
View File
@@ -723,30 +723,36 @@ void GameScene::tocado(uint8_t player_id) {
if (hit_timer_per_player_[player_id] == 0.0F) { if (hit_timer_per_player_[player_id] == 0.0F) {
// *** PHASE 1: TRIGGER DEATH *** // *** PHASE 1: TRIGGER DEATH ***
// Capturar velocitat ABANS del markHit (que la reseteja a zero).
// Sense això, els debris no hereten cap inèrcia de la nau.
const Vec2 SHIP_VEL_PRE_DEATH = ships_[player_id].getVelocityVector();
const Vec2 SHIP_POS = ships_[player_id].getCenter();
const float SHIP_ANGLE = ships_[player_id].getAngle();
const float SHIP_BRIGHT = ships_[player_id].getBrightness();
// Mark ship as dead (stops rendering and input) // Mark ship as dead (stops rendering and input)
ships_[player_id].markHit(); ships_[player_id].markHit();
// Create ship explosion const Vec2 INHERITED_VEL = SHIP_VEL_PRE_DEATH *
const Vec2& ship_pos = ships_[player_id].getCenter(); Defaults::Physics::Debris::SHIP_VELOCITY_INHERITANCE;
float ship_angle = ships_[player_id].getAngle();
Vec2 vel_nau = ships_[player_id].getVelocityVector();
// Reduir la velocity heretada per la ship segons defaults (més realista)
constexpr float INHERIT = Defaults::Physics::Debris::SHIP_VELOCITY_INHERITANCE;
Vec2 vel_nau_80 = {.x = vel_nau.x * INHERIT, .y = vel_nau.y * INHERIT};
// Mateixa dispersió i efecte que els debris d'enemic (lifetime,
// friction, segment_multiplier alineats); només canvien sound i color.
debris_manager_.explode( debris_manager_.explode(
ships_[player_id].getShape(), // Ship shape (3 lines) ships_[player_id].getShape(),
ship_pos, // Center position SHIP_POS,
ship_angle, // Ship orientation SHIP_ANGLE,
1.0F, // Normal scale 1.0F,
Defaults::Physics::Debris::VELOCITAT_BASE, // 80 px/s Defaults::Physics::Debris::VELOCITAT_BASE,
ships_[player_id].getBrightness(), // Heredar brightness SHIP_BRIGHT,
vel_nau_80, // Heredar 80% velocity INHERITED_VEL,
0.0F, // Nave: trayectorias rectas (sin drotacio) 0.0F, // sense herència angular
0.0F, // Sin herencia visual (rotación aleatoria) 0.0F, // sin herencia visual
Defaults::Sound::EXPLOSION2, // Sonido alternativo para la explosión Defaults::Sound::EXPLOSION2,
Defaults::Palette::SHIP // Debris hereda color de la nave Defaults::Palette::SHIP,
); Defaults::Physics::Debris::ENEMY_LIFETIME,
Defaults::Physics::Debris::ENEMY_FRICTION,
Defaults::Physics::Debris::ENEMY_SEGMENT_MULTIPLIER);
// Start death timer (non-zero to avoid re-triggering) // Start death timer (non-zero to avoid re-triggering)
hit_timer_per_player_[player_id] = Defaults::Game::HIT_TIMER_TRIGGER_DEATH; hit_timer_per_player_[player_id] = Defaults::Game::HIT_TIMER_TRIGGER_DEATH;