refactor(debris): la bala impacta al cos O als trossos, mai a tots dos
This commit is contained in:
@@ -24,10 +24,11 @@ namespace Systems::EnemyEvents {
|
||||
ctx.floating_score_manager.crear(POINTS, enemy.getCenter());
|
||||
}
|
||||
|
||||
void doCreateDebris(Systems::Collision::Context& ctx, const Enemy& enemy) {
|
||||
void doCreateDebris(Systems::Collision::Context& ctx, const Enemy& enemy, const Bullet* bullet) {
|
||||
constexpr float SPEED_EXPLOSIO = 80.0F;
|
||||
const Vec2 INHERITED_VEL = enemy.getVelocityVector() *
|
||||
Defaults::Physics::Debris::ENEMY_VELOCITY_INHERITANCE;
|
||||
const Vec2 BULLET_VEL = (bullet != nullptr) ? bullet->getBody().velocity : Vec2{};
|
||||
ctx.debris_manager.explode(
|
||||
enemy.getShape(),
|
||||
enemy.getCenter(),
|
||||
@@ -42,7 +43,8 @@ namespace Systems::EnemyEvents {
|
||||
enemy.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_VEL);
|
||||
}
|
||||
|
||||
void doCreateFireworks(Systems::Collision::Context& ctx, const Enemy& enemy) {
|
||||
@@ -67,6 +69,24 @@ namespace Systems::EnemyEvents {
|
||||
|
||||
void dispatchEvent(Systems::Collision::Context& ctx, Enemy& enemy, EnemyEventType event, uint8_t shooter_id, const Bullet* bullet) {
|
||||
const auto& actions = enemy.getConfig().events.getActions(event);
|
||||
|
||||
// Pre-scan: aquest event matarà l'enemic? Si sí, l'impuls de la bala
|
||||
// va directament als debris (via doCreateDebris) i NO s'aplica al cos
|
||||
// — així evitem el "double-count" on els trossos hereten la velocitat
|
||||
// del cos (boostat per la bala) I a més el seu propi impuls de bala.
|
||||
// Regla: el bullet impacta al cos O als trossos, mai a tots dos.
|
||||
bool will_die = false;
|
||||
for (const auto& action : actions) {
|
||||
if (action.type == EnemyActionType::DESTROY) {
|
||||
will_die = true;
|
||||
break;
|
||||
}
|
||||
if (action.type == EnemyActionType::SET_HURT && enemy.isWounded()) {
|
||||
will_die = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& action : actions) {
|
||||
switch (action.type) {
|
||||
case EnemyActionType::SET_HURT:
|
||||
@@ -86,13 +106,15 @@ namespace Systems::EnemyEvents {
|
||||
doAddScore(ctx, enemy, shooter_id);
|
||||
break;
|
||||
case EnemyActionType::CREATE_DEBRIS:
|
||||
doCreateDebris(ctx, enemy);
|
||||
doCreateDebris(ctx, enemy, bullet);
|
||||
break;
|
||||
case EnemyActionType::CREATE_FIREWORKS:
|
||||
doCreateFireworks(ctx, enemy);
|
||||
break;
|
||||
case EnemyActionType::APPLY_IMPULSE:
|
||||
doApplyImpulse(enemy, bullet);
|
||||
if (!will_die) {
|
||||
doApplyImpulse(enemy, bullet);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user