Afegit un lock per evitar que es puga incrementar el poder de la fase

Es necesita almenys un jugador viu per a poder incrementar el poder de la fase
This commit is contained in:
2025-01-04 14:09:10 +01:00
parent 7b8f16610a
commit 81ee352553
7 changed files with 43 additions and 46 deletions

View File

@@ -229,12 +229,6 @@ void Balloon::move()
}
}
// Deshabilita el globo
void Balloon::disable() { enabled_ = false; }
// Explosiona el globo
void Balloon::pop() { disable(); }
// Actualiza al globo a su posicion, animación y controla los contadores
void Balloon::update()
{

View File

@@ -170,12 +170,6 @@ public:
// Actualiza la posición y estados del globo
void move();
// Deshabilita el globo y pone a cero todos los valores
void disable();
// Explosiona el globo
void pop();
// Actualiza al globo a su posicion, animación y controla los contadores
void update();
@@ -215,4 +209,5 @@ public:
void setSpeed(float speed) { speed_ = speed; }
void setInvulnerable(bool value) { invulnerable_ = value; }
void setSound(bool value) { sound_enabled_ = value; }
void disable() { enabled_ = false; }
};

View File

@@ -258,7 +258,7 @@ int BalloonManager::popBalloon(std::shared_ptr<Balloon> balloon)
// Agrega la explosión y elimina el globo
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
balloon->pop();
balloon->disable();
}
return score;
@@ -294,7 +294,7 @@ int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
// Destruye el globo
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
balloon->pop();
balloon->disable();
return score;
}

View File

@@ -256,32 +256,29 @@ void Game::renderPlayers()
// Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage()
{
if (state_ == GameState::PLAYING)
if (Stage::power >= Stage::get(Stage::number).power_to_complete)
{
if (Stage::power >= Stage::get(Stage::number).power_to_complete)
{
// Cambio de fase
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
++Stage::number;
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
balloon_manager_->resetBalloonSpeed();
screen_->flash(flash_color, 3);
screen_->shake();
// Cambio de fase
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power;
++Stage::number;
JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
balloon_manager_->resetBalloonSpeed();
screen_->flash(flash_color, 3);
screen_->shake();
// Escribe el texto por pantalla
if (Stage::number < 10)
// Escribe el texto por pantalla
if (Stage::number < 10)
{
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
if (Stage::number == 9)
{
std::vector<Path> paths = {paths_.at(2), paths_.at(3)};
if (Stage::number == 9)
{
createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
}
else
{
auto text = Resource::get()->getText("04b_25_2x");
const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38);
createMessage(paths, text->writeToTexture(caption, 1, -4));
}
createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
}
else
{
auto text = Resource::get()->getText("04b_25_2x");
const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38);
createMessage(paths, text->writeToTexture(caption, 1, -4));
}
}
}
@@ -858,7 +855,8 @@ void Game::renderPathSprites()
void Game::killPlayer(std::shared_ptr<Player> &player)
{
if (!player->isPlaying() || player->isInvulnerable())
{ // Si no está jugando o tiene inmunidad, no hace nada
{
// Si no está jugando o tiene inmunidad, no hace nada
return;
}
@@ -874,12 +872,16 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
else
{
// Si no tiene cafes, muere
// pauseMusic();
balloon_manager_->stopAllBalloons();
JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
screen_->shake();
JA_PlaySound(Resource::get()->getSound("voice_no.wav"));
player->setPlayingState(PlayerState::DYING);
if (allPlayersAreNotPlaying())
{
// No se puede subir poder de fase si no hay nadie jugando
Stage::power_can_be_added = false;
}
}
}
@@ -919,7 +921,6 @@ void Game::update()
counter_++;
updateDemo();
#ifdef RECORDING
updateRecording();
#endif

View File

@@ -10,6 +10,7 @@
#include "texture.h" // Para Texture
#include "resource.h"
#include "jail_audio.h"
#include "stage.h"
// Constructor
Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector<std::shared_ptr<Texture>> texture, const std::vector<std::vector<std::string>> &animations)
@@ -503,6 +504,7 @@ void Player::setPlayingState(PlayerState state)
init();
playing_state_ = PlayerState::PLAYING;
setScoreboardMode(ScoreboardMode::SCORE);
Stage::power_can_be_added = true;
break;
}
case PlayerState::CONTINUE:

View File

@@ -5,10 +5,11 @@
namespace Stage
{
std::vector<Stage> stages; // Variable con los datos de cada pantalla
int power = 0; // Poder acumulado en la fase
int total_power = 0; // Poder total necesario para completar el juego
int number = 0; // Fase actual
std::vector<Stage> stages; // Variable con los datos de cada pantalla
int power = 0; // Poder acumulado en la fase
int total_power = 0; // Poder total necesario para completar el juego
int number = 0; // Fase actual
bool power_can_be_added = true; // Habilita la recolecta de poder
// Devuelve una fase
Stage get(int index) { return stages.at(std::min(9, index)); }
@@ -35,7 +36,10 @@ namespace Stage
// Añade poder
void addPower(int amount)
{
power += amount;
total_power += amount;
if (power_can_be_added)
{
power += amount;
total_power += amount;
}
}
}

View File

@@ -19,6 +19,7 @@ namespace Stage
extern int power; // Poder acumulado en la fase
extern int total_power; // Poder total necesario para completar el juego
extern int number; // Fase actual
extern bool power_can_be_added; // Indica si se puede añadir poder a la fase
// Devuelve una fase
Stage get(int index);