From 744f5d5711167e5ba318cc0c6e4eadfe3fd313d5 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 27 Sep 2023 19:42:26 +0200 Subject: [PATCH] =?UTF-8?q?FIX:=20La=20m=C3=A1xima=20puntuaci=C3=B3n=20no?= =?UTF-8?q?=20se=20actualizaba=20correctamente=20en=20el=20marcador=20cuan?= =?UTF-8?q?do=20se=20jugaba=20con=20puntuaciones=20online=20activadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/enter_id.cpp | 2 +- source/game.cpp | 64 ++++++++++++++++++++++++++++----------------- source/game.h | 4 +++ 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/source/enter_id.cpp b/source/enter_id.cpp index 136e206..fd0dbb8 100644 --- a/source/enter_id.cpp +++ b/source/enter_id.cpp @@ -82,7 +82,7 @@ void EnterID::checkEvents() { if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN) { - options->online.jailerID = (std::string)name; + options->online.jailerID = toLower((std::string)name); endSection(); break; } diff --git a/source/game.cpp b/source/game.cpp index 741a1c4..4e3f0aa 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -32,6 +32,12 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr // Carga los recursos 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); 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); @@ -392,10 +398,6 @@ void Game::loadMedia() << "** LOADING RESOURCES FOR GAME SECTION" << std::endl; } - // Carga ficheros - loadScoreFile(); - loadDemoFile(); - // Texturas bulletTexture = new Texture(renderer, asset->get("bullet.png")); gameBuildingsTexture = new Texture(renderer, asset->get("game_buildings.png")); @@ -1612,6 +1614,12 @@ void Game::updateHiScore() // Actualiza la máxima puntuación 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 scoreDataFile[0] = hiScore; scoreDataFile[1] = hiScore % 43; @@ -1736,22 +1744,7 @@ void Game::renderScoreBoard() // HI-SCORE textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset3, lang->getText(56)); - if (options->online.enabled) - { - 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)); - } + textScoreBoard->writeCentered(PLAY_AREA_CENTER_X, offset4, hiScoreName + updateScoreText(hiScore)); } // Actualiza las variables del jugador @@ -3088,15 +3081,12 @@ void Game::checkGameInput() } } - // Comprueba el input de pausa - //if (input->checkInput(input_pause, REPEAT_FALSE)) + // Si se pulsa cualquier tecla, se sale del modo demo if (input->checkAnyInput()) { section->name = SECTION_PROG_TITLE; } - - // Incrementa el contador de la demo if (demo.counter < TOTAL_DEMO_DATA) { @@ -3966,4 +3956,30 @@ void Game::reloadTextures() gamePowerMeterTexture->reLoad(); gameSkyColorsTexture->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 = ""; + } } \ No newline at end of file diff --git a/source/game.h b/source/game.h index d5ef460..5be190a 100644 --- a/source/game.h +++ b/source/game.h @@ -199,6 +199,7 @@ private: Uint8 ticksSpeed; // Velocidad a la que se repiten los bucles del programa Uint32 hiScore; // 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 Uint8 currentStage; // Indica la fase actual Uint8 stageBitmapCounter; // Contador para el tiempo visible del texto de Stage @@ -511,6 +512,9 @@ private: // Recarga las texturas void reloadTextures(); + // Establece la máxima puntuación desde fichero o desde las puntuaciones online + void setHiScore(); + public: // 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);