From 92f76d091d574f1378a852c9d856b6a46dd5186f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 28 May 2026 13:13:36 +0200 Subject: [PATCH] =?UTF-8?q?fix(col=C2=B7lisions):=20les=20bales=20d'enemic?= =?UTF-8?q?=20deixen=20de=20comptar=20com=20a=20foc=20amic=20(out-of-bound?= =?UTF-8?q?s=20a=20lives=5Fper=5Fplayer)=20i=20maten=20d'un=20toc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/game/systems/collision_system.cpp | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/source/game/systems/collision_system.cpp b/source/game/systems/collision_system.cpp index 1db2c63..6db6382 100644 --- a/source/game/systems/collision_system.cpp +++ b/source/game/systems/collision_system.cpp @@ -145,6 +145,12 @@ namespace Systems::Collision { continue; } const uint8_t BULLET_OWNER = bullet.getOwnerId(); + // Les bales d'enemic NO són friendly fire: les gestiona + // detectEnemyBulletShip. Sense aquest filtre, owner >= ENEMY_OWNER_BASE + // entraria ací i faria un out-of-bounds a lives_per_player[owner]. + if (BULLET_OWNER >= Defaults::Entities::ENEMY_OWNER_BASE) { + continue; + } for (uint8_t player_id = 0; player_id < 2; player_id++) { // Una bala mai no impacta al seu propi shooter: les bales d'aquest joc no @@ -208,22 +214,11 @@ namespace Systems::Collision { } // *** BALA D'ENEMIC → SHIP *** - // Regla "cos XOR trossos": l'impuls de la bala s'aplica al cos - // només si el ship sobreviu (fereix). Si el ship mor, el bullet - // va directament als trossos (via tocado) i el cos no rep impuls - // — els trossos ja porten la força de la bala, qualsevol impuls - // afegit al cos seria double-count. + // Mata d'un sol toc (decisió de disseny). El bullet va als trossos + // via tocado; el cos no rep impuls (seria double-count amb la + // velocitat que ja hereten els trossos). const Vec2 BULLET_VEL = bullet.getBody().velocity; - if (ctx.ships[player_id].isHurt()) { - // Segon impacte durant HURT → mort. - ctx.on_player_hit(player_id, BULLET_VEL); - } else { - // Fereix: el cos sobreviu, rep l'impuls. No hi ha debris encara. - const Vec2 IMPULSE = BULLET_VEL * - (bullet.getBody().mass * bullet.getConfig().physics.impact_momentum_factor); - ctx.ships[player_id].getBody().applyImpulse(IMPULSE); - ctx.ships[player_id].hurt(); - } + ctx.on_player_hit(player_id, BULLET_VEL); breakBullet(ctx.debris_manager, bullet); break; // una bala impacta una vegada per frame }