game: clang-tidy readability-function-cognitive-complexity
This commit is contained in:
@@ -495,64 +495,96 @@ void Game::checkPlayerItemCollision(std::shared_ptr<Player> &player) {
|
||||
// Comprueba y procesa la colisión de las balas
|
||||
void Game::checkBulletCollision() {
|
||||
for (auto &bullet : bullets_) {
|
||||
// Comprueba la colisión con el Tabe
|
||||
if (bullet->isEnabled() && tabe_->isEnabled()) {
|
||||
if (checkCollision(bullet->getCollider(), tabe_->getCollider())) {
|
||||
tabe_->setState(TabeState::HIT);
|
||||
bullet->disable();
|
||||
auto pos = tabe_->getCollider();
|
||||
if (tabe_->tryToGetBonus()) {
|
||||
createItem(ItemType::DEBIAN, pos.x, pos.y);
|
||||
playSound("debian_drop.wav");
|
||||
} else {
|
||||
if (rand() % 3 == 0) {
|
||||
createItem(ItemType::COFFEE, pos.x, pos.y);
|
||||
}
|
||||
playSound("tabe_hit.wav");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!bullet->isEnabled()) continue;
|
||||
|
||||
if (checkBulletTabeCollision(bullet)) {
|
||||
break; // Exit early if bullet hit Tabe
|
||||
}
|
||||
|
||||
// Comprueba la colisión con los globos
|
||||
for (auto &balloon : balloon_manager_->getBalloons()) {
|
||||
if (balloon->isEnabled() && (!balloon->isInvulnerable()) && bullet->isEnabled()) {
|
||||
if (checkCollision(balloon->getCollider(), bullet->getCollider())) {
|
||||
// Obtiene al jugador que disparó la bala
|
||||
auto player = getPlayer(bullet->getOwner());
|
||||
|
||||
// Suelta el item si se da el caso
|
||||
const auto DROPPED_ITEM = dropItem();
|
||||
if (DROPPED_ITEM != ItemType::NONE && !demo_.recording) {
|
||||
if (DROPPED_ITEM != ItemType::COFFEE_MACHINE) {
|
||||
createItem(DROPPED_ITEM, balloon->getPosX(), balloon->getPosY());
|
||||
} else {
|
||||
createItem(DROPPED_ITEM, player->getPosX(), param.game.game_area.rect.y - Item::COFFEE_MACHINE_HEIGHT);
|
||||
coffee_machine_enabled_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Explota el globo
|
||||
const auto SCORE = balloon_manager_->popBalloon(balloon);
|
||||
evaluateAndSetMenace();
|
||||
|
||||
// Otorga los puntos al jugador que disparó la bala
|
||||
if (player->isPlaying()) {
|
||||
player->addScore(SCORE * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||
player->incScoreMultiplier();
|
||||
}
|
||||
updateHiScore();
|
||||
|
||||
// Deshabilita la bala
|
||||
bullet->disable();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (checkBulletBalloonCollision(bullet)) {
|
||||
break; // Exit early if bullet hit balloon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja la colisión entre bala y Tabe
|
||||
bool Game::checkBulletTabeCollision(std::shared_ptr<Bullet> bullet) {
|
||||
if (!tabe_->isEnabled()) return false;
|
||||
|
||||
if (!checkCollision(bullet->getCollider(), tabe_->getCollider())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tabe_->setState(TabeState::HIT);
|
||||
bullet->disable();
|
||||
|
||||
handleTabeHitEffects();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Maneja los efectos de golpear al Tabe
|
||||
void Game::handleTabeHitEffects() {
|
||||
auto pos = tabe_->getCollider();
|
||||
|
||||
if (tabe_->tryToGetBonus()) {
|
||||
createItem(ItemType::DEBIAN, pos.x, pos.y);
|
||||
playSound("debian_drop.wav");
|
||||
} else {
|
||||
if (rand() % 3 == 0) {
|
||||
createItem(ItemType::COFFEE, pos.x, pos.y);
|
||||
}
|
||||
playSound("tabe_hit.wav");
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja la colisión entre bala y globos
|
||||
bool Game::checkBulletBalloonCollision(std::shared_ptr<Bullet> bullet) {
|
||||
for (auto &balloon : balloon_manager_->getBalloons()) {
|
||||
if (!balloon->isEnabled() || balloon->isInvulnerable()) continue;
|
||||
|
||||
if (!checkCollision(balloon->getCollider(), bullet->getCollider())) continue;
|
||||
|
||||
processBalloonHit(bullet, balloon);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Procesa el impacto en un globo
|
||||
void Game::processBalloonHit(std::shared_ptr<Bullet> bullet, std::shared_ptr<Balloon> balloon) {
|
||||
auto player = getPlayer(bullet->getOwner());
|
||||
|
||||
handleItemDrop(balloon, player);
|
||||
handleBalloonDestruction(balloon, player);
|
||||
|
||||
bullet->disable();
|
||||
}
|
||||
|
||||
// Maneja la caída de items cuando se destruye un globo
|
||||
void Game::handleItemDrop(std::shared_ptr<Balloon> balloon, std::shared_ptr<Player> player) {
|
||||
const auto DROPPED_ITEM = dropItem();
|
||||
if (DROPPED_ITEM == ItemType::NONE || demo_.recording) return;
|
||||
|
||||
if (DROPPED_ITEM != ItemType::COFFEE_MACHINE) {
|
||||
createItem(DROPPED_ITEM, balloon->getPosX(), balloon->getPosY());
|
||||
} else {
|
||||
createItem(DROPPED_ITEM, player->getPosX(), param.game.game_area.rect.y - Item::COFFEE_MACHINE_HEIGHT);
|
||||
coffee_machine_enabled_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Maneja la destrucción del globo y puntuación
|
||||
void Game::handleBalloonDestruction(std::shared_ptr<Balloon> balloon, std::shared_ptr<Player> player) {
|
||||
const auto SCORE = balloon_manager_->popBalloon(balloon);
|
||||
evaluateAndSetMenace();
|
||||
|
||||
if (player->isPlaying()) {
|
||||
player->addScore(SCORE * player->getScoreMultiplier() * difficulty_score_multiplier_);
|
||||
player->incScoreMultiplier();
|
||||
}
|
||||
updateHiScore();
|
||||
}
|
||||
|
||||
// Mueve las balas activas
|
||||
void Game::updateBullets() {
|
||||
for (auto &bullet : bullets_) {
|
||||
@@ -571,7 +603,7 @@ void Game::renderBullets() {
|
||||
|
||||
// Crea un objeto bala
|
||||
void Game::createBullet(int x, int y, BulletType kind, bool powered_up, int owner) {
|
||||
bullets_.emplace_back(std::make_unique<Bullet>(x, y, kind, powered_up, owner));
|
||||
bullets_.emplace_back(std::make_shared<Bullet>(x, y, kind, powered_up, owner));
|
||||
}
|
||||
|
||||
// Vacia el vector de balas
|
||||
|
||||
Reference in New Issue
Block a user