From dc2824a095266b8ec4a8da89e47010e51d96ddcf Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 21 May 2026 10:22:25 +0200 Subject: [PATCH] feat(collision): la bala transmet impulse mass-aware al enemic (Fase 2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Defaults::Physics::Bullet::IMPACT_IMPULSE (50 px·s placeholder) - detectBulletEnemy: calcula normal bullet→enemy, normalitza (fallback a direcció de bala o (0,-1) si estan solapats) i crida enemy.applyImpulse(normal * IMPACT_IMPULSE) abans de destruir. El destruir() immediat encara zera la velocity, així que l'efecte visual no es nota: serà visible quan la Fase 3 difereixi la mort. Co-Authored-By: Claude Opus 4.7 (1M context) --- source/core/defaults/physics.hpp | 5 +++++ source/game/systems/collision_system.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/source/core/defaults/physics.hpp b/source/core/defaults/physics.hpp index 7a204ba..218cdba 100644 --- a/source/core/defaults/physics.hpp +++ b/source/core/defaults/physics.hpp @@ -10,6 +10,11 @@ namespace Defaults::Physics { constexpr float MAX_VELOCITY = 120.0F; // px/s constexpr float FRICTION = 20.0F; // px/s² + // Bullet — impacto físico contra enemigo (impulse mass-aware). + namespace Bullet { + constexpr float IMPACT_IMPULSE = 50.0F; // Magnitud del impulse en la dirección bullet→enemy + } // namespace Bullet + // Explosions (debris physics) namespace Debris { constexpr float VELOCITAT_BASE = 80.0F; // Velocidad inicial (px/s) diff --git a/source/game/systems/collision_system.cpp b/source/game/systems/collision_system.cpp index ff1f6f9..f610d4c 100644 --- a/source/game/systems/collision_system.cpp +++ b/source/game/systems/collision_system.cpp @@ -23,6 +23,17 @@ namespace Systems::Collision { // *** COLISIÓN bullet → enemy *** const Vec2& enemy_pos = enemy.getCenter(); + // Empuje físico: impulse en la dirección bullet→enemy (fallback a la + // dirección de la bala si están exactamente solapados). + Vec2 normal = enemy_pos - bullet.getCenter(); + if (normal.lengthSquared() > 0.000001F) { + normal = normal.normalized(); + } else { + const Vec2 BVEL = bullet.getBody().velocity; + normal = (BVEL.lengthSquared() > 0.0F) ? BVEL.normalized() : Vec2{.x = 0.0F, .y = -1.0F}; + } + enemy.applyImpulse(normal * Defaults::Physics::Bullet::IMPACT_IMPULSE); + // 1. Puntos según tipo int points = 0; switch (enemy.getType()) {