From 1b403c4a56f861ab73cc87f590239d2eeec89e3c Mon Sep 17 00:00:00 2001 From: Poul Sander Date: Sun, 14 Apr 2024 16:57:33 +0200 Subject: [PATCH] Completed implementation of 5 blocks variant. Including menu and a slight bug fix to one of the initial setups --- source/code/BlockGame.cpp | 2 +- source/code/ScoresDisplay.cpp | 57 +++++++++++++++++++++++++++++++++-- source/code/ScoresDisplay.hpp | 7 +++++ source/code/common.cpp | 10 ++++++ source/code/common.h | 5 +++ source/code/main.cpp | 5 +++ source/code/menudef.cpp | 19 ++++++++++++ 7 files changed, 101 insertions(+), 4 deletions(-) diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 0c95078..c72b951 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -578,7 +578,7 @@ void BlockGame::putStartBlocks(int n) { default: //row 0: board[0][0]=4; - board[1][0]=5; + board[1][0]=1; board[2][0]=2; board[3][0]=0; board[4][0]=1; diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index fe31ec3..4b2767e 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp @@ -58,7 +58,7 @@ void ScoresDisplay::Write(SDL_Renderer* target, int x, int y, const std::string& Write(target, x, y, text.c_str()); } -const int numberOfPages = 7; +const int numberOfPages = 13; void ScoresDisplay::DrawBackgroundAndCalcPlacements() { DrawBackground(globalData.screen); @@ -85,13 +85,32 @@ void ScoresDisplay::DrawHighscores(int x, int y, bool endless, int level = 0) { case 4: header = _("Endless (Fastest):"); break; + case 5: + header = _("Endless (5 blocks):"); + break; + case 6: + header = _("Endless (5 blocks, Fast):"); + break; + case 7: + header = _("Endless (5 blocks, Faster):"); + break; + case 8: + header = _("Endless (5 blocks, Even faster):"); + break; + case 9: + header = _("Endless (5 blocks, Fastest):"); + break; default: header = _("Endless:"); }; Write(globalData.screen, x+100,y+100, header ); } else { - Write(globalData.screen, x+100,y+100, _("Time Trial:") ); + std::string header = _("Time Trial:"); + if (level == 1) { + header = _("Time Trial (5 blocks):"); + } + Write(globalData.screen, x+100,y+100, header ); } for (int i =0; i<10; i++) { record r; @@ -109,12 +128,32 @@ void ScoresDisplay::DrawHighscores(int x, int y, bool endless, int level = 0) { case 4: r = theTopScoresEndless4.getScoreNumber(i); break; + case 5: + r = theTopScoresEndless0_5.getScoreNumber(i); + break; + case 6: + r = theTopScoresEndless1_5.getScoreNumber(i); + break; + case 7: + r = theTopScoresEndless2_5.getScoreNumber(i); + break; + case 8: + r = theTopScoresEndless3_5.getScoreNumber(i); + break; + case 9: + r = theTopScoresEndless4_5.getScoreNumber(i); + break; default: r = theTopScoresEndless0.getScoreNumber(i); } } else { - r = theTopScoresTimeTrial.getScoreNumber(i); + if (level == 1) { + r = theTopScoresTimeTrial_5.getScoreNumber(i); + } + else { + r = theTopScoresTimeTrial.getScoreNumber(i); + } } char playerScore[32]; char playerName[32]; @@ -207,6 +246,18 @@ void ScoresDisplay::Draw(SDL_Renderer* target) { DrawHighscores(100,100,false); break; case 6: + case 7: + case 8: + case 9: + case 10: + //Highscores, endless 5 blocks + DrawHighscores(100,100,true, page-1); + break; + case 11: + //Highscores, Time Trial 5 blocks + DrawHighscores(100,100,false, 1); + break; + case 12: default: DrawStats(); }; diff --git a/source/code/ScoresDisplay.hpp b/source/code/ScoresDisplay.hpp index 3fae1d6..13a6836 100644 --- a/source/code/ScoresDisplay.hpp +++ b/source/code/ScoresDisplay.hpp @@ -52,6 +52,13 @@ class ScoresDisplay : public HelpCommonState { Highscore theTopScoresEndless3 = Highscore("endless", 0.04); //Stores highscores for endless Highscore theTopScoresEndless4 = Highscore("endless", 0.015); //Stores highscores for endless Highscore theTopScoresTimeTrial = Highscore("timetrial", 0.5); //Stores highscores for timetrial + // 5 variant + Highscore theTopScoresEndless0_5 = Highscore("endless_block5", 0.5); //Stores highscores for endless + Highscore theTopScoresEndless1_5 = Highscore("endless_block5", 0.1); //Stores highscores for endless + Highscore theTopScoresEndless2_5 = Highscore("endless_block5", 0.07); //Stores highscores for endless + Highscore theTopScoresEndless3_5 = Highscore("endless_block5", 0.04); //Stores highscores for endless + Highscore theTopScoresEndless4_5 = Highscore("endless_block5", 0.015); //Stores highscores for endless + Highscore theTopScoresTimeTrial_5 = Highscore("timetrial_block5", 0.5); //Stores highscores for timetrial private: void DrawHighscores(int x, int y, bool endless, int speedLevel); void DrawStats(); diff --git a/source/code/common.cpp b/source/code/common.cpp index 70f06eb..2b59fcc 100644 --- a/source/code/common.cpp +++ b/source/code/common.cpp @@ -220,6 +220,16 @@ int Config::getInt(const std::string& varName) { } } +int Config::getInt(const std::string& varName, int defaultValue) { + if (exists(varName)) { + return str2int(configMap[varName]); + } + else { + setInt(varName, defaultValue); + return defaultValue; + } +} + double Config::getValue(const std::string& varName) { if (exists(varName)) { return str2double(configMap[varName]); diff --git a/source/code/common.h b/source/code/common.h index 446db22..8915991 100644 --- a/source/code/common.h +++ b/source/code/common.h @@ -126,6 +126,11 @@ class Config */ int getInt(const std::string &varName); + /** + * Gets an int. If not set will set a default value. + */ + int getInt(const std::string& varName, int defaultValue); + /*getValue(varName) *Looks in the config file and returns the double that matches the key "varName" *Returns "0.0" if varName does not exist or cannot be parsed. diff --git a/source/code/main.cpp b/source/code/main.cpp index 0cdc04e..257a456 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -711,6 +711,7 @@ static void StartSinglePlayerEndless(int startSpeed) { startInfo.ticks = SDL_GetTicks(); startInfo.startBlocks = startInfo.ticks; startInfo.gameSpeed = startSpeed; + startInfo.basicBlockVariants = Config::getInstance()->getInt("basic_block_variants", 6); player1->NewGame(startInfo); twoPlayers =false; BlockGameAction a; @@ -726,6 +727,7 @@ static void StartSinglePlayerTimeTrial() { BlockGameStartInfo startInfo; startInfo.ticks = SDL_GetTicks(); startInfo.timeTrial = true; + startInfo.basicBlockVariants = Config::getInstance()->getInt("basic_block_variants", 6); player1->NewGame(startInfo); twoPlayers =false; BlockGameAction a; @@ -764,6 +766,7 @@ static void StarTwoPlayerTimeTrial() { BlockGameStartInfo startInfo; startInfo.ticks = SDL_GetTicks(); startInfo.timeTrial = true; + startInfo.basicBlockVariants = Config::getInstance()->getInt("basic_block_variants", 6); BlockGameStartInfo startInfo2 = startInfo; registerTTHighscorePlayer1 = true; registerTTHighscorePlayer2 = true; @@ -794,6 +797,7 @@ static void StartTwoPlayerVs() { startInfo.ticks = SDL_GetTicks(); startInfo.vsMode = true; startInfo.startBlocks = startInfo.ticks; + startInfo.basicBlockVariants = Config::getInstance()->getInt("basic_block_variants", 6); BlockGameStartInfo startInfo2 = startInfo; if (player1AI) { startInfo.AI = true; @@ -1389,6 +1393,7 @@ int runGame(Gametype gametype, int level) { startInfo.vsMode = true; startInfo.vsAI = true; startInfo.level = theAIlevel; + startInfo.basicBlockVariants = Config::getInstance()->getInt("basic_block_variants", 6); theGame.NewGame(startInfo); startInfo.AI = true; theGame2.NewGame(startInfo); diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index c77b0e8..eeaf85e 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -342,6 +342,10 @@ static void SetFullscreenLabel (Button* b) { b->setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") ); } +static void SetBlockVariationLabel (Button* b) { + b->setLabel(_("Block variants: ")+std::to_string(Config::getInstance()->getInt("basic_block_variants", 6)) ); +} + class AlwaysSoftwareRenderButton : public Button { virtual void doAction() override { Config::getInstance()->setInt("always-software", !Config::getInstance()->getInt("always-software")); @@ -373,6 +377,18 @@ class FullscreenButton : public Button { } }; +class BlockVariantButton : public Button { + virtual void doAction() override { + int blockVariation = Config::getInstance()->getInt("basic_block_variants", 6); + blockVariation++; + if (blockVariation>6) { + blockVariation = 5; + } + Config::getInstance()->setInt("basic_block_variants", blockVariation); + SetBlockVariationLabel(this); + } +}; + static void buttonActionPlayer1Name() { if ( OpenDialogbox(200, 100, globalData.player1name, _("Enter player 1 name:")) ) { return; //must save if true @@ -440,6 +456,7 @@ static void ConfigureMenu() { MusicButton bMusic; SoundButton bSound; FullscreenButton buttonFullscreen; + BlockVariantButton bBlockVariant; Button bPlayerConfig; bPlayerConfig.setLabel(_("Player configuration") ); bPlayerConfig.setAction(PlayerConfigMenu); @@ -450,10 +467,12 @@ static void ConfigureMenu() { SetMusicLabel(&bMusic); SetSoundLabel(&bSound); SetFullscreenLabel(&buttonFullscreen); + SetBlockVariationLabel(&bBlockVariant); cm.addButton(&bMusic); cm.addButton(&bSound); cm.addButton(&bSoftware); cm.addButton(&buttonFullscreen); + cm.addButton(&bBlockVariant); cm.addButton(&bPlayerConfig); cm.addButton(&bThemes); RunGameState(cm);