refactor: consolidar Ship::isAlive/isHit/isActive en isActive()
Els tres mètodes retornaven el mateix bool a partir d'is_hit_: isActive() = !is_hit_ (override de Entity) isAlive() = !is_hit_ isHit() = is_hit_ Eren tres formes diferents de preguntar el mateix, repartides sense criteri pels call-sites (collision_system, game_scene). Conservem isActive() perquè és l'override polimòrfic d'Entity i esborrem els altres dos. Actualitzats els 5 call-sites externs. Hallazgo #11 de CODE_REVIEW.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,9 +34,7 @@ class Ship : public Entities::Entity {
|
|||||||
return !is_hit_ && invulnerable_timer_ <= 0.0F;
|
return !is_hit_ && invulnerable_timer_ <= 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters (API pública sin cambios)
|
// Getters
|
||||||
[[nodiscard]] auto isAlive() const -> bool { return !is_hit_; }
|
|
||||||
[[nodiscard]] auto isHit() const -> bool { return is_hit_; }
|
|
||||||
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_timer_ > 0.0F; }
|
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_timer_ > 0.0F; }
|
||||||
// Velocidad como vector cartesiano (ahora viene directa del body_).
|
// Velocidad como vector cartesiano (ahora viene directa del body_).
|
||||||
[[nodiscard]] auto getVelocityVector() const -> Vec2 { return body_.velocity; }
|
[[nodiscard]] auto getVelocityVector() const -> Vec2 { return body_.velocity; }
|
||||||
|
|||||||
@@ -573,11 +573,11 @@ void GameScene::drawInitHudState() {
|
|||||||
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) {
|
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && ships_[0].isActive()) {
|
||||||
ships_[0].draw();
|
ships_[0].draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) {
|
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && ships_[1].isActive()) {
|
||||||
ships_[1].draw();
|
ships_[1].draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -820,7 +820,7 @@ void GameScene::fireBullet(uint8_t player_id) {
|
|||||||
if (hit_timer_per_player_[player_id] > 0.0F) {
|
if (hit_timer_per_player_[player_id] > 0.0F) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!ships_[player_id].isAlive()) {
|
if (!ships_[player_id].isActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Systems::Collision {
|
namespace Systems::Collision {
|
||||||
|
|
||||||
void detectBulletEnemy(Context& ctx) {
|
void detectBulletEnemy(Context& ctx) {
|
||||||
constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_ENEMY_AMPLIFIER;
|
constexpr float AMPLIFIER = Defaults::Game::COLLISION_BULLET_ENEMY_AMPLIFIER;
|
||||||
constexpr float VELOCITAT_EXPLOSIO = 80.0F; // px/s (explosión suau)
|
constexpr float VELOCITAT_EXPLOSIO = 80.0F; // px/s (explosión suau)
|
||||||
|
|
||||||
@@ -44,9 +44,15 @@ void detectBulletEnemy(Context& ctx) {
|
|||||||
// 2. Destruir enemy + crear explosión (debris hereda color del enemy)
|
// 2. Destruir enemy + crear explosión (debris hereda color del enemy)
|
||||||
SDL_Color enemy_color{};
|
SDL_Color enemy_color{};
|
||||||
switch (enemy.getType()) {
|
switch (enemy.getType()) {
|
||||||
case EnemyType::PENTAGON: enemy_color = Defaults::Palette::PENTAGON; break;
|
case EnemyType::PENTAGON:
|
||||||
case EnemyType::QUADRAT: enemy_color = Defaults::Palette::QUADRAT; break;
|
enemy_color = Defaults::Palette::PENTAGON;
|
||||||
case EnemyType::MOLINILLO: enemy_color = Defaults::Palette::MOLINILLO; break;
|
break;
|
||||||
|
case EnemyType::QUADRAT:
|
||||||
|
enemy_color = Defaults::Palette::QUADRAT;
|
||||||
|
break;
|
||||||
|
case EnemyType::MOLINILLO:
|
||||||
|
enemy_color = Defaults::Palette::MOLINILLO;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
enemy.destruir();
|
enemy.destruir();
|
||||||
Vec2 vel_enemic = enemy.getVelocityVector();
|
Vec2 vel_enemic = enemy.getVelocityVector();
|
||||||
@@ -61,23 +67,22 @@ void detectBulletEnemy(Context& ctx) {
|
|||||||
enemy.getRotationDelta(),
|
enemy.getRotationDelta(),
|
||||||
0.0F, // sin herencia visual
|
0.0F, // sin herencia visual
|
||||||
Defaults::Sound::EXPLOSION,
|
Defaults::Sound::EXPLOSION,
|
||||||
enemy_color
|
enemy_color);
|
||||||
);
|
|
||||||
|
|
||||||
// 3. Desactivar bullet (solo destruye 1 enemy)
|
// 3. Desactivar bullet (solo destruye 1 enemy)
|
||||||
bullet.desactivar();
|
bullet.desactivar();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void detectShipEnemy(Context& ctx) {
|
void detectShipEnemy(Context& ctx) {
|
||||||
constexpr float AMPLIFIER = Defaults::Game::COLLISION_SHIP_ENEMY_AMPLIFIER;
|
constexpr float AMPLIFIER = Defaults::Game::COLLISION_SHIP_ENEMY_AMPLIFIER;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
// Skip si ya tocado / muerto / invulnerable
|
// Skip si ya tocado / muerto / invulnerable
|
||||||
if (ctx.hit_timer_per_player[i] > 0.0F ||
|
if (ctx.hit_timer_per_player[i] > 0.0F ||
|
||||||
!ctx.ships[i].isAlive() ||
|
!ctx.ships[i].isActive() ||
|
||||||
ctx.ships[i].isInvulnerable()) {
|
ctx.ships[i].isInvulnerable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -92,9 +97,9 @@ void detectShipEnemy(Context& ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void detectBulletPlayer(Context& ctx) {
|
void detectBulletPlayer(Context& ctx) {
|
||||||
if (!Defaults::Game::FRIENDLY_FIRE_ENABLED) {
|
if (!Defaults::Game::FRIENDLY_FIRE_ENABLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -109,7 +114,7 @@ void detectBulletPlayer(Context& ctx) {
|
|||||||
|
|
||||||
for (uint8_t player_id = 0; player_id < 2; player_id++) {
|
for (uint8_t player_id = 0; player_id < 2; player_id++) {
|
||||||
if (ctx.hit_timer_per_player[player_id] > 0.0F ||
|
if (ctx.hit_timer_per_player[player_id] > 0.0F ||
|
||||||
!ctx.ships[player_id].isAlive() ||
|
!ctx.ships[player_id].isActive() ||
|
||||||
ctx.ships[player_id].isInvulnerable()) {
|
ctx.ships[player_id].isInvulnerable()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -139,12 +144,12 @@ void detectBulletPlayer(Context& ctx) {
|
|||||||
break; // Una bullet solo impacta una vez por frame
|
break; // Una bullet solo impacta una vez por frame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void detectAll(Context& ctx) {
|
void detectAll(Context& ctx) {
|
||||||
detectBulletEnemy(ctx);
|
detectBulletEnemy(ctx);
|
||||||
detectShipEnemy(ctx);
|
detectShipEnemy(ctx);
|
||||||
detectBulletPlayer(ctx);
|
detectBulletPlayer(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Systems::Collision
|
} // namespace Systems::Collision
|
||||||
|
|||||||
Reference in New Issue
Block a user