diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 042c8b8..652a3c8 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -41,10 +41,10 @@ const char* const menu_unmarked = "menu_unmarked"; ButtonGfx standardButton; void ButtonGfx::setSurfaces() { - xsize = spriteHolder->GetSprite(menu_marked).GetWidth(); - ysize = spriteHolder->GetSprite(menu_marked).GetHeight(); + this->xsize = spriteHolder->GetSprite(menu_marked).GetWidth(); + this->ysize = spriteHolder->GetSprite(menu_marked).GetHeight(); if (verboseLevel) { - cout << "Surfaces set, size: " <xsize << " , " << this->ysize << "\n"; } } @@ -121,7 +121,6 @@ int Button::getHeight() { } void Menu::drawSelf() { - SDL_RenderClear(screen); DrawBackground(screen); vector::iterator it; for (it = buttons.begin(); it < buttons.end(); it++) { diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 3d07ce1..602bc25 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp @@ -37,9 +37,16 @@ static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) { const int numberOfPages = 3; +void ScoresDisplay::DrawBackgroundAndCalcPlacements() { + DrawBackground(screen); + nextX = xsize-buttonXsize-20; + backY = ysize-buttonYsize-20; + nextY = backY; +} + //Draws the highscores void ScoresDisplay::DrawHighscores(int x, int y, bool endless) { - DrawBackground(screen); + DrawBackgroundAndCalcPlacements(); if (endless) { nf_standard_blue_font.draw(screen, x+100,y+100, "%s",_("Endless:") ); } @@ -64,7 +71,7 @@ void ScoresDisplay::DrawHighscores(int x, int y, bool endless) { } void ScoresDisplay::DrawStats() { - DrawBackground(screen); + DrawBackgroundAndCalcPlacements(); int y = 5; const int y_spacing = 30; NFont_Write(screen, 10,y,_("Stats") ); diff --git a/source/code/ScoresDisplay.hpp b/source/code/ScoresDisplay.hpp index d95fafe..20922e7 100644 --- a/source/code/ScoresDisplay.hpp +++ b/source/code/ScoresDisplay.hpp @@ -41,19 +41,18 @@ public: //button coodinates: int scoreX = 0; int scoreY = 0; - int backX = 20; - int backY = 0; - int nextX = 0; - int nextY = 0; - int xsize = 0; - int ysize = 0; int buttonXsize = 0; int buttonYsize = 0; private: void DrawHighscores(int x, int y, bool endless); void DrawStats(); + void DrawBackgroundAndCalcPlacements(); bool isActive = true; bool bMouseUp = false; + int backX = 20; + int backY = 0; + int nextX = 0; + int nextY = 0; }; #endif /* SCORESDISPLAY_HPP */ diff --git a/source/code/global.hpp b/source/code/global.hpp index f9a559c..71753b7 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp @@ -63,6 +63,9 @@ extern Highscore theTopScoresEndless; //Stores highscores for endless extern Highscore theTopScoresTimeTrial; //Stores highscores for timetrial extern std::unique_ptr spriteHolder; +//The xsize and ysize are updated everytime the background is drawn +extern int xsize; +extern int ysize; #endif /* _GLOBAL_HPP */ diff --git a/source/code/main.cpp b/source/code/main.cpp index 4b1e00f..daaf64d 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -267,6 +267,7 @@ void ResetFullscreen() { } void DrawBackground(SDL_Renderer* target) { + SDL_RenderClear(target); SDL_GetWindowSize(sdlWindow, &xsize, &ysize); backgroundImage.DrawScaled(target, SDL_GetTicks(), 0, 0, xsize, ysize); } @@ -625,12 +626,6 @@ void OpenScoresDisplay() { ScoresDisplay d; d.scoreX = buttonXsize*2; d.scoreY = 0; - d.backX = 20; - d.backY = ysize-buttonYsize-20; - d.nextX = xsize-buttonXsize-20; - d.nextY = d.backY; - d.xsize = xsize; - d.ysize = ysize; d.buttonXsize = buttonXsize; d.buttonYsize = buttonYsize; RunGameState(d); @@ -1475,7 +1470,6 @@ int main(int argc, char* argv[]) { s.singlePuzzle = true; theGame.NewGame(s); } - SDL_RenderClear(screen); DrawBackground(screen); DrawEverything(xsize,ysize,&theGame,&theGame2); SDL_RenderPresent(screen); @@ -1619,33 +1613,33 @@ int runGame(Gametype gametype, int level) { return 1; } break; - case Gametype::SinglePlayerVs: { - //1 player - Vs mode - int theAIlevel = level; //startSingleVs(); - BlockGameStartInfo startInfo; - startInfo.ticks = SDL_GetTicks(); - startInfo.vsMode = true; - startInfo.vsAI = true; - startInfo.level = theAIlevel; - theGame.NewGame(startInfo); - startInfo.AI = true; - theGame2.NewGame(startInfo); - DrawBackground(screen); - twoPlayers = true; //Single player, but AI plays - theGame.name = player1name; - theGame2.name = player2name; - } - break; + case Gametype::SinglePlayerVs: + { + //1 player - Vs mode + int theAIlevel = level; //startSingleVs(); + BlockGameStartInfo startInfo; + startInfo.ticks = SDL_GetTicks(); + startInfo.vsMode = true; + startInfo.vsAI = true; + startInfo.level = theAIlevel; + theGame.NewGame(startInfo); + startInfo.AI = true; + theGame2.NewGame(startInfo); + DrawBackground(screen); + twoPlayers = true; //Single player, but AI plays + theGame.name = player1name; + theGame2.name = player2name; + } + break; case Gametype::TwoPlayerTimeTrial: - StarTwoPlayerTimeTrial(); - break; + StarTwoPlayerTimeTrial(); + break; case Gametype::TwoPlayerVs: - StartTwoPlayerVs(); - break; + StartTwoPlayerVs(); + break; case Gametype::SinglePlayerEndless: - default: - StartSinglePlayerEndless(); - break; + default: + StartSinglePlayerEndless(); }; mustsetupgame = false; DrawBackground(screen); @@ -1657,7 +1651,6 @@ int runGame(Gametype gametype, int level) { SDL_Delay(1); } - SDL_RenderClear(screen); DrawBackground(screen); //updates the balls and explosions:g theBallManager.update(); @@ -1958,8 +1951,8 @@ int runGame(Gametype gametype, int level) { &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize)) { //Clicked the next button after a stage clear or puzzle nextLevel(theGame, SDL_GetTicks()); - } + if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x) &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize) &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize)) { diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index feefca5..7d227c4 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc @@ -160,8 +160,8 @@ static Uint8 player2handicap=0; unsigned long int currentTime; //contains the current time, so we don't call SDL_GetTickets() too often... -static int xsize = 1024; -static int ysize = 768; +int xsize = 1024; +int ysize = 768; //Stores the players names (way to long, but at least no buffer overflows (max length is 16 for display reasons)) std::string player1name;