feat(bullet): debris en trencar-se amb so HIT mogut des d'enemy.herir()

This commit is contained in:
2026-05-22 18:42:23 +02:00
parent bf79eecca0
commit 18e05e36e6
5 changed files with 69 additions and 27 deletions
+48 -2
View File
@@ -7,6 +7,7 @@
#include "core/audio/audio.hpp"
#include "core/physics/collision.hpp"
#include "core/types.hpp"
#include "game/constants.hpp"
namespace Systems::Collision {
@@ -81,6 +82,29 @@ namespace Systems::Collision {
// No heretem color: el burst usa el blanc per defecte per a un feel més lluminós.
ctx.firework_manager.spawn(ENEMY_POS);
}
// Trenca una bala en debris (8 fragments de l'octàgon) + so HIT + desactiva.
// S'invoca des de qualsevol desactivació de bala (impacte amb enemic, amb jugador,
// o sortida del PLAYAREA) per a un feedback visual i sonor consistent.
void breakBullet(Effects::DebrisManager& debris_manager, Bullet& bullet) {
constexpr float DEBRIS_VELOCITY = 60.0F;
debris_manager.explode(
bullet.getShape(),
bullet.getCenter(),
bullet.getAngle(),
1.0F, // scale
DEBRIS_VELOCITY,
bullet.getBrightness(),
Vec2{}, // sense herència de velocitat (fragments radials)
0.0F, // sense velocity angular heretada
0.0F, // sense rotació visual heretada
Defaults::Sound::HIT,
Defaults::Palette::BULLET,
Defaults::Physics::Debris::TEMPS_VIDA,
Defaults::Physics::Debris::ACCELERACIO,
1); // sense duplicat de segments
bullet.desactivar();
}
} // anonymous namespace
void detectBulletEnemy(Context& ctx) {
@@ -114,7 +138,7 @@ namespace Systems::Collision {
enemy.herir(SHOOTER);
}
bullet.desactivar();
breakBullet(ctx.debris_manager, bullet);
break; // Una bala impacta a un enemy y muere
}
}
@@ -242,7 +266,7 @@ namespace Systems::Collision {
ctx.on_player_hit(player_id);
ctx.lives_per_player[BULLET_OWNER]++;
Audio::get()->playSound(Defaults::Sound::FRIENDLY_FIRE_HIT, Audio::Group::GAME);
bullet.desactivar();
breakBullet(ctx.debris_manager, bullet);
break; // Una bullet solo impacta una vez por frame
}
}
@@ -256,4 +280,26 @@ namespace Systems::Collision {
detectBulletPlayer(ctx);
}
void desactivateOutOfBoundsBullets(
std::array<Bullet, static_cast<std::size_t>(Defaults::Entities::MAX_BALES) * 2>& bullets,
Effects::DebrisManager& debris_manager) {
float min_x;
float max_x;
float min_y;
float max_y;
Constants::getPlayAreaBounds(min_x, max_x, min_y, max_y);
constexpr float R = Defaults::Entities::BULLET_RADIUS;
for (auto& bullet : bullets) {
if (!bullet.isActive()) {
continue;
}
const Vec2& pos = bullet.getCenter();
if (pos.x < min_x + R || pos.x > max_x - R ||
pos.y < min_y + R || pos.y > max_y - R) {
breakBullet(debris_manager, bullet);
}
}
}
} // namespace Systems::Collision