fix(bullet): col·lisió swept, sense grace_timer, mor al border visual
This commit is contained in:
@@ -87,8 +87,11 @@ namespace Systems::Collision {
|
||||
constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_ENEMY_AMPLIFIER;
|
||||
|
||||
for (auto& bullet : ctx.bullets) {
|
||||
if (!bullet.isActive()) {
|
||||
continue;
|
||||
}
|
||||
for (auto& enemy : ctx.enemies) {
|
||||
if (!Physics::checkCollision(bullet, enemy, AMPLIFIER)) {
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), Defaults::Entities::BULLET_RADIUS, enemy, AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -207,12 +210,17 @@ namespace Systems::Collision {
|
||||
constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_PLAYER_AMPLIFIER;
|
||||
|
||||
for (auto& bullet : ctx.bullets) {
|
||||
if (!bullet.isActive() || bullet.getGraceTimer() > 0.0F) {
|
||||
if (!bullet.isActive()) {
|
||||
continue;
|
||||
}
|
||||
const uint8_t BULLET_OWNER = bullet.getOwnerId();
|
||||
|
||||
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
|
||||
// reboten ni el shooter pot atrapar-les, així que la prevenció és per disseny.
|
||||
if (BULLET_OWNER == player_id) {
|
||||
continue;
|
||||
}
|
||||
if (ctx.hit_timer_per_player[player_id] > 0.0F ||
|
||||
!ctx.ships[player_id].isActive() ||
|
||||
ctx.ships[player_id].isInvulnerable()) {
|
||||
@@ -225,20 +233,14 @@ namespace Systems::Collision {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Physics::checkCollision(bullet, ctx.ships[player_id], AMPLIFIER)) {
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), Defaults::Entities::BULLET_RADIUS, ctx.ships[player_id], AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// *** FRIENDLY FIRE HIT ***
|
||||
if (BULLET_OWNER == player_id) {
|
||||
// Self-hit: víctima pierde 1 vida.
|
||||
ctx.on_player_hit(player_id);
|
||||
} else {
|
||||
// Teammate hit: víctima pierde 1, atacante gana 1.
|
||||
ctx.on_player_hit(player_id);
|
||||
ctx.lives_per_player[BULLET_OWNER]++;
|
||||
}
|
||||
|
||||
// *** TEAMMATE HIT (friendly fire) ***
|
||||
// Víctima perd 1 vida, atacant en guanya 1.
|
||||
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();
|
||||
break; // Una bullet solo impacta una vez por frame
|
||||
|
||||
Reference in New Issue
Block a user