Au, a dormir que tinc son

This commit is contained in:
2024-11-06 22:22:35 +01:00
parent d902bb9088
commit 0e527ff9d9
8 changed files with 422 additions and 628 deletions

View File

@@ -1,7 +1,8 @@
#include "game.h"
#include "asset.h" // Para Asset
#include "background.h" // Para Background
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
#include "stage.h"
#include "asset.h" // Para Asset
#include "background.h" // Para Background
#include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus
#include "balloon_manager.h"
#include "fade.h" // Para Fade, FadeType
#include "global_inputs.h" // Para check
@@ -795,7 +796,7 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
{
// Si no tiene cafes, muere
pauseMusic();
stopAllBalloons();
balloon_manager_->stopAllBalloons();
JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
screen_->shake();
JA_PlaySound(Resource::get()->getSound("coffeeout.wav"));
@@ -1112,7 +1113,7 @@ void Game::checkEvents()
{
case SDLK_1: // Crea una powerball
{
createPowerBall();
balloon_manager_->createPowerBall();
break;
}
case SDLK_2: // Crea dos globos gordos
@@ -1166,9 +1167,6 @@ void Game::reloadTextures()
for (auto &texture : item_textures_)
texture->reLoad();
for (auto &texture : balloon_textures_)
texture->reLoad();
for (auto &textures : player_textures_)
for (auto &texture : textures)
texture->reLoad();
@@ -1579,8 +1577,7 @@ void Game::setTotalPower()
total_power_to_complete_game_ = 0;
for (int i = 0; i < 10; ++i)
{
total_power_to_complete_game_ +=
balloon_formations_->getStage(i).power_to_complete;
total_power_to_complete_game_ += Stage::get(i).power_to_complete;
}
}
@@ -1593,7 +1590,9 @@ void Game::initScoreboard()
{
scoreboard_->setName(player->getScoreBoardPanel(), player->getName());
if (player->isWaiting())
{
scoreboard_->setMode(player->getScoreBoardPanel(), ScoreboardMode::WAITING);
}
}
}
@@ -1655,19 +1654,6 @@ void Game::initPlayers(int player_id)
player->setInvulnerable(false);
}
// Crea dos globos gordos
void Game::createTwoBigBalloons()
{
const auto set = balloon_formations_->getStage(0).balloon_pool.set[1];
const auto numEnemies = set.number_of_balloons;
for (int i = 0; i < numEnemies; ++i)
{
auto p = set.init[i];
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_,
p.creation_counter);
}
}
// Pausa la música
void Game::pauseMusic()
{
@@ -1784,28 +1770,28 @@ void Game::cleanVectors()
// Gestiona el nivel de amenaza
void Game::updateMenace()
{
const auto stage = balloon_formations_->getStage(current_stage_);
const float percent = current_power_ / stage.power_to_complete;
const int difference = stage.max_menace - stage.min_menace;
const auto stage = balloon_formations_->getStage(current_stage_);
const float percent = current_power_ / stage.power_to_complete;
const int difference = stage.max_menace - stage.min_menace;
// Aumenta el nivel de amenaza en función de la puntuación
menace_threshold_ = stage.min_menace + (difference * percent);
// Aumenta el nivel de amenaza en función de la puntuación
menace_threshold_ = stage.min_menace + (difference * percent);
// Si el nivel de amenza es inferior al umbral
if (menace_current_ < menace_threshold_)
{
// Crea una formación de enemigos
balloon_manager_->deployBalloonFormation();
// Si el nivel de amenza es inferior al umbral
if (menace_current_ < menace_threshold_)
{
// Crea una formación de enemigos
balloon_manager_->deployBalloonFormation();
// Recalcula el nivel de amenaza con el nuevo globo
evaluateAndSetMenace();
}
// Recalcula el nivel de amenaza con el nuevo globo
evaluateAndSetMenace();
}
}
// Calcula y establece el valor de amenaza en funcion de los globos activos
void Game::evaluateAndSetMenace()
{
menace_current_ = std::accumulate(
balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
menace_current_ = std::accumulate(
balloons_.begin(), balloons_.end(), 0, [](int sum, const auto &balloon)
{ return sum + (balloon->isEnabled() ? balloon->getMenace() : 0); });
}