refactor(debris): la bala impacta al cos O als trossos, mai a tots dos

This commit is contained in:
2026-05-25 21:26:32 +02:00
parent b511740d93
commit 610eaf257e
8 changed files with 87 additions and 32 deletions
+7 -3
View File
@@ -580,7 +580,7 @@ auto GameScene::buildCollisionContext() -> Systems::Collision::Context {
.firework_manager = firework_manager_,
.floating_score_manager = floating_score_manager_,
.match_config = match_config_,
.on_player_hit = [this](uint8_t pid) { tocado(pid); },
.on_player_hit = [this](uint8_t pid, const Vec2& bv) { tocado(pid, bv); },
};
}
@@ -764,7 +764,7 @@ void GameScene::drawLevelCompletedState() {
drawScoreboard();
}
void GameScene::tocado(uint8_t player_id) {
void GameScene::tocado(uint8_t player_id, const Vec2& bullet_velocity) {
// Death sequence: 3 phases
// Phase 1: First call (hit_timer_per_player_[player_id] == 0) - trigger explosion
// Phase 2: Animation (0 < itocado_ < 3.0s) - debris animation
@@ -788,6 +788,9 @@ void GameScene::tocado(uint8_t player_id) {
// Mateixa dispersió i efecte que els debris d'enemic (lifetime,
// friction, segment_multiplier alineats); només canvien sound i color.
// bullet_velocity arriba a explode() com a impuls extra independent
// de la inèrcia del cos del ship — els trossos volen amb la força
// de la bala encara que el ship estiga quiet.
debris_manager_.explode(
ships_[player_id].getShape(),
SHIP_POS,
@@ -802,7 +805,8 @@ void GameScene::tocado(uint8_t player_id) {
ships_[player_id].getConfig().colors.normal,
Defaults::Physics::Debris::ENEMY_LIFETIME,
Defaults::Physics::Debris::ENEMY_FRICTION,
Defaults::Physics::Debris::ENEMY_SEGMENT_MULTIPLIER);
Defaults::Physics::Debris::ENEMY_SEGMENT_MULTIPLIER,
bullet_velocity);
// Start death timer (non-zero to avoid re-triggering)
hit_timer_per_player_[player_id] = Defaults::Game::HIT_TIMER_TRIGGER_DEATH;
+4 -1
View File
@@ -101,7 +101,10 @@ class GameScene final : public Scene {
bool init_hud_rect_sound_played_{false}; // Flag para evitar repetir sonido del rectángulo
// Funciones privades
void tocado(uint8_t player_id);
// bullet_velocity: velocitat de la bala que ha causat la mort (Vec2{} si no
// ve d'una bala). Es passa al debris perquè els fragments volin en direcció
// de la bala (independent de la inèrcia del cos del ship).
void tocado(uint8_t player_id, const Vec2& bullet_velocity = {.x = 0.0F, .y = 0.0F});
void drawScoreboard(); // Dibuixar marcador de puntuación
void fireBullet(uint8_t player_id); // Shoot bullet from player
[[nodiscard]] auto getSpawnPoint(uint8_t player_id) const -> Vec2; // Get spawn position for player