pasaeta loca de clang-format (despres m'arrepentiré pero bueno)

This commit is contained in:
2025-07-18 20:01:13 +02:00
parent 734c220fb0
commit dabba41179
112 changed files with 22361 additions and 26474 deletions

View File

@@ -1,17 +1,18 @@
#include "balloon_manager.h"
#include <stdlib.h> // Para rand
#include <algorithm> // Para remove_if
#include <numeric> // Para accumulate
#include <stdlib.h> // Para rand
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
#include "explosions.h" // Para Explosions
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "stage.h" // Para addPower
#include "utils.h" // Para Zone, Color, flash_color
#include <algorithm> // Para remove_if
#include <numeric> // Para accumulate
#include "balloon.h" // Para Balloon, BALLOON_SCORE, BALLOON_VELX...
#include "balloon_formations.h" // Para BalloonFormationParams, BalloonForma...
#include "explosions.h" // Para Explosions
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "stage.h" // Para addPower
#include "utils.h" // Para Zone, Color, flash_color
// Constructor
BalloonManager::BalloonManager()
@@ -19,8 +20,7 @@ BalloonManager::BalloonManager()
balloon_formations_(std::make_unique<BalloonFormations>()) { init(); }
// Inicializa
void BalloonManager::init()
{
void BalloonManager::init() {
// Texturas - Globos
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon1.png"));
balloon_textures_.emplace_back(Resource::get()->getTexture("balloon2.png"));
@@ -55,10 +55,8 @@ void BalloonManager::init()
}
// Actualiza
void BalloonManager::update()
{
for (auto balloon : balloons_)
{
void BalloonManager::update() {
for (auto balloon : balloons_) {
balloon->update();
}
updateBalloonDeployCounter();
@@ -66,32 +64,25 @@ void BalloonManager::update()
}
// Renderiza los objetos
void BalloonManager::render()
{
for (auto &balloon : balloons_)
{
void BalloonManager::render() {
for (auto &balloon : balloons_) {
balloon->render();
}
explosions_->render();
}
// Crea una formación de enemigos
void BalloonManager::deployBalloonFormation(int stage)
{
void BalloonManager::deployBalloonFormation(int stage) {
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
if (balloon_deploy_counter_ == 0)
{
if (balloon_deploy_counter_ == 0) {
// En este punto se decide entre crear una powerball o una formación enemiga
if ((rand() % 100 < 15) && (canPowerBallBeCreated()))
{
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
// Crea una powerball
createPowerBall();
// Da un poco de margen para que se creen mas enemigos
balloon_deploy_counter_ = 10;
}
else
{
} else {
// Decrementa el contador de despliegues enemigos de la PowerBall
power_ball_counter_ = (power_ball_counter_ > 0) ? (power_ball_counter_ - 1) : 0;
@@ -99,8 +90,7 @@ void BalloonManager::deployBalloonFormation(int stage)
auto formation = rand() % 10;
// Evita repetir la ultima formación enemiga desplegada
if (formation == last_balloon_deploy_)
{
if (formation == last_balloon_deploy_) {
++formation %= 10;
}
@@ -108,8 +98,7 @@ void BalloonManager::deployBalloonFormation(int stage)
const auto set = balloon_formations_->getSet(stage, formation);
const auto num_enemies = set.number_of_balloons;
for (int i = 0; i < num_enemies; ++i)
{
for (int i = 0; i < num_enemies; ++i) {
auto p = set.init[i];
createBalloon(
p.x,
@@ -127,42 +116,34 @@ void BalloonManager::deployBalloonFormation(int stage)
}
// Crea una formación de enemigos específica
void BalloonManager::deploySet(int set_number)
{
void BalloonManager::deploySet(int set_number) {
const auto set = balloon_formations_->getSet(set_number);
const auto num_enemies = set.number_of_balloons;
for (int i = 0; i < num_enemies; ++i)
{
for (int i = 0; i < num_enemies; ++i) {
auto p = set.init[i];
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
}
}
// Crea una formación de enemigos específica
void BalloonManager::deploySet(int set_number, int y)
{
void BalloonManager::deploySet(int set_number, int y) {
const auto set = balloon_formations_->getSet(set_number);
const auto num_enemies = set.number_of_balloons;
for (int i = 0; i < num_enemies; ++i)
{
for (int i = 0; i < num_enemies; ++i) {
auto p = set.init[i];
createBalloon(p.x, y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
}
}
// Vacia del vector de globos los globos que ya no sirven
void BalloonManager::freeBalloons()
{
auto it = std::remove_if(balloons_.begin(), balloons_.end(), [](const auto &balloon)
{ return !balloon->isEnabled(); });
void BalloonManager::freeBalloons() {
auto it = std::remove_if(balloons_.begin(), balloons_.end(), [](const auto &balloon) { return !balloon->isEnabled(); });
balloons_.erase(it, balloons_.end());
}
// Actualiza la variable enemyDeployCounter
void BalloonManager::updateBalloonDeployCounter()
{
if (balloon_deploy_counter_ > 0)
{
void BalloonManager::updateBalloonDeployCounter() {
if (balloon_deploy_counter_ > 0) {
--balloon_deploy_counter_;
}
}
@@ -171,17 +152,13 @@ void BalloonManager::updateBalloonDeployCounter()
bool BalloonManager::canPowerBallBeCreated() { return (!power_ball_enabled_) && (calculateScreenPower() > POWERBALL_SCREENPOWER_MINIMUM) && (power_ball_counter_ == 0); }
// Calcula el poder actual de los globos en pantalla
int BalloonManager::calculateScreenPower()
{
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
{ return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
int BalloonManager::calculateScreenPower() {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getPower() : 0); });
}
// Crea un globo nuevo en el vector de globos
std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer)
{
if (can_deploy_balloons_)
{
std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonType type, BalloonSize size, float velx, float speed, int creation_timer) {
if (can_deploy_balloons_) {
const int INDEX = static_cast<int>(size);
balloons_.emplace_back(std::make_shared<Balloon>(x, y, type, size, velx, speed, creation_timer, play_area_, balloon_textures_.at(INDEX), balloon_animations_.at(INDEX)));
balloons_.back()->setSound(sound_enabled_);
@@ -194,10 +171,8 @@ std::shared_ptr<Balloon> BalloonManager::createBalloon(float x, int y, BalloonTy
}
// Crea un globo a partir de otro globo
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction)
{
if (can_deploy_balloons_)
{
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction) {
if (can_deploy_balloons_) {
// Calcula parametros
const float VX = direction == "LEFT" ? BALLOON_VELX_NEGATIVE : BALLOON_VELX_POSITIVE;
const auto SIZE = static_cast<BalloonSize>(static_cast<int>(balloon->getSize()) - 1);
@@ -214,22 +189,18 @@ void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon> &balloon,
b->setVelY(b->getType() == BalloonType::BALLOON ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
// Herencia de estados
if (balloon->isStopped())
{
if (balloon->isStopped()) {
b->stop();
}
if (balloon->isUsingReversedColor())
{
if (balloon->isUsingReversedColor()) {
b->useReverseColor();
}
}
}
// Crea una PowerBall
void BalloonManager::createPowerBall()
{
if (can_deploy_balloons_)
{
void BalloonManager::createPowerBall() {
if (can_deploy_balloons_) {
constexpr int VALUES = 6;
constexpr float POS_Y = -BALLOON_SIZE[4];
constexpr int CREATION_TIME = 0;
@@ -251,33 +222,26 @@ void BalloonManager::createPowerBall()
}
// Establece la velocidad de los globos
void BalloonManager::setBalloonSpeed(float speed)
{
void BalloonManager::setBalloonSpeed(float speed) {
balloon_speed_ = speed;
for (auto &balloon : balloons_)
{
for (auto &balloon : balloons_) {
balloon->setSpeed(speed);
}
}
// Explosiona un globo. Lo destruye y crea otros dos si es el caso
int BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
{
int BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon) {
Stage::addPower(1);
int score = 0;
if (balloon->getType() == BalloonType::POWERBALL)
{
if (balloon->getType() == BalloonType::POWERBALL) {
balloon->pop(true);
score = destroyAllBalloons();
power_ball_enabled_ = false;
balloon_deploy_counter_ = 20;
}
else
{
} else {
score = balloon->getScore();
if (balloon->getSize() != BalloonSize::SIZE1)
{
if (balloon->getSize() != BalloonSize::SIZE1) {
createChildBalloon(balloon, "LEFT");
createChildBalloon(balloon, "RIGHT");
}
@@ -291,28 +255,26 @@ int BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
}
// Explosiona un globo. Lo destruye = no crea otros globos
int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
{
int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon) {
int score = 0;
// Calcula la puntuación y el poder que generaria el globo en caso de romperlo a él y a sus hijos
switch (balloon->getSize())
{
case BalloonSize::SIZE4:
score = BALLOON_SCORE[3] + (2 * BALLOON_SCORE[2]) + (4 * BALLOON_SCORE[1]) + (8 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE3:
score = BALLOON_SCORE[2] + (2 * BALLOON_SCORE[1]) + (4 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE2:
score = BALLOON_SCORE[1] + (2 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE1:
score = BALLOON_SCORE[0];
break;
default:
score = 0;
break;
switch (balloon->getSize()) {
case BalloonSize::SIZE4:
score = BALLOON_SCORE[3] + (2 * BALLOON_SCORE[2]) + (4 * BALLOON_SCORE[1]) + (8 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE3:
score = BALLOON_SCORE[2] + (2 * BALLOON_SCORE[1]) + (4 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE2:
score = BALLOON_SCORE[1] + (2 * BALLOON_SCORE[0]);
break;
case BalloonSize::SIZE1:
score = BALLOON_SCORE[0];
break;
default:
score = 0;
break;
}
// Aumenta el poder de la fase
@@ -326,11 +288,9 @@ int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
}
// Destruye todos los globos
int BalloonManager::destroyAllBalloons()
{
int BalloonManager::destroyAllBalloons() {
int score = 0;
for (auto &balloon : balloons_)
{
for (auto &balloon : balloons_) {
score += destroyBalloon(balloon);
}
@@ -342,59 +302,46 @@ int BalloonManager::destroyAllBalloons()
}
// Detiene todos los globos
void BalloonManager::stopAllBalloons()
{
for (auto &balloon : balloons_)
{
void BalloonManager::stopAllBalloons() {
for (auto &balloon : balloons_) {
balloon->stop();
}
}
// Pone en marcha todos los globos
void BalloonManager::startAllBalloons()
{
for (auto &balloon : balloons_)
{
if (!balloon->isBeingCreated())
{
void BalloonManager::startAllBalloons() {
for (auto &balloon : balloons_) {
if (!balloon->isBeingCreated()) {
balloon->start();
}
}
}
// Cambia el color de todos los globos
void BalloonManager::reverseColorsToAllBalloons()
{
for (auto &balloon : balloons_)
{
if (balloon->isStopped())
{
void BalloonManager::reverseColorsToAllBalloons() {
for (auto &balloon : balloons_) {
if (balloon->isStopped()) {
balloon->useReverseColor();
}
}
}
// Cambia el color de todos los globos
void BalloonManager::normalColorsToAllBalloons()
{
for (auto &balloon : balloons_)
{
void BalloonManager::normalColorsToAllBalloons() {
for (auto &balloon : balloons_) {
balloon->useNormalColor();
}
}
// Crea dos globos gordos
void BalloonManager::createTwoBigBalloons()
{
void BalloonManager::createTwoBigBalloons() {
deploySet(1);
}
// Crea una disposición de globos aleatoria
void BalloonManager::createRandomBalloons()
{
void BalloonManager::createRandomBalloons() {
const int num_balloons = 2 + rand() % 4;
for (int i = 0; i < num_balloons; ++i)
{
for (int i = 0; i < num_balloons; ++i) {
const float x = param.game.game_area.rect.x + (rand() % static_cast<int>(param.game.game_area.rect.w)) - BALLOON_SIZE[3];
const int y = param.game.game_area.rect.y + (rand() % 50);
const BalloonSize size = static_cast<BalloonSize>(rand() % 4);
@@ -405,37 +352,29 @@ void BalloonManager::createRandomBalloons()
}
// Obtiene el nivel de ameza actual generado por los globos
int BalloonManager::getMenace()
{
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
int BalloonManager::getMenace() {
return std::accumulate(balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon) { return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
}
// Establece el sonido de los globos
void BalloonManager::setSounds(bool value)
{
void BalloonManager::setSounds(bool value) {
sound_enabled_ = value;
for (auto &balloon : balloons_)
{
for (auto &balloon : balloons_) {
balloon->setSound(value);
}
}
// Activa o desactiva los sonidos de rebote los globos
void BalloonManager::setBouncingSounds(bool value)
{
void BalloonManager::setBouncingSounds(bool value) {
bouncing_sound_enabled_ = value;
for (auto &balloon : balloons_)
{
for (auto &balloon : balloons_) {
balloon->setBouncingSound(value);
}
}
// Activa o desactiva los sonidos de los globos al explotar
void BalloonManager::setPoppingSounds(bool value)
{
void BalloonManager::setPoppingSounds(bool value) {
poping_sound_enabled_ = value;
for (auto &balloon : balloons_)
{
for (auto &balloon : balloons_) {
balloon->setPoppingSound(value);
}
}