git repos / blockattack-game

commit 343fbe43

sago007 · 2018-03-27 19:53
343fbe4395c871e76ec4edc228edc9d8772e1410 patch · browse files
parent e554e0a8555edbe7fc1d6eab2cd1794887a10201

Changed the scoreboard text to be drawn as SagoTextFields

Changed files

M source/code/BlockGameSdl.inc before
M source/code/main.cpp before
M source/code/sago/SagoTextField.cpp before
diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc index d64b94b..3d59a20 100644 --- a/source/code/BlockGameSdl.inc +++ b/source/code/BlockGameSdl.inc
@@ -23,13 +23,25 @@ http://www.blockattack.net
#include "BlockGame.hpp"
#include "global.hpp"
+#include "sago/SagoTextField.hpp"
+static void setScoreboardFont(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text){
+ field.SetHolder(holder);
+ field.SetFont("penguinattack");
+ field.SetColor({255,255,255,255});
+ field.SetFontSize(20);
+ field.SetText(text);
+}
class BlockGameSdl : public BlockGame {
public:
- BlockGameSdl(int tx, int ty) {
+ BlockGameSdl(int tx, int ty, const sago::SagoDataHolder* holder) {
topx = tx;
topy = ty;
+ setScoreboardFont(holder, scoreLabel, _("Score:"));
+ setScoreboardFont(holder, timeLabel, _("Time:"));
+ setScoreboardFont(holder, chainLabel, _("Chain:"));
+ setScoreboardFont(holder, speedLabel, _("Speed:"));
}
@@ -290,10 +302,10 @@ public:
void DoPaintJob() {
DrawIMG(boardBackBack,globalData.screen,this->GetTopX()-60,this->GetTopY()-68);
- globalData.scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+148,_("Score:") );
- globalData.scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+197,_("Time:") );
- globalData.scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+246,_("Chain:") );
- globalData.scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+295,_("Speed:") );
+ this->scoreLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+148);
+ this->timeLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+197);
+ this->chainLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+246);
+ this->speedLabel.Draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+295);
DrawImgBoard(backBoard, 0, 0);
PaintBricks();
@@ -420,6 +432,10 @@ public:
private:
int topx, topy;
+ sago::SagoTextField scoreLabel;
+ sago::SagoTextField timeLabel;
+ sago::SagoTextField chainLabel;
+ sago::SagoTextField speedLabel;
};
diff --git a/source/code/main.cpp b/source/code/main.cpp index 676da45..3e90c91 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1080,8 +1080,8 @@ int main(int argc, char* argv[]) {
cout << "Images loaded" << "\n";
}
- BlockGameSdl theGame = BlockGameSdl(50, 100); //creates game objects
- BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500, 100);
+ BlockGameSdl theGame = BlockGameSdl(50, 100, &globalData.spriteHolder->GetDataHolder()); //creates game objects
+ BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500, 100, &globalData.spriteHolder->GetDataHolder());
player1 = &theGame;
player2 = &theGame2;
@@ -1180,15 +1180,15 @@ int runGame(Gametype gametype, int level) {
globalData.theTopScoresTimeTrial = Highscore("timetrial");
drawBalls = true;
puzzleLoaded = false;
- bool bNearDeath = false; //Play music faster or louder while tru
+ bool bNearDeath = false; //Play music faster or louder while tru
theBallManager = BallManager();
theExplosionManager = ExplosionManager();
- BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects
- BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500,100);
+ BlockGameSdl theGame = BlockGameSdl(50, 100, &globalData.spriteHolder->GetDataHolder()); //creates game objects
+ BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500, 100, &globalData.spriteHolder->GetDataHolder());
player1 = &theGame;
player2 = &theGame2;
- theGame.DoPaintJob(); //Makes sure what there is something to paint
+ theGame.DoPaintJob(); //Makes sure what there is something to paint
theGame2.DoPaintJob();
BlockGameAction a;
a.action = BlockGameAction::Action::SET_GAME_OVER;
diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp index 578ec0c..ecfbc2c 100644 --- a/source/code/sago/SagoTextField.cpp +++ b/source/code/sago/SagoTextField.cpp
@@ -137,10 +137,6 @@ const std::string& SagoTextField::GetText() const {
}
void SagoTextField::ClearCache() {
- if (!data->tex) {
- std::cerr << "FATAL: DataHolder not set!\n";
- abort();
- }
if (data->texture) {
SDL_DestroyTexture(data->texture);
data->texture = nullptr;
@@ -160,6 +156,10 @@ void SagoTextField::ClearCache() {
}
void SagoTextField::UpdateCache(SDL_Renderer* target) {
+ if (!data->tex) {
+ std::cerr << "FATAL: DataHolder not set!\n";
+ abort();
+ }
ClearCache();
TTF_Font *font = data->tex->getFontPtr(data->fontName, data->fontSize);
data->textSurface = TTF_RenderUTF8_Blended (font, data->text.c_str(), data->color);