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 // Actualiza al globo a su posicion, animación y controla los contadores
void Balloon::update() void Balloon::update()
{ {

View File

@@ -170,12 +170,6 @@ public:
// Actualiza la posición y estados del globo // Actualiza la posición y estados del globo
void move(); 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 // Actualiza al globo a su posicion, animación y controla los contadores
void update(); void update();
@@ -215,4 +209,5 @@ public:
void setSpeed(float speed) { speed_ = speed; } void setSpeed(float speed) { speed_ = speed; }
void setInvulnerable(bool value) { invulnerable_ = value; } void setInvulnerable(bool value) { invulnerable_ = value; }
void setSound(bool value) { sound_enabled_ = 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 // Agrega la explosión y elimina el globo
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize())); explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
balloon->pop(); balloon->disable();
} }
return score; return score;
@@ -294,7 +294,7 @@ int BalloonManager::destroyBalloon(std::shared_ptr<Balloon> &balloon)
// Destruye el globo // Destruye el globo
explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize())); explosions_->add(balloon->getPosX(), balloon->getPosY(), static_cast<int>(balloon->getSize()));
balloon->pop(); balloon->disable();
return score; return score;
} }

View File

@@ -256,32 +256,29 @@ void Game::renderPlayers()
// Comprueba si hay cambio de fase y actualiza las variables // Comprueba si hay cambio de fase y actualiza las variables
void Game::updateStage() 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;
// Cambio de fase ++Stage::number;
Stage::power = Stage::get(Stage::number).power_to_complete - Stage::power; JA_PlaySound(Resource::get()->getSound("stage_change.wav"));
++Stage::number; balloon_manager_->resetBalloonSpeed();
JA_PlaySound(Resource::get()->getSound("stage_change.wav")); screen_->flash(flash_color, 3);
balloon_manager_->resetBalloonSpeed(); screen_->shake();
screen_->flash(flash_color, 3);
screen_->shake();
// Escribe el texto por pantalla // Escribe el texto por pantalla
if (Stage::number < 10) 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)}; createMessage(paths, Resource::get()->getTexture("game_text_last_stage"));
if (Stage::number == 9) }
{ else
createMessage(paths, Resource::get()->getTexture("game_text_last_stage")); {
} auto text = Resource::get()->getText("04b_25_2x");
else const std::string caption = std::to_string(10 - Stage::number) + lang::getText(38);
{ createMessage(paths, text->writeToTexture(caption, 1, -4));
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) void Game::killPlayer(std::shared_ptr<Player> &player)
{ {
if (!player->isPlaying() || player->isInvulnerable()) 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; return;
} }
@@ -874,12 +872,16 @@ void Game::killPlayer(std::shared_ptr<Player> &player)
else else
{ {
// Si no tiene cafes, muere // Si no tiene cafes, muere
// pauseMusic();
balloon_manager_->stopAllBalloons(); balloon_manager_->stopAllBalloons();
JA_PlaySound(Resource::get()->getSound("player_collision.wav")); JA_PlaySound(Resource::get()->getSound("player_collision.wav"));
screen_->shake(); screen_->shake();
JA_PlaySound(Resource::get()->getSound("voice_no.wav")); JA_PlaySound(Resource::get()->getSound("voice_no.wav"));
player->setPlayingState(PlayerState::DYING); 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_++; counter_++;
updateDemo(); updateDemo();
#ifdef RECORDING #ifdef RECORDING
updateRecording(); updateRecording();
#endif #endif

View File

@@ -10,6 +10,7 @@
#include "texture.h" // Para Texture #include "texture.h" // Para Texture
#include "resource.h" #include "resource.h"
#include "jail_audio.h" #include "jail_audio.h"
#include "stage.h"
// Constructor // 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) 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(); init();
playing_state_ = PlayerState::PLAYING; playing_state_ = PlayerState::PLAYING;
setScoreboardMode(ScoreboardMode::SCORE); setScoreboardMode(ScoreboardMode::SCORE);
Stage::power_can_be_added = true;
break; break;
} }
case PlayerState::CONTINUE: case PlayerState::CONTINUE:

View File

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

View File

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