FIX: La máxima puntuación no se actualizaba correctamente en el marcador cuando se jugaba con puntuaciones online activadas

This commit is contained in:
2023-09-27 19:42:26 +02:00
parent 8fa40c802e
commit 744f5d5711
3 changed files with 45 additions and 25 deletions

View File

@@ -82,7 +82,7 @@ void EnterID::checkEvents()
{ {
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN) if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
{ {
options->online.jailerID = (std::string)name; options->online.jailerID = toLower((std::string)name);
endSection(); endSection();
break; break;
} }

View File

@@ -32,6 +32,12 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
// Carga los recursos // Carga los recursos
loadMedia(); loadMedia();
// Carga ficheros
loadDemoFile();
// Establece la máxima puntuación desde fichero o desde las puntuaciones online
setHiScore();
clouds1A = new MovingSprite(0, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer); clouds1A = new MovingSprite(0, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer);
clouds1B = new MovingSprite(256, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer); clouds1B = new MovingSprite(256, 0, 256, 52, -0.4f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer);
clouds2A = new MovingSprite(0, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer); clouds2A = new MovingSprite(0, 52, 256, 32, -0.2f, 0.0f, 0.0f, 0.0f, gameCloudsTexture, renderer);
@@ -392,10 +398,6 @@ void Game::loadMedia()
<< "** LOADING RESOURCES FOR GAME SECTION" << std::endl; << "** LOADING RESOURCES FOR GAME SECTION" << std::endl;
} }
// Carga ficheros
loadScoreFile();
loadDemoFile();
// Texturas // Texturas
bulletTexture = new Texture(renderer, asset->get("bullet.png")); bulletTexture = new Texture(renderer, asset->get("bullet.png"));
gameBuildingsTexture = new Texture(renderer, asset->get("game_buildings.png")); gameBuildingsTexture = new Texture(renderer, asset->get("game_buildings.png"));
@@ -1612,6 +1614,12 @@ void Game::updateHiScore()
// Actualiza la máxima puntuación // Actualiza la máxima puntuación
hiScore = player->getScore(); hiScore = player->getScore();
// Cambia el nombre del jugador con la máxima puntuación
if (options->online.enabled)
{
hiScoreName = options->online.jailerID.substr(0, 12) + " - ";
}
// Almacena la máxima puntuación en el fichero junto con un checksum // Almacena la máxima puntuación en el fichero junto con un checksum
scoreDataFile[0] = hiScore; scoreDataFile[0] = hiScore;
scoreDataFile[1] = hiScore % 43; scoreDataFile[1] = hiScore % 43;
@@ -1736,22 +1744,7 @@ void Game::renderScoreBoard()
// HI-SCORE // HI-SCORE
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56)); textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56));
if (options->online.enabled) textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, hiScoreName + updateScoreText(hiScore));
{
if (jscore::getNumUsers() > 0)
{
const std::string txt = jscore::getUserName(0).substr(0, 12) + " - " + updateScoreText((Uint32)jscore::getPoints(0));
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, txt);
}
else
{
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, "Bacteriol - 0000010");
}
}
else
{
textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, updateScoreText(hiScore));
}
} }
// Actualiza las variables del jugador // Actualiza las variables del jugador
@@ -3088,15 +3081,12 @@ void Game::checkGameInput()
} }
} }
// Comprueba el input de pausa // Si se pulsa cualquier tecla, se sale del modo demo
//if (input->checkInput(input_pause, REPEAT_FALSE))
if (input->checkAnyInput()) if (input->checkAnyInput())
{ {
section->name = SECTION_PROG_TITLE; section->name = SECTION_PROG_TITLE;
} }
// Incrementa el contador de la demo // Incrementa el contador de la demo
if (demo.counter < TOTAL_DEMO_DATA) if (demo.counter < TOTAL_DEMO_DATA)
{ {
@@ -3966,4 +3956,30 @@ void Game::reloadTextures()
gamePowerMeterTexture->reLoad(); gamePowerMeterTexture->reLoad();
gameSkyColorsTexture->reLoad(); gameSkyColorsTexture->reLoad();
gameTextTexture->reLoad(); gameTextTexture->reLoad();
}
// Establece la máxima puntuación desde fichero o desde las puntuaciones online
void Game::setHiScore()
{
// Carga el fichero de puntos
loadScoreFile();
// Establece el resto de variables
if (options->online.enabled)
{
if (jscore::getNumUsers() > 0)
{
hiScoreName = jscore::getUserName(0).substr(0, 12) + " - ";
hiScore = (Uint32)jscore::getPoints(0);
}
else
{
hiScoreName = "Bacteriol - ";
hiScore = 10;
}
}
else
{
hiScoreName = "";
}
} }

View File

@@ -199,6 +199,7 @@ private:
Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
Uint32 hiScore; // Puntuación máxima Uint32 hiScore; // Puntuación máxima
bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima
std::string hiScoreName; // Nombre del jugador que ostenta la máxima puntuación
stage_t stage[10]; // Variable con los datos de cada pantalla stage_t stage[10]; // Variable con los datos de cada pantalla
Uint8 currentStage; // Indica la fase actual Uint8 currentStage; // Indica la fase actual
Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage
@@ -511,6 +512,9 @@ private:
// Recarga las texturas // Recarga las texturas
void reloadTextures(); void reloadTextures();
// Establece la máxima puntuación desde fichero o desde las puntuaciones online
void setHiScore();
public: public:
// Constructor // Constructor
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section); Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section);