Skip to content

Commit

Permalink
Completed implementation of 5 blocks variant. Including menu and a sl…
Browse files Browse the repository at this point in the history
…ight bug fix to one of the initial setups
  • Loading branch information
sago007 committed Apr 14, 2024
1 parent b76e007 commit 1b403c4
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/code/BlockGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 54 additions & 3 deletions source/code/ScoresDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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];
Expand Down Expand Up @@ -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();
};
Expand Down
7 changes: 7 additions & 0 deletions source/code/ScoresDisplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions source/code/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
5 changes: 5 additions & 0 deletions source/code/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions source/code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions source/code/menudef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -440,6 +456,7 @@ static void ConfigureMenu() {
MusicButton bMusic;
SoundButton bSound;
FullscreenButton buttonFullscreen;
BlockVariantButton bBlockVariant;
Button bPlayerConfig;
bPlayerConfig.setLabel(_("Player configuration") );
bPlayerConfig.setAction(PlayerConfigMenu);
Expand All @@ -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);
Expand Down

0 comments on commit 1b403c4

Please sign in to comment.