git repos / blockattack-game

commit 72383a9e

sago007 · 2016-10-30 11:56
72383a9e4333ecc1699c17fef457b6ac9bc741a8 patch · browse files
parent 288644261cdd864557f6c8ae96fc3bbd9a7a12e1

Removed a lot of "extern" global variables and replaced them with 1. Might not seem like a big difference but now it is a little easier to see if data are used or not.

Changed files

M source/code/BlockGameSdl.inc before
M source/code/DialogBox.cpp before
M source/code/MenuSystem.cpp before
M source/code/ScoresDisplay.cpp before
M source/code/global.hpp before
M source/code/main.cpp before
M source/code/mainVars.inc before
M source/code/menudef.cpp before
diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc index a3c108a..194e238 100644 --- a/source/code/BlockGameSdl.inc +++ b/source/code/BlockGameSdl.inc
@@ -33,19 +33,19 @@ public:
void DrawImgBoard(const sago::SagoSprite& img, int x, int y) const {
- DrawIMG(img, screen, x+topx, y+topy);
+ DrawIMG(img, globalData.screen, x+topx, y+topy);
}
void DrawImgBoardBounded(const sago::SagoSprite& img, int x, int y) const {
- DrawIMG_Bounded(img, screen, x+topx, y+topy, topx, topy, topx + backBoard.GetWidth(), topy + backBoard.GetHeight());
+ DrawIMG_Bounded(img, globalData.screen, x+topx, y+topy, topx, topy, topx + backBoard.GetWidth(), topy + backBoard.GetHeight());
}
void PrintTextCenteredBoard(int x, int y, const char* text) {
- nf_button_font.draw(screen, x+topx+60, y+topy+10, NFont::CENTER, "%s", text);
+ globalData.nf_button_font.draw(globalData.screen, x+topx+60, y+topy+10, NFont::CENTER, "%s", text);
}
void PrintIntRightAlignedBoard(int x, int y, int number) {
- nf_button_font.draw(screen, x+topx+60, y+topy+10, NFont::RIGHT, "%d", number);
+ globalData.nf_button_font.draw(globalData.screen, x+topx+60, y+topy+10, NFont::RIGHT, "%d", number);
}
void SetTopXY(int tx, int ty) {
@@ -105,7 +105,7 @@ public:
}
void PlayerWonEvent() const override {
- if (!SoundEnabled) {
+ if (!globalData.SoundEnabled) {
return;
}
Mix_PlayChannel(1, applause, 0);
@@ -116,27 +116,27 @@ public:
}
void BlockPopEvent() const override {
- if (!SoundEnabled) {
+ if (!globalData.SoundEnabled) {
return;
}
Mix_PlayChannel(0, boing, 0);
}
void LongChainDoneEvent() const override {
- if (!SoundEnabled) {
+ if (!globalData.SoundEnabled) {
return;
}
Mix_PlayChannel(1, applause, 0);
}
void TimeTrialEndEvent() const override {
- if (!NoSound && SoundEnabled) {
+ if (!globalData.NoSound && globalData.SoundEnabled) {
Mix_PlayChannel(1,counterFinalChunk,0);
}
}
void EndlessHighscoreEvent() const override {
- if (!SoundEnabled) {
+ if (!globalData.SoundEnabled) {
return;
}
Mix_PlayChannel(1, applause, 0);
@@ -287,12 +287,12 @@ private:
public:
//Draws everything
void DoPaintJob() {
- DrawIMG(boardBackBack,screen,this->GetTopX()-60,this->GetTopY()-68);
+ DrawIMG(boardBackBack,globalData.screen,this->GetTopX()-60,this->GetTopY()-68);
- nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+148,_("Score:") );
- nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+197,_("Time:") );
- nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+246,_("Chain:") );
- nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+295,_("Speed:") );
+ globalData.nf_scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+148,_("Score:") );
+ globalData.nf_scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+197,_("Time:") );
+ globalData.nf_scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+246,_("Chain:") );
+ globalData.nf_scoreboard_font.draw(globalData.screen, this->GetTopX()+310,this->GetTopY()-68+295,_("Speed:") );
DrawImgBoard(backBoard, 0, 0);
PaintBricks();
@@ -302,7 +302,7 @@ public:
if (puzzleMode&&(!bGameOver)) {
//We need to write nr. of moves left!
strHolder = _("Moves left: ") + std::to_string(MovesLeft);
- nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s", strHolder.c_str());
}
if (puzzleMode && stageButtonStatus == SBpuzzleMode) {
@@ -310,7 +310,7 @@ public:
PrintTextCenteredBoard(cordRetryButton.x, cordRetryButton.y, _("Retry"));
if (getLevel()<PuzzleGetNumberOfPuzzles()-1) {
if (hasWonTheGame) {
- DrawImgBoard(bNext,cordNextButton.x, cordNextButton.y);
+ DrawImgBoard(globalData.bNext, cordNextButton.x, cordNextButton.y);
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Next"));
}
else {
@@ -320,7 +320,7 @@ public:
}
else {
strHolder = "Last puzzle";
- nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s",strHolder.c_str());
}
}
if (stageClear && stageButtonStatus == SBstageClear) {
@@ -328,7 +328,7 @@ public:
PrintTextCenteredBoard(cordRetryButton.x, cordRetryButton.y, _("Retry"));
if (getLevel()<50-1) {
if (hasWonTheGame) {
- DrawImgBoard(bNext,cordNextButton.x, cordNextButton.y);
+ DrawImgBoard(globalData.bNext, cordNextButton.x, cordNextButton.y);
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Next"));
}
else {
@@ -338,7 +338,7 @@ public:
}
else {
strHolder = "Last stage";
- nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s",strHolder.c_str());
}
}
if (!bGameOver && stop > 20) {
@@ -349,7 +349,7 @@ public:
if (AI_Enabled&&(!bGameOver)) {
strHolder = "AI_status: " + std::to_string(AIstatus)+ ", "+ std::to_string(AIlineToClear);
//NFont_Write( 5, 5, strHolder.c_str());
- nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s",strHolder.c_str());
}
#endif
if (!bGameOver) {
@@ -358,7 +358,7 @@ public:
int my = 0;
this->GetMouseCursor(touched, mx, my);
if (touched) {
- DrawImgBoard(spriteHolder->GetSprite("touchcursor"),mx*bsize, 11*bsize-my*bsize-pixels);
+ DrawImgBoard(globalData.spriteHolder->GetSprite("touchcursor"),mx*bsize, 11*bsize-my*bsize-pixels);
}
else {
DrawImgBoard(cursor,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4);
@@ -366,7 +366,7 @@ public:
}
if (ticks<gameStartedAt) {
int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000;
- if ( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound)) {
+ if ( (currentCounter!=lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) {
Mix_PlayChannel(1,counterChunk,0);
}
lastCounter = currentCounter;
@@ -385,7 +385,7 @@ public:
}
}
else {
- if (SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver)) {
+ if (globalData.SoundEnabled&&(!globalData.NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver)) {
int currentCounter = (ticks-(int)gameStartedAt)/1000;
if (currentCounter!=lastCounter) {
if (currentCounter>115 && currentCounter<120) {
@@ -395,8 +395,8 @@ public:
lastCounter = currentCounter;
}
else {
- if ( (0==lastCounter) && (SoundEnabled)&&(!NoSound)) {
- Mix_PlayChannel(1,counterFinalChunk,0);
+ if ( (0==lastCounter) && (globalData.SoundEnabled)&&(!globalData.NoSound)) {
+ Mix_PlayChannel(1, counterFinalChunk, 0);
}
lastCounter = -1;
}
diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp index a6f38d4..755f7d4 100644 --- a/source/code/DialogBox.cpp +++ b/source/code/DialogBox.cpp
@@ -27,18 +27,18 @@ http://www.blockattack.net
#include "ReadKeyboard.h"
static void NFont_Write(SDL_Renderer* target, int x, int y, const std::string& text) {
- nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
+ globalData.nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
}
static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int width, const std::string& name) {
const int size = 32;
SDL_Rect bounds_ns = {topx, topy+size, width, height-2*size}; //bounds for south
SDL_Rect bounds_e = {topx, topy, width-size, height};
- const sago::SagoSprite& n = spriteHolder->GetSprite(name+"n");
- const sago::SagoSprite& s = spriteHolder->GetSprite(name+"s");
- const sago::SagoSprite& e = spriteHolder->GetSprite(name+"e");
- const sago::SagoSprite& w = spriteHolder->GetSprite(name+"w");
- const sago::SagoSprite& fill = spriteHolder->GetSprite(name+"fill");
+ const sago::SagoSprite& n = globalData.spriteHolder->GetSprite(name+"n");
+ const sago::SagoSprite& s = globalData.spriteHolder->GetSprite(name+"s");
+ const sago::SagoSprite& e = globalData.spriteHolder->GetSprite(name+"e");
+ const sago::SagoSprite& w = globalData.spriteHolder->GetSprite(name+"w");
+ const sago::SagoSprite& fill = globalData.spriteHolder->GetSprite(name+"fill");
for (int i = 1; i < width/size; ++i) {
n.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy, bounds_e);
for (int j = 1; j < height/size; ++j) {
@@ -49,10 +49,10 @@ static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int w
s.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy+height-size, bounds_e);
}
//Corners
- const sago::SagoSprite& nw = spriteHolder->GetSprite(name+"nw");
- const sago::SagoSprite& ne = spriteHolder->GetSprite(name+"ne");
- const sago::SagoSprite& se = spriteHolder->GetSprite(name+"se");
- const sago::SagoSprite& sw = spriteHolder->GetSprite(name+"sw");
+ const sago::SagoSprite& nw = globalData.spriteHolder->GetSprite(name+"nw");
+ const sago::SagoSprite& ne = globalData.spriteHolder->GetSprite(name+"ne");
+ const sago::SagoSprite& se = globalData.spriteHolder->GetSprite(name+"se");
+ const sago::SagoSprite& sw = globalData.spriteHolder->GetSprite(name+"sw");
nw.Draw(target, SDL_GetTicks(), topx, topy);
ne.Draw(target, SDL_GetTicks(), topx+width-size, topy);
se.Draw(target, SDL_GetTicks(), topx+width-size, topy+height-size);
@@ -95,27 +95,27 @@ bool DialogBox::IsActive() {
void DialogBox::Draw(SDL_Renderer* target) {
- DrawBackground(screen);
- this->x = xsize/2-300;
- this->y = ysize/2-100;
+ DrawBackground(globalData.screen);
+ this->x = globalData.xsize/2-300;
+ this->y = globalData.ysize/2-100;
DrawRectYellow(target, x, y, 200, 600);
- nf_button_font.draw(target, x+300, y+20, NFont::CENTER, "%s", header.c_str());
- nf_button_font.draw(target, x+150, y+140, NFont::CENTER, _("Enter to accept"));
- nf_button_font.draw(target, x+450, y+140, NFont::CENTER, _("Esc to cancel"));
+ globalData.nf_button_font.draw(target, x+300, y+20, NFont::CENTER, "%s", header.c_str());
+ globalData.nf_button_font.draw(target, x+150, y+140, NFont::CENTER, _("Enter to accept"));
+ globalData.nf_button_font.draw(target, x+450, y+140, NFont::CENTER, _("Esc to cancel"));
DrawRectWhite(target, x+26, y+64, 54, 600-2*26);
NFont_Write(target, x+40, y+76,rk->GetString());
std::string strHolder = rk->GetString();
strHolder.erase((int)rk->CharsBeforeCursor());
if (((SDL_GetTicks()/600)%2)==1) {
- NFont_Write(target, x+40+nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
+ NFont_Write(target, x+40+globalData.nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
}
}
void DialogBox::ProcessInput(const SDL_Event& event, bool& processed) {
if (event.type == SDL_TEXTINPUT) {
- if ((rk->ReadKey(event))&&(SoundEnabled)&&(!NoSound)) {
- Mix_PlayChannel(1, typingChunk, 0);
+ if ((rk->ReadKey(event))&&(globalData.SoundEnabled)&&(!globalData.NoSound)) {
+ Mix_PlayChannel(1, globalData.typingChunk, 0);
}
}
@@ -129,8 +129,8 @@ void DialogBox::ProcessInput(const SDL_Event& event, bool& processed) {
isActive = false;
}
else {
- if ((rk->ReadKey(event))&&(SoundEnabled)&&(!NoSound)) {
- Mix_PlayChannel(1,typingChunk,0);
+ if ((rk->ReadKey(event))&&(globalData.SoundEnabled)&&(!globalData.NoSound)) {
+ Mix_PlayChannel(1, globalData.typingChunk, 0);
}
}
}
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 3227275..bad3237 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -42,9 +42,9 @@ const char* const menu_unmarked = "menu_unmarked";
ButtonGfx standardButton;
void ButtonGfx::setSurfaces() {
- this->xsize = spriteHolder->GetSprite(menu_marked).GetWidth();
- this->ysize = spriteHolder->GetSprite(menu_marked).GetHeight();
- if (verboseLevel) {
+ this->xsize = globalData.spriteHolder->GetSprite(menu_marked).GetWidth();
+ this->ysize = globalData.spriteHolder->GetSprite(menu_marked).GetHeight();
+ if (globalData.verboseLevel) {
cout << "Surfaces set, size: " << this->xsize << " , " << this->ysize << "\n";
}
}
@@ -92,13 +92,13 @@ bool Button::isPopOnRun() const {
static void drawToScreen(const Button &b) {
if (b.marked) {
- spriteHolder->GetSprite(menu_marked).Draw(screen, SDL_GetTicks(), b.x, b.y);
+ globalData.spriteHolder->GetSprite(menu_marked).Draw(globalData.screen, SDL_GetTicks(), b.x, b.y);
}
else {
- spriteHolder->GetSprite(menu_unmarked).Draw(screen, SDL_GetTicks(), b.x, b.y);
+ globalData.spriteHolder->GetSprite(menu_unmarked).Draw(globalData.screen, SDL_GetTicks(), b.x, b.y);
}
- standardButton.thefont->draw(screen, b.x+standardButton.xsize/2,b.y+standardButton.ysize/2-standardButton.thefont->getHeight("%s", b.label.c_str())/2, NFont::CENTER, "%s", b.label.c_str());
+ standardButton.thefont->draw(globalData.screen, b.x+standardButton.xsize/2,b.y+standardButton.ysize/2-standardButton.thefont->getHeight("%s", b.label.c_str())/2, NFont::CENTER, "%s", b.label.c_str());
}
@@ -116,7 +116,7 @@ void Menu::drawSelf() {
}
drawToScreen(exit);
standardButton.thefont->draw(screen, 50, 50, "%s", title.c_str());
- mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
+ globalData.mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
}
@@ -124,7 +124,7 @@ void Menu::placeButtons() {
int nextY = 100;
int X = 50;
for (Button* it : buttons) {
- X = (xsize - standardButton.xsize)/2;
+ X = (globalData.xsize - standardButton.xsize)/2;
it->x = X;
it->y = nextY;
nextY += standardButton.ysize+10;
@@ -301,7 +301,7 @@ void Menu::run() {
int oldmousex = mousex;
int oldmousey = mousey;
while (running && !Config::getInstance()->isShuttingDown()) {
- if (!(highPriority)) {
+ if (!(globalData.highPriority)) {
SDL_Delay(10);
}
SDL_Event event;
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 3efb349..9b80fa2 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp
@@ -32,15 +32,15 @@ using std::cerr;
using std::vector;
static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
- nf_standard_blue_font.draw(target, x, y, "%s", text);
+ globalData.nf_standard_blue_font.draw(target, x, y, "%s", text);
}
const int numberOfPages = 3;
void ScoresDisplay::DrawBackgroundAndCalcPlacements() {
- DrawBackground(screen);
- nextX = xsize-buttonXsize-20;
- backY = ysize-buttonYsize-20;
+ DrawBackground(globalData.screen);
+ nextX = globalData.xsize-buttonXsize-20;
+ backY = globalData.ysize-buttonYsize-20;
nextY = backY;
}
@@ -48,25 +48,25 @@ void ScoresDisplay::DrawBackgroundAndCalcPlacements() {
void ScoresDisplay::DrawHighscores(int x, int y, bool endless) {
DrawBackgroundAndCalcPlacements();
if (endless) {
- nf_standard_blue_font.draw(screen, x+100,y+100, "%s",_("Endless:") );
+ globalData.nf_standard_blue_font.draw(globalData.screen, x+100,y+100, "%s",_("Endless:") );
}
else {
- nf_standard_blue_font.draw(screen, x+100,y+100, "%s",_("Time Trial:") );
+ globalData.nf_standard_blue_font.draw(globalData.screen, x+100,y+100, "%s",_("Time Trial:") );
}
for (int i =0; i<10; i++) {
record r;
if (endless) {
- r = theTopScoresEndless.getScoreNumber(i);
+ r = globalData.theTopScoresEndless.getScoreNumber(i);
}
else {
- r = theTopScoresTimeTrial.getScoreNumber(i);
+ r = globalData.theTopScoresTimeTrial.getScoreNumber(i);
}
char playerScore[32];
char playerName[32];
snprintf(playerScore, sizeof(playerScore), "%i", r.score);
snprintf(playerName, sizeof(playerName), "%s", r.name.c_str());
- nf_standard_blue_font.draw(screen, x+420,y+150+i*35, "%s",playerScore);
- nf_standard_blue_font.draw(screen, x+60,y+150+i*35, "%s",playerName);
+ globalData.nf_standard_blue_font.draw(globalData.screen, x+420,y+150+i*35, "%s",playerScore);
+ globalData.nf_standard_blue_font.draw(globalData.screen, x+60,y+150+i*35, "%s",playerName);
}
}
@@ -74,60 +74,60 @@ void ScoresDisplay::DrawStats() {
DrawBackgroundAndCalcPlacements();
int y = 5;
const int y_spacing = 30;
- NFont_Write(screen, 10,y,_("Stats") );
+ NFont_Write(globalData.screen, 10,y,_("Stats") );
y+=y_spacing*2;
- NFont_Write(screen, 10,y,_("Chains") );
+ NFont_Write(globalData.screen, 10,y,_("Chains") );
for (int i=2; i<13; i++) {
y+=y_spacing;
- NFont_Write(screen, 10,y,(std::to_string(i)+"X").c_str());
+ NFont_Write(globalData.screen, 10,y,(std::to_string(i)+"X").c_str());
string numberAsString = std::to_string(Stats::getInstance()->getNumberOf("chainX"+std::to_string(i)));
- NFont_Write(screen, 300,y,numberAsString.c_str());
+ NFont_Write(globalData.screen, 300,y,numberAsString.c_str());
}
y+=y_spacing*2;
- NFont_Write(screen, 10,y,_("Lines Pushed: ") );
+ NFont_Write(globalData.screen, 10,y,_("Lines Pushed: ") );
string numberAsString = std::to_string(Stats::getInstance()->getNumberOf("linesPushed"));
- NFont_Write(screen, 300,y,numberAsString.c_str());
+ NFont_Write(globalData.screen, 300,y,numberAsString.c_str());
y+=y_spacing;
- NFont_Write(screen, 10,y, _("Puzzles solved: ") );
+ NFont_Write(globalData.screen, 10,y, _("Puzzles solved: ") );
numberAsString = std::to_string(Stats::getInstance()->getNumberOf("puzzlesSolved"));
- NFont_Write(screen, 300,y,numberAsString.c_str());
+ NFont_Write(globalData.screen, 300,y,numberAsString.c_str());
y+=y_spacing*2;
- NFont_Write(screen, 10,y, _("Run time: ") );
+ NFont_Write(globalData.screen, 10,y, _("Run time: ") );
commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks()));
y+=y_spacing;
- NFont_Write(screen, 10, y, SPrintCF( _("Days: %i"), ct.days) );
+ NFont_Write(globalData.screen, 10, y, SPrintCF( _("Days: %i"), ct.days) );
y+=y_spacing;
- NFont_Write(screen, 10, y, SPrintCF( _("Hours: %i"), ct.hours) );
+ NFont_Write(globalData.screen, 10, y, SPrintCF( _("Hours: %i"), ct.hours) );
y+=y_spacing;
- NFont_Write(screen, 10, y, SPrintCF( _("Minutes: %i"), ct.minutes) );
+ NFont_Write(globalData.screen, 10, y, SPrintCF( _("Minutes: %i"), ct.minutes) );
y+=y_spacing;
- NFont_Write(screen, 10, y, SPrintCF( _("Seconds: %i"), ct.seconds) );
+ NFont_Write(globalData.screen, 10, y, SPrintCF( _("Seconds: %i"), ct.seconds) );
y-=y_spacing*4; //Four rows back
- const int x_offset3 = xsize/3+10; //Ofset for three rows
- NFont_Write(screen, x_offset3,y, _("Play time: ") );
+ const int x_offset3 = globalData.xsize/3+10; //Ofset for three rows
+ NFont_Write(globalData.screen, x_offset3,y, _("Play time: ") );
ct = TimeHandler::getTime("playTime");
y+=y_spacing;
- NFont_Write(screen, x_offset3, y, SPrintCF( _("Days: %i"), ct.days) );
+ NFont_Write(globalData.screen, x_offset3, y, SPrintCF( _("Days: %i"), ct.days) );
y+=y_spacing;
- NFont_Write(screen, x_offset3, y, SPrintCF( _("Hours: %i"), ct.hours) );
+ NFont_Write(globalData.screen, x_offset3, y, SPrintCF( _("Hours: %i"), ct.hours) );
y+=y_spacing;
- NFont_Write(screen, x_offset3, y, SPrintCF( _("Minutes: %i"), ct.minutes) );
+ NFont_Write(globalData.screen, x_offset3, y, SPrintCF( _("Minutes: %i"), ct.minutes) );
y+=y_spacing;
- NFont_Write(screen, x_offset3, y, SPrintCF( _("Seconds: %i"), ct.seconds) );
+ NFont_Write(globalData.screen, x_offset3, y, SPrintCF( _("Seconds: %i"), ct.seconds) );
- const int x_offset = xsize/2+10;
+ const int x_offset = globalData.xsize/2+10;
y = 5+y_spacing*2;
- NFont_Write(screen, x_offset,y, _("VS CPU (win/loss)") );
+ NFont_Write(globalData.screen, x_offset,y, _("VS CPU (win/loss)") );
for (int i=0; i<7; i++) {
y += y_spacing;
- NFont_Write(screen, x_offset,y,string("AI "+std::to_string(i+1)).c_str());
+ NFont_Write(globalData.screen, x_offset,y,string("AI "+std::to_string(i+1)).c_str());
numberAsString = std::to_string(Stats::getInstance()->getNumberOf("defeatedAI"+std::to_string(i)));
string numberAsString2 = std::to_string(Stats::getInstance()->getNumberOf("defeatedByAI"+std::to_string(i)));
string toPrint = numberAsString + "/" + numberAsString2;
- NFont_Write(screen, x_offset+230,y,toPrint.c_str());
+ NFont_Write(globalData.screen, x_offset+230,y,toPrint.c_str());
}
}
@@ -157,15 +157,15 @@ void ScoresDisplay::Draw(SDL_Renderer*) {
};
//Draw buttons:
- bHighScore.Draw(screen, 0, scoreX,scoreY);
- bBack.Draw(screen, 0, backX, backY);
- nf_button_font.draw(screen, backX+60,backY+10, NFont::CENTER ,_("Back"));
- bNext.Draw(screen, 0, nextX, nextY);
- nf_button_font.draw(screen, nextX+60,nextY+10, NFont::CENTER,_("Next"));
+ globalData.bHighScore.Draw(globalData.screen, 0, scoreX,scoreY);
+ globalData.bBack.Draw(globalData.screen, 0, backX, backY);
+ globalData.nf_button_font.draw(globalData.screen, backX+60,backY+10, NFont::CENTER ,_("Back"));
+ globalData.bNext.Draw(globalData.screen, 0, nextX, nextY);
+ globalData.nf_button_font.draw(globalData.screen, nextX+60,nextY+10, NFont::CENTER,_("Next"));
//Draw page number
string pageXofY = (boost::format(_("Page %1% of %2%") )%(page+1)%numberOfPages).str();
- NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
+ NFont_Write(globalData.screen, globalData.xsize/2-globalData.nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2, globalData.ysize-60, pageXofY.c_str());
}
void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
diff --git a/source/code/global.hpp b/source/code/global.hpp index 10ada65..50506c1 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp
@@ -41,32 +41,36 @@ bool OpenDialogbox(int x, int y, std::string& name, const std::string& header);
void DrawBackground(SDL_Renderer* target);
void UpdateMouseCoordinates(const SDL_Event& event, int& mousex, int& mousey);
-extern sago::SagoSprite menuMarked;
-extern sago::SagoSprite menuUnmarked;
-extern sago::SagoSprite bHighScore;
-extern sago::SagoSprite bBack;
-extern sago::SagoSprite bNext;
-extern NFont nf_scoreboard_font;
-extern NFont nf_standard_blue_font;
-extern NFont nf_button_font;
-extern bool MusicEnabled; //true if background music is enabled
-extern bool SoundEnabled; //true if sound effects is enabled
-extern bool bFullscreen; //true if game is running fullscreen
-extern std::string player1name;
-extern std::string player2name;
-extern SDL_Renderer *screen; //The whole screen;
-extern Mix_Chunk *typingChunk;
-extern sago::SagoSprite mouse;
-extern bool highPriority;
-extern bool NoSound;
-extern int verboseLevel;
-extern Highscore theTopScoresEndless; //Stores highscores for endless
-extern Highscore theTopScoresTimeTrial; //Stores highscores for timetrial
-extern std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
+struct GlobalData {
+ sago::SagoSprite menuMarked;
+ sago::SagoSprite menuUnmarked;
+ sago::SagoSprite bHighScore;
+ sago::SagoSprite bBack;
+ sago::SagoSprite bNext;
+ NFont nf_scoreboard_font;
+ NFont nf_standard_blue_font;
+ NFont nf_button_font;
+ bool MusicEnabled; //true if background music is enabled
+ bool SoundEnabled; //true if sound effects is enabled
+ bool bFullscreen; //true if game is running fullscreen
+ std::string player1name;
+ std::string player2name;
+ SDL_Renderer *screen = nullptr; //The whole screen;
+ Mix_Chunk *typingChunk;
+ sago::SagoSprite mouse;
+ bool highPriority = false;
+ bool NoSound = false;
+ int verboseLevel = 0;
+ Highscore theTopScoresEndless; //Stores highscores for endless
+ Highscore theTopScoresTimeTrial; //Stores highscores for timetrial
+ std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
-//The xsize and ysize are updated everytime the background is drawn
-extern int xsize;
-extern int ysize;
+ //The xsize and ysize are updated everytime the background is drawn
+ int xsize = 1024;
+ int ysize = 768;
+};
+
+extern GlobalData globalData;
#endif /* _GLOBAL_HPP */
diff --git a/source/code/main.cpp b/source/code/main.cpp index d64becd..d2ebfb2 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -85,6 +85,7 @@ using std::cout;
using std::exception;
using std::vector;
+GlobalData globalData;
static int InitImages(sago::SagoSpriteHolder& holder);
@@ -120,8 +121,8 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
bricks[6] = holder.GetSprite("block_grey");
bomb = holder.GetSprite("block_bomb");
backgroundImage = holder.GetSprite("background");
- bHighScore = holder.GetSprite("b_highscore");
- bBack = holder.GetSprite("b_blank");
+ globalData.bHighScore = holder.GetSprite("b_highscore");
+ globalData.bBack = holder.GetSprite("b_blank");
bForward = holder.GetSprite("b_forward");
blackLine = holder.GetSprite("black_line");
stageBobble = holder.GetSprite("i_stage_clear_limit");
@@ -174,11 +175,11 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
transCover = holder.GetSprite("trans_cover");
bExit = holder.GetSprite("b_exit");
bSkip = holder.GetSprite("b_blank");
- bNext = holder.GetSprite("b_blank");
+ globalData.bNext = holder.GetSprite("b_blank");
bRetry = holder.GetSprite("b_blank");
- mouse = holder.GetSprite("mouse");
- menuMarked = holder.GetSprite("menu_marked");
- menuUnmarked = holder.GetSprite("menu_unmarked");
+ globalData.mouse = holder.GetSprite("mouse");
+ globalData.menuMarked = holder.GetSprite("menu_marked");
+ globalData.menuUnmarked = holder.GetSprite("menu_unmarked");
backBoard = holder.GetSprite("back_board");
SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color;
@@ -195,13 +196,13 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
nf_standard_small_color.g = 0;
nf_standard_small_color.r = 200;
nf_standard_small_color.a = 255;
- nf_button_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 24), nf_button_color);
- nf_standard_blue_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 30), nf_standard_blue_color);
- nf_standard_small_font.load(screen, holder.GetDataHolder().getFontPtr("freeserif", 16), nf_standard_small_color);
- nf_scoreboard_font.load(screen, holder.GetDataHolder().getFontPtr("penguinattack", 20), nf_button_color);
+ globalData.nf_button_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 24), nf_button_color);
+ globalData.nf_standard_blue_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 30), nf_standard_blue_color);
+ nf_standard_small_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 16), nf_standard_small_color);
+ globalData.nf_scoreboard_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("penguinattack", 20), nf_button_color);
//Loads the sound if sound present
- if (!NoSound) {
+ if (!globalData.NoSound) {
//And here the music:
bgMusic = holder.GetDataHolder().getMusicPtr("bgmusic");
highbeatMusic = holder.GetDataHolder().getMusicPtr("highbeat");
@@ -210,14 +211,14 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
boing = holder.GetDataHolder().getSoundPtr("pop");
applause = holder.GetDataHolder().getSoundPtr("applause");
photoClick = holder.GetDataHolder().getSoundPtr("cameraclick");
- typingChunk = holder.GetDataHolder().getSoundPtr("typing");
+ globalData.typingChunk = holder.GetDataHolder().getSoundPtr("typing");
counterChunk = holder.GetDataHolder().getSoundPtr("counter");
counterFinalChunk = holder.GetDataHolder().getSoundPtr("counter_final");
const int soundVolume = 84; //0-128
Mix_VolumeChunk(boing, soundVolume);
Mix_VolumeChunk(applause, soundVolume);
Mix_VolumeChunk(photoClick, soundVolume);
- Mix_VolumeChunk(typingChunk, soundVolume);
+ Mix_VolumeChunk(globalData.typingChunk, soundVolume);
Mix_VolumeChunk(counterChunk, soundVolume);
Mix_VolumeChunk(counterFinalChunk, soundVolume);
} //All sound has been loaded or not
@@ -240,29 +241,28 @@ void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x
static void NFont_Write(SDL_Renderer* target, int x, int y, const string& text) {
- nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
+ globalData.nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
}
static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
- nf_standard_blue_font.draw(target, x, y, "%s", text);
+ globalData.nf_standard_blue_font.draw(target, x, y, "%s", text);
}
SDL_Window* sdlWindow;
std::unique_ptr<sago::SagoDataHolder> dataHolder;
-std::unique_ptr<sago::SagoSpriteHolder> spriteHolder;
void ResetFullscreen() {
Mix_HaltMusic(); //We need to reload all data in case the screen type changes. Music must be stopped before unload.
- if (bFullscreen) {
+ if (globalData.bFullscreen) {
SDL_SetWindowFullscreen(sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
}
else {
SDL_SetWindowFullscreen(sdlWindow, 0);
}
- dataHolder.reset(new sago::SagoDataHolder(screen));
- spriteHolder.reset(new sago::SagoSpriteHolder( *(dataHolder.get()) ) );
- InitImages(*(spriteHolder.get()) );
+ dataHolder.reset(new sago::SagoDataHolder(globalData.screen));
+ globalData.spriteHolder.reset(new sago::SagoSpriteHolder( *(dataHolder.get()) ) );
+ InitImages(*(globalData.spriteHolder.get()) );
SDL_ShowCursor(SDL_DISABLE);
}
@@ -271,13 +271,13 @@ static bool logicalRenderer = false;
void DrawBackground(SDL_Renderer* target) {
SDL_RenderClear(target);
if (logicalRenderer) {
- xsize = 1024;
- ysize = 768;
+ globalData.xsize = 1024;
+ globalData.ysize = 768;
}
else {
- SDL_GetWindowSize(sdlWindow, &xsize, &ysize);
+ SDL_GetWindowSize(sdlWindow, &globalData.xsize, &globalData.ysize);
}
- backgroundImage.DrawScaled(target, SDL_GetTicks(), 0, 0, xsize, ysize);
+ backgroundImage.DrawScaled(target, SDL_GetTicks(), 0, 0, globalData.xsize, globalData.ysize);
}
/**
@@ -341,9 +341,9 @@ public:
if (y<1.0) {
velocityY=10.0;
}
- if ((velocityY>minVelocity) && (y>(ysize-ballSize)) && (y<ysize)) {
+ if ((velocityY>minVelocity) && (y>(globalData.ysize-ballSize)) && (y<globalData.ysize)) {
velocityY = -0.70*velocityY;
- y = ysize-ballSize;
+ y = globalData.ysize-ballSize;
}
lastTime = currentTime;
}
@@ -397,7 +397,7 @@ public:
if (ballUsed[i]) {
ballArray[i].update();
- if (ballArray[i].getY()>ysize+100 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize) {
+ if (ballArray[i].getY()>globalData.ysize+100 || ballArray[i].getX()>globalData.xsize || ballArray[i].getX()<-ballSize) {
ballUsed[i] = false;
}
}
@@ -589,18 +589,18 @@ static TextManager theTextManager;
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
void writeScreenShot() {
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Saving screenshot" << "\n";
}
int rightNow = (int)time(nullptr);
string buf = getPathToSaveFiles() + "/screenshots/screenshot"+std::to_string(rightNow)+".bmp";
SDL_Surface* sreenshotSurface = SDL_CreateRGBSurface(0, 1024, 768, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
- SDL_RenderReadPixels(screen, NULL, SDL_PIXELFORMAT_ARGB8888, sreenshotSurface->pixels, sreenshotSurface->pitch);
+ SDL_RenderReadPixels(globalData.screen, NULL, SDL_PIXELFORMAT_ARGB8888, sreenshotSurface->pixels, sreenshotSurface->pitch);
SDL_SaveBMP(sreenshotSurface, buf.c_str());
SDL_FreeSurface(sreenshotSurface);
- if (!NoSound) {
- if (SoundEnabled) {
- Mix_PlayChannel(1,photoClick,0);
+ if (!globalData.NoSound) {
+ if (globalData.SoundEnabled) {
+ Mix_PlayChannel(1, photoClick, 0);
}
}
}
@@ -616,7 +616,7 @@ void RunGameState(sago::GameStateInterface& state ) {
int mousex,mousey;
bool done = false; //We are done!
while (!done && !Config::getInstance()->isShuttingDown()) {
- state.Draw(screen);
+ state.Draw(globalData.screen);
SDL_Delay(1);
SDL_Event event;
@@ -641,8 +641,8 @@ void RunGameState(sago::GameStateInterface& state ) {
state.Update();
- mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
- SDL_RenderPresent(screen);
+ globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey);
+ SDL_RenderPresent(globalData.screen);
if (mustWriteScreenshot) {
writeScreenShot();
}
@@ -667,17 +667,17 @@ void OpenScoresDisplay() {
static void DrawBalls() {
for (int i = 0; i< maxNumberOfBalls; i++) {
if (theBallManager.ballUsed[i]) {
- DrawIMG(balls[theBallManager.ballArray[i].getColor()],screen,theBallManager.ballArray[i].getX(),theBallManager.ballArray[i].getY());
+ DrawIMG(balls[theBallManager.ballArray[i].getColor()],globalData.screen,theBallManager.ballArray[i].getX(),theBallManager.ballArray[i].getY());
} //if used
if (theExplosionManager.explosionUsed[i]) {
- DrawIMG(explosion[theExplosionManager.explosionArray[i].getFrame()],screen,theExplosionManager.explosionArray[i].getX(),theExplosionManager.explosionArray[i].getY());
+ 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;
- DrawIMG(iChainFrame,screen,x,y);
+ DrawIMG(iChainFrame,globalData.screen,x,y);
- nf_standard_small_font.draw(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",theTextManager.textArray[i].getText());
}
} //for
} //DrawBalls
@@ -686,20 +686,20 @@ static void DrawBalls() {
//draws everything
void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* theGame2) {
SDL_ShowCursor(SDL_DISABLE);
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
theGame->DoPaintJob();
theGame2->DoPaintJob();
string strHolder;
strHolder = std::to_string(theGame->GetScore()+theGame->GetHandicap());
- NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str());
if (theGame->GetAIenabled()) {
- NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") );
+ NFont_Write(globalData.screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") );
}
else if (editorMode || singlePuzzle) {
- NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") );
+ NFont_Write(globalData.screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") );
}
else {
- NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name);
+ NFont_Write(globalData.screen, theGame->GetTopX()+10,theGame->GetTopY()-34, globalData.player1name);
}
if (theGame->isTimeTrial()) {
int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt();
@@ -726,7 +726,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
- NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
}
else {
int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
@@ -743,27 +743,27 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
else {
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
- NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str());
}
strHolder = std::to_string(theGame->GetChains());
- NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str());
//drawspeedLevel:
strHolder = std::to_string(theGame->GetSpeedLevel());
- NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str());
if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY())) {
oldBubleX = theGame->GetTopX()+280;
oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1;
- DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
+ DrawIMG(stageBobble,globalData.screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1);
}
//player1 finnish, player2 start
- //DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
+ //DrawIMG(boardBackBack,globalData.screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68);
if (!editorMode /*&& !singlePuzzle*/ ) {
/*
*If single player mode (and not VS)
*/
if (!twoPlayers && !theGame->isGameOver()) {
//Blank player2's board:
- DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY());
+ DrawIMG(backBoard,globalData.screen,theGame2->GetTopX(),theGame2->GetTopY());
//Write a description:
string gametypeName;
string infostring;
@@ -785,32 +785,32 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
infostring = _("Score as much as possible. No time limit.");
}
if (infostring.length() > 0) {
- NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10, gametypeName);
- NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160, _("Objective:"));
- nf_standard_blue_font.drawBox(screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, "%s", infostring.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10, gametypeName);
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160, _("Objective:"));
+ globalData.nf_standard_blue_font.drawBox(globalData.screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, "%s", infostring.c_str());
}
//Write the keys that are in use
int y = theGame2->GetTopY()+400;
- NFont_Write(screen, theGame2->GetTopX()+7,y,_("Movement keys:") );
- NFont_Write(screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
- NFont_Write(screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
- NFont_Write(screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y,_("Movement keys:") );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() );
if (theGame->isPuzzleMode()) {
- NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() );
}
else {
- NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() );
}
}
strHolder = std::to_string(theGame2->GetScore()+theGame2->GetHandicap());
- NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str());
if (theGame2->GetAIenabled()) {
- NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") );
+ NFont_Write(globalData.screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") );
}
else {
- NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
+ NFont_Write(globalData.screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name);
}
if (theGame2->isTimeTrial()) {
int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt();
@@ -837,7 +837,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0);
- NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
}
else {
int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000;
@@ -854,18 +854,18 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
else {
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
- NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str());
}
strHolder = std::to_string(theGame2->GetChains());
- NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str());
strHolder = std::to_string(theGame2->GetSpeedLevel());
- NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
+ NFont_Write(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str());
}
//player2 finnish
//draw exit
- bExit.Draw(screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset);
+ bExit.Draw(globalData.screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset);
DrawBalls();
#if DEBUG
@@ -879,7 +879,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
Ticks = SDL_GetTicks();
}
- nf_standard_blue_font.draw(screen, 800, 4, "%s", FPS);
+ globalData.nf_standard_blue_font.draw(globalData.screen, 800, 4, "%s", FPS);
#endif
}
@@ -912,25 +912,25 @@ int PuzzleLevelSelect(int Type) {
}
while (!levelSelected) {
- DrawBackground(screen);
- DrawIMG(iCheckBoxArea,screen,xplace,yplace);
+ DrawBackground(globalData.screen);
+ DrawIMG(iCheckBoxArea,globalData.screen,xplace,yplace);
if (Type == 0) {
- NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") );
+ NFont_Write(globalData.screen, xplace+12,yplace+2,_("Select Puzzle") );
}
if (Type == 1) {
- NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
+ NFont_Write(globalData.screen, xplace+12,yplace+2, _("Stage Clear Level Select") );
}
//Now drow the fields you click in (and a V if clicked):
for (int i = 0; i < nrOfLevels; i++) {
- DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
+ DrawIMG(iLevelCheckBox,globalData.screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
if (i==selected) {
- DrawIMG(iLevelCheckBoxMarked,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
+ DrawIMG(iLevelCheckBoxMarked,globalData.screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
}
if (Type == 0 && PuzzleIsCleared(i)) {
- DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
+ DrawIMG(iLevelCheck,globalData.screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
}
if (Type == 1 && IsStageCleared(i)) {
- DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
+ DrawIMG(iLevelCheck,globalData.screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50);
}
}
@@ -1031,17 +1031,17 @@ int PuzzleLevelSelect(int Type) {
timeString = SPrintStringF(_("Time used: %d : %02d"), GetStageTime(selected)/1000/60, (GetStageTime(selected)/1000)%60);
}
- NFont_Write(screen, 200,200,scoreString.c_str());
- NFont_Write(screen, 200,250,timeString.c_str());
+ NFont_Write(globalData.screen, 200,200,scoreString.c_str());
+ NFont_Write(globalData.screen, 200,250,timeString.c_str());
string totalString = (boost::format(_("Total score: %1% in %2%:%3%"))%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str();
- NFont_Write(screen, 200,600,totalString.c_str());
+ NFont_Write(globalData.screen, 200,600,totalString.c_str());
}
- mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
- SDL_RenderPresent(screen); //draws it all to the screen
+ globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey);
+ SDL_RenderPresent(globalData.screen); //draws it all to the screen
}
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
return levelNr;
}
@@ -1064,8 +1064,8 @@ static void StartSinglePlayerEndless() {
a.action = BlockGameAction::Action::SET_GAME_OVER;
a.tick = startInfo.ticks;
player2->DoAction(a);
- player1->name = player1name;
- player2->name = player2name;
+ player1->name = globalData.player1name;
+ player2->name = globalData.player2name;
registerEndlessHighscore = true;
}
@@ -1080,8 +1080,8 @@ static void StartSinglePlayerTimeTrial() {
a.tick = startInfo.ticks;
player2->DoAction(a);
//vsMode = false;
- player1->name = player1name;
- player2->name = player2name;
+ player1->name = globalData.player1name;
+ player2->name = globalData.player2name;
registerTTHighscorePlayer1 = true;
saveReplay = true;
}
@@ -1095,15 +1095,15 @@ static int StartSinglePlayerPuzzle() {
return 1;
}
player1->NewGame(startInfo);
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
twoPlayers = false;
BlockGameAction a;
a.action = BlockGameAction::Action::SET_GAME_OVER;
a.tick = startInfo.ticks;
player2->DoAction(a);
//vsMode = true;
- player1->name = player1name;
- player2->name = player2name;
+ player1->name = globalData.player1name;
+ player2->name = globalData.player2name;
return 0;
}
@@ -1132,8 +1132,8 @@ static void StarTwoPlayerTimeTrial() {
player1->NewGame(startInfo);
player2->NewGame(startInfo2);
twoPlayers = true;
- player1->name = player1name;
- player2->name = player2name;
+ player1->name = globalData.player1name;
+ player2->name = globalData.player2name;
}
static void StartTwoPlayerVs() {
@@ -1159,13 +1159,13 @@ static void StartTwoPlayerVs() {
player2->NewGame(startInfo2);
//vsMode = true;
twoPlayers = true;
- player1->name = player1name;
- player2->name = player2name;
+ player1->name = globalData.player1name;
+ player2->name = globalData.player2name;
}
static void MoveBlockGameSdls( BlockGameSdl& game1, BlockGameSdl& game2 ) {
game1.SetTopXY(50, 100);
- game2.SetTopXY(xsize-500,100);
+ game2.SetTopXY(globalData.xsize-500, 100);
}
struct globalConfig {
@@ -1256,13 +1256,13 @@ static void ParseArguments(int argc, char* argv[], globalConfig& conf) {
exit(0);
}
if (vm.count("nosound")) {
- NoSound = true;
+ globalData.NoSound = true;
}
if (vm.count("priority")) {
- highPriority = true;
+ globalData.highPriority = true;
}
if (vm.count("verbose-basic")) {
- verboseLevel++;
+ globalData.verboseLevel++;
}
if (vm.count("verbose-game-controller")) {
GameControllerSetVerbose(true);
@@ -1296,8 +1296,8 @@ int main(int argc, char* argv[]) {
config.puzzleName = "puzzle.levels";
FsSearchParthMainAppend(config.search_paths);
config.savepath = getPathToSaveFiles();
- highPriority = false; //if true the game will take most resources, but increase framerate.
- bFullscreen = false;
+ globalData.highPriority = false; //if true the game will take most resources, but increase framerate.
+ globalData.bFullscreen = false;
//Set default Config variables:
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -1308,11 +1308,11 @@ int main(int argc, char* argv[]) {
PhysFsSetSearchPath(config.search_paths, config.savepath);
//Os create folders must be after the paramters because they can change the home folder
PhysFsCreateFolders();
- SoundEnabled = true;
- MusicEnabled = true;
+ globalData.SoundEnabled = true;
+ globalData.MusicEnabled = true;
twoPlayers = false; //true if two players splitscreen
- theTopScoresEndless = Highscore("endless");
- theTopScoresTimeTrial = Highscore("timetrial");
+ globalData.theTopScoresEndless = Highscore("endless");
+ globalData.theTopScoresTimeTrial = Highscore("timetrial");
drawBalls = true;
puzzleLoaded = false;
theBallManager = BallManager();
@@ -1331,17 +1331,17 @@ int main(int argc, char* argv[]) {
theTextManager = TextManager();
//Open Audio
- if (!NoSound) {
+ if (!globalData.NoSound) {
//If sound has not been disabled, then load the sound system
if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0) {
cerr << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << "\n"
<< "Sound will be disabled!" << "\n";
- NoSound = true; //Tries to stop all sound from playing/loading
+ globalData.NoSound = true; //Tries to stop all sound from playing/loading
}
}
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
//Copyright notice:
cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << "\n" << "http://www.blockattack.net" << "\n" << "Copyright 2004-2016 Poul Sander" << "\n" <<
"A SDL2 based game (see www.libsdl.org)" << "\n" <<
@@ -1364,16 +1364,16 @@ int main(int argc, char* argv[]) {
keySettings[player2keys].change = SDLK_LCTRL;
keySettings[player2keys].push = SDLK_LSHIFT;
- player1name = _("Player 1");
- player2name = _("Player 2");
+ globalData.player1name = _("Player 1");
+ globalData.player2name = _("Player 2");
Config* configSettings = Config::getInstance();
//configSettings->setString("aNumber"," A string");
//configSettings->save();
if (configSettings->exists("fullscreen")) { //Test if an configFile exists
- bFullscreen = (bool)configSettings->getInt("fullscreen");
- MusicEnabled = (bool)configSettings->getInt("musicenabled");
- SoundEnabled = (bool)configSettings->getInt("soundenabled");
+ globalData.bFullscreen = (bool)configSettings->getInt("fullscreen");
+ globalData.MusicEnabled = (bool)configSettings->getInt("musicenabled");
+ globalData.SoundEnabled = (bool)configSettings->getInt("soundenabled");
if (configSettings->exists("sdl2_player1keyup")) {
keySettings[0].up = (SDL_Keycode)configSettings->getInt("sdl2_player1keyup");
@@ -1413,17 +1413,17 @@ int main(int argc, char* argv[]) {
keySettings[2].push = (SDL_Keycode)configSettings->getInt("sdl2_player2keypush");
}
if (configSettings->exists("player1name")) {
- player1name = configSettings->getString("player1name");
+ globalData.player1name = configSettings->getString("player1name");
}
if (configSettings->exists("player2name")) {
- player2name = configSettings->getString("player2name");
+ globalData.player2name = configSettings->getString("player2name");
}
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Data loaded from config file" << "\n";
}
}
else {
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Unable to load options file, using default values" << "\n";
}
}
@@ -1438,25 +1438,25 @@ int main(int argc, char* argv[]) {
sdlWindow = SDL_CreateWindow("Block Attack - Rise of the Blocks " VERSION_NUMBER,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
- xsize, ysize,
+ globalData.xsize, globalData.ysize,
createWindowParams );
dieOnNullptr(sdlWindow, "Unable to create window");
SDL_Renderer* renderer = SDL_CreateRenderer(sdlWindow, -1, 0);
dieOnNullptr(renderer, "Unable to create render");
if (config.autoScale) {
- SDL_RenderSetLogicalSize(renderer, xsize, ysize);
+ SDL_RenderSetLogicalSize(renderer, globalData.xsize, globalData.ysize);
logicalRenderer = true;
}
- screen = renderer;
+ globalData.screen = renderer;
ResetFullscreen();
SetSDLIcon(sdlWindow);
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Images loaded" << "\n";
}
- BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects
- BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
+ BlockGameSdl theGame = BlockGameSdl(50, 100); //creates game objects
+ BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500, 100);
player1 = &theGame;
player2 = &theGame2;
@@ -1467,8 +1467,8 @@ int main(int argc, char* argv[]) {
//Takes names from file instead
- theGame.name = player1name;
- theGame2.name = player2name;
+ theGame.name = globalData.player1name;
+ theGame2.name = globalData.player2name;
if (singlePuzzle) {
LoadPuzzleStages();
@@ -1478,10 +1478,10 @@ int main(int argc, char* argv[]) {
s.singlePuzzle = true;
theGame.NewGame(s);
}
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
MoveBlockGameSdls(theGame, theGame2);
- DrawEverything(xsize,ysize,&theGame,&theGame2);
- SDL_RenderPresent(screen);
+ DrawEverything(globalData.xsize, globalData.ysize, &theGame, &theGame2);
+ SDL_RenderPresent(globalData.screen);
if (singlePuzzle) {
runGame(Gametype::Puzzle, singlePuzzleNr);
}
@@ -1494,9 +1494,9 @@ int main(int argc, char* argv[]) {
//Saves options
if (!editorMode) {
- configSettings->setInt("fullscreen",(int)bFullscreen);
- configSettings->setInt("musicenabled",(int)MusicEnabled);
- configSettings->setInt("soundenabled",(int)SoundEnabled);
+ configSettings->setInt("fullscreen",(int)globalData.bFullscreen);
+ configSettings->setInt("musicenabled",(int)globalData.MusicEnabled);
+ configSettings->setInt("soundenabled",(int)globalData.SoundEnabled);
configSettings->setInt("sdl2_player1keyup",(int)keySettings[0].up);
configSettings->setInt("sdl2_player1keydown",(int)keySettings[0].down);
@@ -1512,8 +1512,8 @@ int main(int argc, char* argv[]) {
configSettings->setInt("sdl2_player2keychange",(int)keySettings[2].change);
configSettings->setInt("sdl2_player2keypush",(int)keySettings[2].push);
- configSettings->setString("player1name",player1name);
- configSettings->setString("player2name",player2name);
+ configSettings->setString("player1name", globalData.player1name);
+ configSettings->setString("player2name", globalData.player2name);
configSettings->save();
}
@@ -1521,12 +1521,12 @@ int main(int argc, char* argv[]) {
//int hours, mins, secs,
commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << "\n";
}
ct = TimeHandler::addTime("totalTime",ct);
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << "\n";
}
@@ -1544,8 +1544,8 @@ int main(int argc, char* argv[]) {
int runGame(Gametype gametype, int level) {
int mousex, mousey; //Mouse coordinates
- theTopScoresEndless = Highscore("endless");
- theTopScoresTimeTrial = Highscore("timetrial");
+ globalData.theTopScoresEndless = Highscore("endless");
+ globalData.theTopScoresTimeTrial = Highscore("timetrial");
drawBalls = true;
puzzleLoaded = false;
bool bNearDeath = false; //Play music faster or louder while tru
@@ -1553,7 +1553,7 @@ int runGame(Gametype gametype, int level) {
theBallManager = BallManager();
theExplosionManager = ExplosionManager();
BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects
- BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100);
+ BlockGameSdl theGame2 = BlockGameSdl(globalData.xsize-500,100);
player1 = &theGame;
player2 = &theGame2;
theGame.DoPaintJob(); //Makes sure what there is something to paint
@@ -1564,8 +1564,8 @@ int runGame(Gametype gametype, int level) {
theGame2.DoAction(a);
//Takes names from file instead
- theGame.name = player1name;
- theGame2.name = player2name;
+ theGame.name = globalData.player1name;
+ theGame2.name = globalData.player2name;
bool mustsetupgame = true;
@@ -1580,7 +1580,7 @@ int runGame(Gametype gametype, int level) {
}
//game loop
int done = 0;
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << "Starting game loop" << "\n";
}
@@ -1604,13 +1604,13 @@ int runGame(Gametype gametype, int level) {
s.stageClear = true;
s.level = myLevel;
theGame.NewGame(s);
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
twoPlayers =false;
BlockGameAction a;
a.action = BlockGameAction::Action::SET_GAME_OVER;
theGame2.DoAction(a);
- theGame.name = player1name;
- theGame2.name = player2name;
+ theGame.name = globalData.player1name;
+ theGame2.name = globalData.player2name;
}
break;
case Gametype::Puzzle:
@@ -1630,10 +1630,10 @@ int runGame(Gametype gametype, int level) {
theGame.NewGame(startInfo);
startInfo.AI = true;
theGame2.NewGame(startInfo);
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
twoPlayers = true; //Single player, but AI plays
- theGame.name = player1name;
- theGame2.name = player2name;
+ theGame.name = globalData.player1name;
+ theGame2.name = globalData.player2name;
}
break;
case Gametype::TwoPlayerTimeTrial:
@@ -1647,17 +1647,17 @@ int runGame(Gametype gametype, int level) {
StartSinglePlayerEndless();
};
mustsetupgame = false;
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
MoveBlockGameSdls(theGame, theGame2);
- DrawEverything(xsize,ysize,&theGame,&theGame2);
- SDL_RenderPresent(screen);
+ DrawEverything(globalData.xsize, globalData.ysize, &theGame, &theGame2);
+ SDL_RenderPresent(globalData.screen);
}
- if (!(highPriority)) {
+ if (!(globalData.highPriority)) {
SDL_Delay(1);
}
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
//updates the balls and explosions:g
theBallManager.update();
theExplosionManager.update();
@@ -1685,7 +1685,7 @@ int runGame(Gametype gametype, int level) {
if ( event.type == SDL_KEYDOWN ) {
if ( event.key.keysym.sym == SDLK_ESCAPE || ( event.key.keysym.sym == SDLK_RETURN && theGame.isGameOver() ) ) {
done=1;
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
}
if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled())) {
//player1:
@@ -1941,7 +1941,7 @@ int runGame(Gametype gametype, int level) {
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
//This is the mouse events
bMouseUp = false;
- DrawBackground(screen);
+ DrawBackground(globalData.screen);
if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x)
&&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize)
@@ -1957,8 +1957,8 @@ int runGame(Gametype gametype, int level) {
retryLevel(theGame, SDL_GetTicks());
}
- if (mousex > xsize-bExitOffset && mousex < xsize-bExitOffset+bExitSize &&
- mousey > ysize-bExitOffset && mousey < ysize-bExitOffset+bExitSize) {
+ if (mousex > globalData.xsize-bExitOffset && mousex < globalData.xsize-bExitOffset+bExitSize &&
+ mousey > globalData.ysize-bExitOffset && mousey < globalData.ysize-bExitOffset+bExitSize) {
done = 1;
}
//cout << "Mouse x: " << mousex << ", mouse y: " << mousey << "\n";
@@ -1973,7 +1973,7 @@ int runGame(Gametype gametype, int level) {
//Sees if music is stopped and if music is enabled
- if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath)) {
+ if ((!globalData.NoSound)&&(!Mix_PlayingMusic())&&(globalData.MusicEnabled)&&(!bNearDeath)) {
// then starts playing it.
Mix_PlayMusic(bgMusic, -1); //music loop
Mix_VolumeMusic((MIX_MAX_VOLUME*3)/10);
@@ -1981,13 +1981,13 @@ int runGame(Gametype gametype, int level) {
if (bNearDeath!=bNearDeathPrev) {
if (bNearDeath) {
- if (!NoSound &&(MusicEnabled)) {
+ if (!globalData.NoSound &&(globalData.MusicEnabled)) {
Mix_PlayMusic(highbeatMusic, 1);
Mix_VolumeMusic((MIX_MAX_VOLUME*5)/10);
}
}
else {
- if (!NoSound &&(MusicEnabled)) {
+ if (!globalData.NoSound &&(globalData.MusicEnabled)) {
Mix_PlayMusic(bgMusic, -1);
Mix_VolumeMusic((MIX_MAX_VOLUME*3)/10);
}
@@ -2058,15 +2058,15 @@ int runGame(Gametype gametype, int level) {
if (theGame.isGameOver() && registerTTHighscorePlayer1) {
registerTTHighscorePlayer1 = false;
- theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore());
+ globalData.theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore());
}
if (theGame2.isGameOver() && registerTTHighscorePlayer2) {
registerTTHighscorePlayer2 = false;
- theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
+ globalData.theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
}
if (theGame.isGameOver() && registerEndlessHighscore) {
registerEndlessHighscore = false;
- theTopScoresEndless.addScore(theGame.name, theGame.GetScore());
+ globalData.theTopScoresEndless.addScore(theGame.name, theGame.GetScore());
theGame.EndlessHighscoreEvent();
}
if (theGame.isGameOver() && saveReplay) {
@@ -2082,10 +2082,10 @@ int runGame(Gametype gametype, int level) {
//Once evrything has been checked, update graphics
MoveBlockGameSdls(theGame, theGame2);
- DrawEverything(xsize,ysize,&theGame,&theGame2);
+ DrawEverything(globalData.xsize, globalData.ysize, &theGame, &theGame2);
//Draw the mouse:
- mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
- SDL_RenderPresent(screen);
+ globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), mousex, mousey);
+ SDL_RenderPresent(globalData.screen);
if (mustWriteScreenshot) {
writeScreenShot();
}
diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index 7d227c4..41f449e 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc
@@ -46,14 +46,12 @@ const char sharedir[] = SHAREDIR;
//All graphic in the game (as pointers):
sago::SagoSprite backgroundImage; //Stores the background image
static sago::SagoSprite backBoard; //Stores the background to the board
-sago::SagoSprite bBack; //The "Back" button
static sago::SagoSprite bForward; //The "forward" button
#if NETWORK
//static sago::SagoSprite bNetwork;
//static sago::SagoSprite bConnect;
//static sago::SagoSprite bHost;
#endif
-sago::SagoSprite bHighScore; //The High Score botton
static sago::SagoSprite blackLine; //The seperator in stage clear
static sago::SagoSprite stageBobble; //The bobble instage clear
SDL_Renderer *screen; //The whole screen;
@@ -96,18 +94,10 @@ static sago::SagoSprite garbageGMR;
static sago::SagoSprite transCover; //The transperant block, covers the upcomming
static sago::SagoSprite bSkip;
static sago::SagoSprite bRetry;
-sago::SagoSprite bNext;
static sago::SagoSprite bExit;
const int bExitSize = 100; //height and width of the exit button
const int bExitOffset = 140; //pixels from the buttom right corner to the top left of the exit button
-sago::SagoSprite menuMarked;
-sago::SagoSprite menuUnmarked;
-sago::SagoSprite mouse;
-
-NFont nf_button_font; //Font used for buttons!
-NFont nf_scoreboard_font;
-NFont nf_standard_blue_font; //Font used instead of the old blue SFont
static NFont nf_standard_small_font;
static Mix_Music *bgMusic; //backgroundMusic
@@ -115,27 +105,17 @@ static Mix_Music *highbeatMusic; //Background music with higher beat
static Mix_Chunk *boing; //boing sound when clearing
static Mix_Chunk *applause; //Applause, then the player is good
static Mix_Chunk *photoClick; //clickSound
-Mix_Chunk *typingChunk; //When writing
static Mix_Chunk *counterChunk; //When counting down
static Mix_Chunk *counterFinalChunk;
-Highscore theTopScoresEndless; //Stores highscores for endless
-Highscore theTopScoresTimeTrial; //Stores highscores for timetrial
-
static bool bMouseUp; //true if the mouse(1) is unpressed
static bool bMouseUp2; //true if the mouse(2) is unpressed
#if NETWORK
static bool bNetworkOpen; //Show the network menu
#endif
-bool NoSound; //if true, absolutely no sound will be played, can be set from the commandline
-//prevents crash on systems without a soundcard
-bool MusicEnabled; //true if background music is enabled
-bool SoundEnabled; //true if sound effects is enabled
static bool bNearDeathPrev; //Near death status last time checked.
-bool bFullscreen; //true if game is running fullscreen
static bool puzzleLoaded; //true if the puzzle levels have been loaded
static bool drawBalls; //if true balls are drawed to the screen, this might lower framerate too much
-bool highPriority;
static bool editorMode = false;
static bool editorModeTest = false;
@@ -160,13 +140,6 @@ static Uint8 player2handicap=0;
unsigned long int currentTime; //contains the current time, so we don't call SDL_GetTickets() too often...
-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;
-std::string player2name;
-
bool twoPlayers; //True if two players are playing
//Old Stage Clear Buble
@@ -183,7 +156,6 @@ unsigned long int Frames, Ticks;
char FPS[10];
#endif
-int verboseLevel = 0;
//keySetup
const int player1keys = 0;
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 15a450d..7d1d0f0 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -54,7 +54,7 @@ extern control keySettings[3];
//Function to return the name of a key, to be displayed...
static string getKeyName(SDL_Keycode key) {
string keyname(SDL_GetKeyName(key));
- if (verboseLevel) {
+ if (globalData.verboseLevel) {
cout << key << " translated to " << keyname << "\n";
}
return keyname;
@@ -96,7 +96,7 @@ void Button_changekey::doAction() {
void InitMenues() {
standardButton.setSurfaces();
- standardButton.thefont = &nf_button_font;
+ standardButton.thefont = &globalData.nf_button_font;
}
static void runSinglePlayerEndless() {
@@ -131,35 +131,35 @@ static void runTwoPlayerVs() {
class MusicButton : public Button {
virtual void doAction() override {
- MusicEnabled = !MusicEnabled;
- setLabel(MusicEnabled? _("Music: On") : _("Music: Off"));
+ globalData.MusicEnabled = !globalData.MusicEnabled;
+ setLabel(globalData.MusicEnabled? _("Music: On") : _("Music: Off"));
}
};
class SoundButton : public Button {
virtual void doAction() override {
- SoundEnabled = !SoundEnabled;
- setLabel(SoundEnabled? _("Sound: On") : _("Sound: Off") );
+ globalData.SoundEnabled = !globalData.SoundEnabled;
+ setLabel(globalData.SoundEnabled? _("Sound: On") : _("Sound: Off") );
}
};
class FullscreenButton : public Button {
virtual void doAction() override {
- bFullscreen = !bFullscreen;
- setLabel(bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
+ globalData.bFullscreen = !globalData.bFullscreen;
+ setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
ResetFullscreen();
}
};
static void buttonActionPlayer1Name() {
- if ( OpenDialogbox(200, 100, player1name, _("Enter player 1 name:")) ) {
+ if ( OpenDialogbox(200, 100, globalData.player1name, _("Enter player 1 name:")) ) {
return; //must save if true
}
}
static void buttonActionPlayer2Name() {
- if ( OpenDialogbox(200, 100, player2name, _("Enter player 2 name:")) ) {
+ if ( OpenDialogbox(200, 100, globalData.player2name, _("Enter player 2 name:")) ) {
return; //must save if true
}
}
@@ -169,7 +169,7 @@ static void buttonActionHighscores() {
}
static void ChangeKeysMenu(long playernumber) {
- Menu km(screen,_("Change key bindings"),true);
+ Menu km(globalData.screen,_("Change key bindings"),true);
Button_changekey bLeft(&keySettings[playernumber].left,_("Left") );
Button_changekey bRight(&keySettings[playernumber].right,_("Right") );
Button_changekey bUp(&keySettings[playernumber].up,_("Up") );
@@ -194,15 +194,15 @@ static void ChangeKeysMenu2() {
}
static void ConfigureMenu() {
- Menu cm(screen,_("Configuration"),true);
+ Menu cm(globalData.screen,_("Configuration"),true);
Button bPlayer1Name,bPlayer2Name;
Button bPlayer1Keys, bPlayer2Keys;
MusicButton bMusic;
SoundButton bSound;
FullscreenButton buttonFullscreen;
- bMusic.setLabel(MusicEnabled? _("Music: On") : _("Music: Off") );
- bSound.setLabel(SoundEnabled? _("Sound: On") : _("Sound: Off") );
- buttonFullscreen.setLabel(bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
+ bMusic.setLabel(globalData.MusicEnabled? _("Music: On") : _("Music: Off") );
+ bSound.setLabel(globalData.SoundEnabled? _("Sound: On") : _("Sound: Off") );
+ buttonFullscreen.setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
bPlayer1Name.setAction(buttonActionPlayer1Name);
bPlayer1Name.setLabel(_("Change player 1's name") );
bPlayer2Name.setAction(buttonActionPlayer2Name);
@@ -222,7 +222,7 @@ static void ConfigureMenu() {
}
static void SinglePlayerVsMenu() {
- Menu spvs(screen,_("Single player VS"),true);
+ Menu spvs(globalData.screen,_("Single player VS"),true);
RunSinglePlayerVsButton d1,d2,d3,d4,d5,d6,d7;
d1.setPopOnRun(true);
d2.setPopOnRun(true);
@@ -256,7 +256,7 @@ static void SinglePlayerVsMenu() {
}
static void MultiplayerMenu() {
- Menu mm(screen,_("Multiplayer"),true);
+ Menu mm(globalData.screen,_("Multiplayer"),true);
Button bTT, bVs;
bTT.setLabel(_("Two player - time trial"));
bTT.setAction(runTwoPlayerTimeTrial);
@@ -269,7 +269,7 @@ static void MultiplayerMenu() {
void MainMenu() {
InitMenues();
- Menu m(screen,_("Block Attack - Rise of the blocks"),false);
+ Menu m(globalData.screen,_("Block Attack - Rise of the blocks"),false);
Button bHi,bTimetrial1, bStageClear, bPuzzle, bVs1, bMulti, bConfigure,bHighscore;
bHi.setLabel(_("Single player - endless") );
bHi.setAction(runSinglePlayerEndless);