diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc index 194e238..40c4898 100644 --- a/source/code/BlockGameSdl.inc +++ b/source/code/BlockGameSdl.inc @@ -22,6 +22,7 @@ http://www.blockattack.net */ #include "BlockGame.hpp" +#include "global.hpp" class BlockGameSdl : public BlockGame { @@ -93,7 +94,7 @@ public: } void AddText(int x, int y, const std::string& text, int time) const override { - theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time); + globalData.theTextManager.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time); } void AddBall(int x, int y, bool right, int color) const override { diff --git a/source/code/TextManager.hpp b/source/code/TextManager.hpp index 1e61afa..7e34fa8 100644 --- a/source/code/TextManager.hpp +++ b/source/code/TextManager.hpp @@ -24,12 +24,13 @@ http://www.blockattack.net #ifndef TEXTMANAGER_HPP #define TEXTMANAGER_HPP +#include class TextMessage { private: int x = 0; int y = 0; - string textt; + std::string textt; unsigned long int time = 0; unsigned long int placeTime = 0; //Then the text was placed public: @@ -39,7 +40,7 @@ public: //constructor: TextMessage(int X, int Y,const char* Text,unsigned int Time) { - placeTime = currentTime; + placeTime = SDL_GetTicks(); x = X; y = Y; textt = Text; @@ -48,7 +49,7 @@ public: //true if the text has expired bool removeMe() { - return currentTime-placeTime>time; + return SDL_GetTicks()-placeTime>time; } int getX() { @@ -65,8 +66,8 @@ public: }; //text popup class TextManager { - static const int maxNumberOfTexts = 6*12*2*2; public: + static const int maxNumberOfTexts = 6*12*2*2; TextMessage textArray[maxNumberOfTexts]; bool textUsed[maxNumberOfTexts]; @@ -76,7 +77,7 @@ public: } } - int addText(int x, int y,string Text,unsigned int Time) { + int addText(int x, int y, const std::string& Text,unsigned int Time) { int textNumber = 0; while (textNumber spriteHolder; + + TextManager theTextManager; //The xsize and ysize are updated everytime the background is drawn int xsize = 1024; diff --git a/source/code/main.cpp b/source/code/main.cpp index 6700dd5..a957dbc 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -493,9 +493,6 @@ public: static ExplosionManager theExplosionManager; -#include "TextManager.hpp" - -static TextManager theTextManager; //Here comes the Block Game object #include "BlockGame.hpp" @@ -593,14 +590,16 @@ static void DrawBalls() { if (theExplosionManager.explosionUsed[i]) { DrawIMG(explosion[theExplosionManager.explosionArray[i].getFrame()],globalData.screen,theExplosionManager.explosionArray[i].getX(),theExplosionManager.explosionArray[i].getY()); } - if (theTextManager.textUsed[i]) { - int x = theTextManager.textArray[i].getX()-12; - int y = theTextManager.textArray[i].getY()-12; + } //for + for (int i = 0; i < globalData.theTextManager.maxNumberOfTexts; ++i) { + if (globalData.theTextManager.textUsed[i]) { + int x = globalData.theTextManager.textArray[i].getX()-12; + int y = globalData.theTextManager.textArray[i].getY()-12; DrawIMG(iChainFrame,globalData.screen,x,y); - nf_standard_small_font.draw(globalData.screen, x+12,y+7, NFont::CENTER, "%s",theTextManager.textArray[i].getText()); + nf_standard_small_font.draw(globalData.screen, x+12,y+7, NFont::CENTER, "%s", globalData.theTextManager.textArray[i].getText()); } - } //for + } } //DrawBalls @@ -1090,7 +1089,7 @@ int main(int argc, char* argv[]) { InitGameControllers(); TTF_Init(); atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc) - theTextManager = TextManager(); + globalData.theTextManager = TextManager(); //Open Audio if (!globalData.NoSound) { @@ -1435,7 +1434,7 @@ int runGame(Gametype gametype, int level) { //updates the balls and explosions:g theBallManager.update(); theExplosionManager.update(); - theTextManager.update(); + globalData.theTextManager.update(); bool mustWriteScreenshot = false;