diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index bbda1ff..016bd9f 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp @@ -64,7 +64,7 @@ int BlockGame::firstUnusedChain() //Constructor BlockGame::BlockGame() { - srand((int)time(NULL)); + srand((int)time(nullptr)); nrFellDown = 0; nrPushedPixel = 0; garbageTarget = this; diff --git a/source/code/CppSdlImageHolder.cpp b/source/code/CppSdlImageHolder.cpp index be8fde0..5d4a6f1 100644 --- a/source/code/CppSdlImageHolder.cpp +++ b/source/code/CppSdlImageHolder.cpp @@ -30,7 +30,7 @@ namespace CppSdl CppSdlImageHolder::CppSdlImageHolder() { - data = NULL; + data = nullptr; } CppSdlImageHolder::CppSdlImageHolder(std::string filename) @@ -77,23 +77,26 @@ SDL_Surface* CppSdlImageHolder::GetRawDataInsecure() Uint32 CppSdlImageHolder::GetWidth() { - if (IsNull()) + if (IsNull()) { return 0; + } return area.w; } Uint32 CppSdlImageHolder::GetHeight() { - if(IsNull()) + if(IsNull()) { return 0; + } return area.h; } void CppSdlImageHolder::PaintTo(SDL_Surface* target, int x, int y) { static SDL_Rect dest; //static for reuse - if(IsNull()) + if(IsNull()) { return; + } dest.x = x; dest.y = y; SDL_BlitSurface(data,&area, target,&dest); @@ -103,24 +106,26 @@ void CppSdlImageHolder::OptimizeForBlit(bool allowAlpha) { static SDL_Surface *tmp; Initialized(); - if(allowAlpha) + if(allowAlpha) { tmp = SDL_DisplayFormatAlpha(data); - else + } + else { tmp = SDL_DisplayFormat(data); + } SDL_FreeSurface(data); data = tmp; } void CppSdlImageHolder::Initialized() { - if(data == NULL) { + if(data == nullptr) { throw std::runtime_error("ImageHolder used uninitialized!"); } } bool CppSdlImageHolder::IsNull() { - if(data == NULL ) { + if(data == nullptr ) { return true; } return false; @@ -128,10 +133,11 @@ bool CppSdlImageHolder::IsNull() void CppSdlImageHolder::MakeNull() { - if(IsNull()) + if(IsNull()) { return; + } SDL_FreeSurface(data); - data = NULL; + data = nullptr; } } diff --git a/source/code/Libs/NFont.cpp b/source/code/Libs/NFont.cpp index 19108ac..d47f7d1 100644 --- a/source/code/Libs/NFont.cpp +++ b/source/code/Libs/NFont.cpp @@ -46,17 +46,21 @@ void NFont::setAnimData(void* data) void NFont::setBuffer(unsigned int size) { delete[] buffer; - if(size > 0) + if(size > 0) { buffer = new char[size]; - else + } + else { buffer = new char[1024]; + } } // Static functions char* NFont::copyString(const char* c) { - if(c == NULL) return NULL; + if(c == NULL) { + return NULL; + } int count = 0; for(; c[count] != '\0'; count++); @@ -77,8 +81,9 @@ Uint32 NFont::getPixel(SDL_Surface *Surface, int x, int y) // No Alpha? Uint8* bits; Uint32 bpp; - if(x < 0 || x >= Surface->w) - return 0; // Best I could do for errors + if(x < 0 || x >= Surface->w) { + return 0; // Best I could do for errors + } bpp = Surface->format->BytesPerPixel; bits = ((Uint8*)Surface->pixels) + y*Surface->pitch + x*bpp; @@ -126,8 +131,9 @@ SDL_Surface* NFont::copySurface(SDL_Surface *Surface) SDL_Surface* NFont::verticalGradient(SDL_Surface* targetSurface, Uint32 top, Uint32 bottom, int heightAdjust) { SDL_Surface* surface = targetSurface; - if(surface == NULL) + if(surface == NULL) { return NULL; + } Uint8 tr, tg, tb; @@ -152,8 +158,9 @@ SDL_Surface* NFont::verticalGradient(SDL_Surface* targetSurface, Uint32 top, Uin x = 0; y++; - if (y >= surface->h) + if (y >= surface->h) { break; + } } ratio = (y - 2)/float(surface->h - heightAdjust); // the neg 3s are for full color at top and bottom @@ -163,8 +170,9 @@ SDL_Surface* NFont::verticalGradient(SDL_Surface* targetSurface, Uint32 top, Uin color = getPixel(surface, x, y); SDL_GetRGBA(color, surface->format, &r, &g, &b, &a); // just getting alpha } - else + else { a = SDL_ALPHA_OPAQUE; + } // Get and clamp the new values temp = int(tr*(1-ratio) + br*ratio); @@ -182,17 +190,21 @@ SDL_Surface* NFont::verticalGradient(SDL_Surface* targetSurface, Uint32 top, Uin if(useCK) { - if(getPixel(surface, x, y) == colorkey) + if(getPixel(surface, x, y) == colorkey) { continue; - if(color == colorkey) + } + if(color == colorkey) { color == 0? color++ : color--; + } } // make sure it isn't pink - if(color == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, a)) + if(color == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, a)) { color--; - if(getPixel(surface, x, y) == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, SDL_ALPHA_OPAQUE)) + } + if(getPixel(surface, x, y) == SDL_MapRGBA(surface->format, 0xFF, 0, 0xFF, SDL_ALPHA_OPAQUE)) { continue; + } int bpp = surface->format->BytesPerPixel; Uint8* bits = ((Uint8 *)surface->pixels) + y*surface->pitch + x*bpp; @@ -310,8 +322,9 @@ void NFont::init() lineSpacing = 0; letterSpacing = 0; - if(buffer == NULL) + if(buffer == NULL) { buffer = new char[1024]; + } } NFont::~NFont() @@ -350,11 +363,13 @@ bool NFont::load(SDL_Surface* FontSurface) { charPos[i] = x; charWidth[i] = x; - while(x < src->w && getPixel(src, x, 0) != pixel) + while(x < src->w && getPixel(src, x, 0) != pixel) { x++; + } charWidth[i] = x - charWidth[i]; - if(charWidth[i] > maxWidth) + if(charWidth[i] > maxWidth) { maxWidth = charWidth[i]; + } i++; } @@ -414,8 +429,9 @@ bool NFont::load(SDL_Surface* FontSurface) SDL_UnlockSurface(src); SDL_SetColorKey(src, SDL_SRCCOLORKEY, pixel); } - else + else { SDL_UnlockSurface(src); + } return true; } @@ -429,8 +445,9 @@ bool NFont::load(SDL_Surface* destSurface, SDL_Surface* FontSurface) #ifdef NFONT_USE_TTF bool NFont::load(TTF_Font* ttf, SDL_Color fg, SDL_Color bg) { - if(ttf == NULL) + if(ttf == NULL) { return false; + } SDL_Surface* surfs[127 - 33]; int width = 0; int height = 0; @@ -455,7 +472,7 @@ bool NFont::load(TTF_Font* ttf, SDL_Color fg, SDL_Color bg) SDL_Rect pixel = {1, 0, 1, 1}; SDL_Rect line = {1, 0, 1, static_cast(result->h)}; - + int x = 1; SDL_Rect dest = {static_cast(x), 0, 0, 0}; for(int i = 0; i < 127 - 33; i++) @@ -481,8 +498,9 @@ bool NFont::load(TTF_Font* ttf, SDL_Color fg, SDL_Color bg) bool NFont::load(TTF_Font* ttf, SDL_Color fg) { - if(ttf == NULL) + if(ttf == NULL) { return false; + } SDL_Surface* surfs[127 - 33]; int width = 0; int height = 0; @@ -593,8 +611,9 @@ SDL_Rect NFont::drawToSurface(int x, int y, const char* text) const SDL_Rect srcRect, dstRect, copyS, copyD; data.dirtyRect = makeRect(x, y, 0, 0); - if(c == NULL || src == NULL || dest == NULL) + if(c == NULL || src == NULL || dest == NULL) { return data.dirtyRect; + } srcRect.y = baseline - ascent; srcRect.h = dstRect.h = height; @@ -619,25 +638,31 @@ SDL_Rect NFont::drawToSurface(int x, int y, const char* text) const } unsigned char ctest = (unsigned char)(*c); // Skip bad characters - if(ctest < 33 || (ctest > 126 && ctest < 161)) + if(ctest < 33 || (ctest > 126 && ctest < 161)) { continue; - if(dstRect.x >= dest->w) + } + if(dstRect.x >= dest->w) { continue; - if(dstRect.y >= dest->h) + } + if(dstRect.y >= dest->h) { continue; + } num = ctest - 33; // Get array index - if(num > 126) // shift the extended characters down to the correct index + if(num > 126) { // shift the extended characters down to the correct index num -= 34; + } srcRect.x = charPos[num]; srcRect.w = dstRect.w = charWidth[num]; copyS = srcRect; copyD = dstRect; SDL_BlitSurface(src, &srcRect, dest, &dstRect); - if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0) + if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0) { data.dirtyRect = dstRect; - else + } + else { data.dirtyRect = rectUnion(data.dirtyRect, dstRect); + } srcRect = copyS; dstRect = copyD; @@ -673,8 +698,9 @@ SDL_Rect NFont::drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const unsigned char num; SDL_Rect srcRect, dstRect, copyS, copyD; - if(c == NULL || src == NULL || dest == NULL) + if(c == NULL || src == NULL || dest == NULL) { return makeRect(x,y,0,0); + } srcRect.y = baseline - ascent; srcRect.h = dstRect.h = height; @@ -706,13 +732,15 @@ SDL_Rect NFont::drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const } unsigned char ctest = (unsigned char)(*c); // Skip bad characters - if(ctest < 33 || (ctest > 126 && ctest < 161)) + if(ctest < 33 || (ctest > 126 && ctest < 161)) { continue; + } //if(x >= dest->w) // This shouldn't be used with position control // continue; num = ctest - 33; - if(num > 126) // shift the extended characters down to the array index + if(num > 126) { // shift the extended characters down to the array index num -= 34; + } srcRect.x = charPos[num]; srcRect.w = dstRect.w = charWidth[num]; @@ -728,10 +756,12 @@ SDL_Rect NFont::drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const copyS = srcRect; copyD = dstRect; SDL_BlitSurface(src, &srcRect, dest, &dstRect); - if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0) + if(data.dirtyRect.w == 0 || data.dirtyRect.h == 0) { data.dirtyRect = dstRect; - else + } + else { data.dirtyRect = rectUnion(data.dirtyRect, dstRect); + } srcRect = copyS; dstRect = copyD; @@ -746,8 +776,9 @@ SDL_Rect NFont::drawToSurfacePos(int x, int y, NFont::AnimFn posFn) const SDL_Rect NFont::draw(int x, int y, const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return makeRect(x, y, 0, 0); + } va_list lst; va_start(lst, formatted_text); @@ -759,8 +790,9 @@ SDL_Rect NFont::draw(int x, int y, const char* formatted_text, ...) const SDL_Rect NFont::drawCenter(int x, int y, const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return makeRect(x, y, 0, 0); + } va_list lst; va_start(lst, formatted_text); @@ -783,8 +815,9 @@ SDL_Rect NFont::drawCenter(int x, int y, const char* formatted_text, ...) const str = c; y += height; } - else + else { c++; + } } char s[strlen(str)+1]; strcpy(s, str); @@ -795,8 +828,9 @@ SDL_Rect NFont::drawCenter(int x, int y, const char* formatted_text, ...) const SDL_Rect NFont::drawRight(int x, int y, const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return makeRect(x, y, 0, 0); + } va_list lst; va_start(lst, formatted_text); @@ -817,8 +851,9 @@ SDL_Rect NFont::drawRight(int x, int y, const char* formatted_text, ...) const str = c; y += height; } - else + else { c++; + } } char s[strlen(str)+1]; strcpy(s, str); @@ -864,8 +899,9 @@ SDL_Surface* NFont::getSurface() const int NFont::getHeight(const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return height; + } va_list lst; va_start(lst, formatted_text); @@ -877,8 +913,9 @@ int NFont::getHeight(const char* formatted_text, ...) const for (c = buffer; *c != '\0'; c++) { - if(*c == '\n') + if(*c == '\n') { numLines++; + } } // Actual height of letter region + line spacing @@ -887,8 +924,9 @@ int NFont::getHeight(const char* formatted_text, ...) const int NFont::getWidth(const char* formatted_text, ...) const { - if (formatted_text == NULL) + if (formatted_text == NULL) { return 0; + } va_list lst; va_start(lst, formatted_text); @@ -926,8 +964,9 @@ int NFont::getWidth(const char* formatted_text, ...) const int NFont::getAscent(const char character) const { unsigned char test = (unsigned char)character; - if(test < 33 || test > 222 || (test > 126 && test < 161)) + if(test < 33 || test > 222 || (test > 126 && test < 161)) { return 0; + } unsigned char num = (unsigned char)character - 33; // Get the max ascent int x = charPos[num]; @@ -953,8 +992,9 @@ int NFont::getAscent(const char character) const int NFont::getAscent(const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return ascent; + } va_list lst; va_start(lst, formatted_text); @@ -967,8 +1007,9 @@ int NFont::getAscent(const char* formatted_text, ...) const for (; *c != '\0'; c++) { int asc = getAscent(*c); - if(asc > max) + if(asc > max) { max = asc; + } } return max; } @@ -976,8 +1017,9 @@ int NFont::getAscent(const char* formatted_text, ...) const int NFont::getDescent(const char character) const { unsigned char test = (unsigned char)character; - if(test < 33 || test > 222 || (test > 126 && test < 161)) + if(test < 33 || test > 222 || (test > 126 && test < 161)) { return 0; + } unsigned char num = (unsigned char)character - 33; // Get the max descent int x = charPos[num]; @@ -1003,8 +1045,9 @@ int NFont::getDescent(const char character) const int NFont::getDescent(const char* formatted_text, ...) const { - if(formatted_text == NULL) + if(formatted_text == NULL) { return descent; + } va_list lst; va_start(lst, formatted_text); @@ -1017,8 +1060,9 @@ int NFont::getDescent(const char* formatted_text, ...) const for (; *c != '\0'; c++) { int des = getDescent(*c); - if(des > max) + if(des > max) { max = des; + } } return max; } @@ -1065,8 +1109,9 @@ void NFont::setDest(SDL_Surface* Dest) int NFont::setBaseline(int Baseline) { - if(Baseline >= 0) + if(Baseline >= 0) { baseline = Baseline; + } else { // Get the baseline by checking a, b, and c and averaging their lowest y-value. diff --git a/source/code/Makefile b/source/code/Makefile index 14917aa..3fa8788 100644 --- a/source/code/Makefile +++ b/source/code/Makefile @@ -72,3 +72,8 @@ run: $(BINARY) clean: rm *.o *.P Libs/*.o Libs/*.P + +SOURCE_FILES = $(OFILES:.o=.cpp) + +format: + astyle -t -j -y -c $(SOURCE_FILES) diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 86f8917..63c5e17 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -42,7 +42,7 @@ inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y) SDL_Rect dest; dest.x = x; dest.y = y; - SDL_BlitSurface(img, NULL, target, &dest); + SDL_BlitSurface(img, nullptr, target, &dest); } ButtonGfx standardButton; @@ -53,8 +53,9 @@ void ButtonGfx::setSurfaces(shared_ptr marked, shared this->unmarked = unmarked; xsize=(marked)->GetWidth(); ysize=(marked)->GetHeight(); - if(verboseLevel) + if(verboseLevel) { cout << "Surfaces set, size: " <screen = *screen; buttons = vector(0); isSubmenu = submenu; - if(isSubmenu) + if(isSubmenu) { exit.setLabel( _("Back") ); - else + } + else { exit.setLabel( _("Exit") ); + } } Menu::Menu(SDL_Surface** screen, const string& title, bool submenu) @@ -218,10 +221,12 @@ Menu::Menu(SDL_Surface** screen, const string& title, bool submenu) buttons = vector(0); isSubmenu = submenu; this->title = title; - if(isSubmenu) + if(isSubmenu) { exit.setLabel(_("Back") ); - else + } + else { exit.setLabel(_("Exit") ); + } } void Menu::run() @@ -232,7 +237,9 @@ void Menu::run() long oldmousey = mousey; while(running && !Config::getInstance()->isShuttingDown()) { - if (!(highPriority)) SDL_Delay(10); + if (!(highPriority)) { + SDL_Delay(10); + } SDL_Event event; @@ -255,15 +262,17 @@ void Menu::run() if (event.key.keysym.sym == SDLK_UP) { marked--; - if(marked<0) - marked = buttons.size(); //not -1, since exit is after the last element in the list + if(marked<0) { + marked = buttons.size(); //not -1, since exit is after the last element in the list + } } if (event.key.keysym.sym == SDLK_DOWN) { marked++; - if(marked>buttons.size()) + if(marked>buttons.size()) { marked = 0; + } } if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_KP_ENTER ) @@ -271,11 +280,13 @@ void Menu::run() if(marked < buttons.size()) { buttons.at(marked)->doAction(); - if(buttons.at(marked)->isPopOnRun()) + if(buttons.at(marked)->isPopOnRun()) { running = false; + } } - if(marked == buttons.size()) + if(marked == buttons.size()) { running = false; + } } } @@ -320,8 +331,9 @@ void Menu::run() if(buttons.at(i)->isClicked(mousex,mousey)) { buttons.at(i)->doAction(); - if(buttons.at(i)->isPopOnRun()) + if(buttons.at(i)->isPopOnRun()) { running = false; + } mousex = 0; } } diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp index dd081c2..cc6d3e8 100644 --- a/source/code/ReadKeyboard.cpp +++ b/source/code/ReadKeyboard.cpp @@ -54,9 +54,15 @@ ReadKeyboard::ReadKeyboard(const char *oldName) i--; charecter = textstring[i]; } - if (i>0)length = i+1; - else if (charecter == ' ') length = 0; - else length = 1; + if (i>0) { + length = i+1; + } + else if (charecter == ' ') { + length = 0; + } + else { + length = 1; + } position = length; } @@ -84,7 +90,9 @@ void ReadKeyboard::removeChar() textstring[i]=textstring[i+1]; } textstring[28]=' '; - if (length>0)length--; + if (length>0) { + length--; + } } bool ReadKeyboard::ReadKey(SDLKey keyPressed) @@ -96,7 +104,9 @@ bool ReadKeyboard::ReadKey(SDLKey keyPressed) } if (keyPressed == SDLK_DELETE) { - if ((length>0)&& (position0)&& (position> key; - if(key==previuskey) //the last entry will be read 2 times if a linebreak is missing in the end + if(key==previuskey) { //the last entry will be read 2 times if a linebreak is missing in the end continue; + } previuskey = key; inFile.get(); //Read the space between the key and the content inFile.getline(value,MAX_VAR_LENGTH); @@ -266,8 +267,9 @@ bool Config::exists(const string &varName) const void Config::setDefault(const string &varName,const string &content) { - if(exists(varName)) - return; //Already exists do not change + if(exists(varName)) { + return; //Already exists do not change + } setString(varName,content); } @@ -302,8 +304,9 @@ string Config::getString(const string &varName) { return configMap[varName]; } - else + else { return ""; + } } int Config::getInt(const string &varName) @@ -312,8 +315,9 @@ int Config::getInt(const string &varName) { return str2int(configMap[varName]); } - else + else { return 0; + } } double Config::getValue(const string &varName) @@ -322,6 +326,7 @@ double Config::getValue(const string &varName) { return str2double(configMap[varName]); } - else + else { return 0.0; + } } diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index 4bd00d3..f021784 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp @@ -29,8 +29,8 @@ http://blockattack.sf.net string getMyDocumentsPath1() { TCHAR pszPath[MAX_PATH]; - //if (SUCCEEDED(SHGetSpecialFolderPath(NULL, pszPath, CSIDL_PERSONAL, FALSE))) { - if (SUCCEEDED(SHGetSpecialFolderPath(NULL, pszPath, CSIDL_PERSONAL, FALSE))) + //if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) { + if (SUCCEEDED(SHGetSpecialFolderPath(nullptr, pszPath, CSIDL_PERSONAL, FALSE))) { // pszPath is now the path that you want cout << "MyDocuments Located: " << pszPath << endl; @@ -56,7 +56,7 @@ Highscore::Highscore(int type) #elif defined(_WIN32) string home = getMyDocumentsPath1(); string filename1, filename2; - if (&home!=NULL) + if (&home!=nullptr) { filename1 = home+"/My Games/blockattack/endless.dat"; filename2 = home+"/My Games/blockattack/timetrial.dat"; @@ -71,8 +71,12 @@ Highscore::Highscore(int type) string filename2 = "timetrial.dat"; #endif ourType = type; - if (type == 1) filename = filename1; - if (type == 2) filename = filename2; + if (type == 1) { + filename = filename1; + } + if (type == 2) { + filename = filename2; + } ifstream scorefile(filename.c_str(), ios::binary); if (scorefile) { @@ -103,7 +107,7 @@ void Highscore::writeFile() #elif defined(_WIN32) string home = getMyDocumentsPath1(); string filename1, filename2; - if (&home!=NULL) + if (&home!=nullptr) { filename1 = home+"/My Games/blockattack/endless.dat"; filename2 = home+"/My Games/blockattack/timetrial.dat"; @@ -117,8 +121,12 @@ void Highscore::writeFile() string filename1 = "endless.dat"; string filename2 = "timetrial.dat"; #endif - if (ourType == 1) filename = filename1; - if (ourType == 2) filename = filename2; + if (ourType == 1) { + filename = filename1; + } + if (ourType == 2) { + filename = filename2; + } ofstream outfile; outfile.open(Highscore::filename.c_str(), ios::binary |ios::trunc); @@ -137,17 +145,20 @@ void Highscore::writeFile() bool Highscore::isHighScore(int newScore) { - if (newScore>tabel[top-1].score) + if (newScore>tabel[top-1].score) { return true; - else + } + else { return false; + } } void Highscore::addScore(const string& newName, int newScore) { int ranking = top-1; - while ((tabel[ranking-1].scoreranking; i--) { tabel[i].score = tabel[i-1].score; diff --git a/source/code/joypad.cpp b/source/code/joypad.cpp index f001394..8edf5c8 100644 --- a/source/code/joypad.cpp +++ b/source/code/joypad.cpp @@ -25,10 +25,12 @@ http://blockattack.sf.net bool Joypad_init() { - if (0==SDL_InitSubSystem(SDL_INIT_JOYSTICK)) + if (0==SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { return true; - else + } + else { return false; + } } Joypad_status Joypad_getStatus(SDL_Joystick *joystick) @@ -47,32 +49,43 @@ Joypad_status Joypad_getStatus(SDL_Joystick *joystick) else { //cout << SDL_JoystickGetAxis(joystick,i*2+1)<< endl; - if (SDL_JoystickGetAxis(joystick,i*2)<(-8000)) + if (SDL_JoystickGetAxis(joystick,i*2)<(-8000)) { status.padLeft[i]=1; - else + } + else { status.padLeft[i]=0; - if (SDL_JoystickGetAxis(joystick,i*2)>(8000)) + } + if (SDL_JoystickGetAxis(joystick,i*2)>(8000)) { status.padRight[i]=1; - else + } + else { status.padRight[i]=0; - if (SDL_JoystickGetAxis(joystick,i*2+1)<(-8000)) + } + if (SDL_JoystickGetAxis(joystick,i*2+1)<(-8000)) { status.padUp[i]=1; - else + } + else { status.padUp[i]=0; - if (SDL_JoystickGetAxis(joystick,i*2+1)>(8000)) + } + if (SDL_JoystickGetAxis(joystick,i*2+1)>(8000)) { status.padDown[i]=1; - else + } + else { status.padDown[i]=0; + } } }//NRofPADS for (int i=0; i=SDL_JoystickNumButtons(joystick)) + if (i>=SDL_JoystickNumButtons(joystick)) { status.button[i]=false; - else if (1==SDL_JoystickGetButton(joystick,i)) + } + else if (1==SDL_JoystickGetButton(joystick,i)) { status.button[i] = true; - else + } + else { status.button[i] = false; + } } return status; } @@ -92,24 +105,29 @@ Joypad::Joypad() but1REL=true; but2REL=true; int joynum = 0; - while ((SDL_JoystickOpened(joynum))&&(joynum=Joypad_number) + } + if (joynum>=Joypad_number) { working = false; + } else { joystick=SDL_JoystickOpen(joynum); - if (joystick==NULL) + if (joystick==nullptr) { working =false; - else + } + else { working=true; + } } } Joypad::~Joypad() { - if(working) + if(working) { SDL_JoystickClose(joystick); + } } void Joypad::update() @@ -121,54 +139,66 @@ void Joypad::update() up=true; upREL=false; } - else + else { up=false; + } if ((downREL)&&((status.padDown[0])||(status.padDown[1])||(status.padDown[2])||(status.padDown[3]))) { down=true; downREL=false; } - else + else { down=false; + } if ((leftREL)&&((status.padLeft[0])||(status.padLeft[1])||(status.padLeft[2])||(status.padLeft[3]))) { left=true; leftREL=false; } - else + else { left=false; + } if ((rightREL)&&((status.padRight[0])||(status.padRight[1])||(status.padRight[2])||(status.padRight[3]))) { right=true; rightREL=false; } - else + else { right=false; + } if ((but1REL)&&((status.button[0])||(status.button[2])||(status.button[4])||(status.button[6]))) { but1=true; but1REL=false; } - else + else { but1=false; + } if ((but2REL)&&((status.button[1])||(status.button[3])||(status.button[5])||(status.button[7]))) { but2=true; but2REL=false; } - else + else { but2=false; + } //Now testing for up - if (!((status.padUp[0])||(status.padUp[1])||(status.padUp[2])||(status.padUp[3]))) + if (!((status.padUp[0])||(status.padUp[1])||(status.padUp[2])||(status.padUp[3]))) { upREL = true; - if (!((status.padDown[0])||(status.padDown[1])||(status.padDown[2])||(status.padDown[3]))) + } + if (!((status.padDown[0])||(status.padDown[1])||(status.padDown[2])||(status.padDown[3]))) { downREL = true; - if (!((status.padLeft[0])||(status.padLeft[1])||(status.padLeft[2])||(status.padLeft[3]))) + } + if (!((status.padLeft[0])||(status.padLeft[1])||(status.padLeft[2])||(status.padLeft[3]))) { leftREL = true; - if (!((status.padRight[0])||(status.padRight[1])||(status.padRight[2])||(status.padRight[3]))) + } + if (!((status.padRight[0])||(status.padRight[1])||(status.padRight[2])||(status.padRight[3]))) { rightREL= true; - if (!((status.button[0])||(status.button[2])||(status.button[4])||(status.button[6]))) + } + if (!((status.button[0])||(status.button[2])||(status.button[4])||(status.button[6]))) { but1REL = true; - if (!((status.button[1])||(status.button[3])||(status.button[5])||(status.button[7]))) + } + if (!((status.button[1])||(status.button[3])||(status.button[5])||(status.button[7]))) { but2REL = true; + } } diff --git a/source/code/listFiles.cpp b/source/code/listFiles.cpp index 1f3f83a..d47a21b 100644 --- a/source/code/listFiles.cpp +++ b/source/code/listFiles.cpp @@ -40,8 +40,9 @@ ListFiles::~ListFiles() void ListFiles::setDirectory(const string &directory) { - for (int i=0; id_name; @@ -113,8 +115,9 @@ void ListFiles::setDirectory2(const string &dic) struct dirent *dp; //cout << "Will look in: " << dic << endl; DirectoryPointer = opendir(dic.c_str()); - if(!DirectoryPointer) + if(!DirectoryPointer) { return; + } while ((dp=readdir(DirectoryPointer))&&(nrOfFilesd_name; @@ -132,8 +135,9 @@ void ListFiles::setDirectory2(const string &dic) string ListFiles::getFileName(int nr) { - if (startFileNr+nrFIRST_FILE) + if (startFileNr>FIRST_FILE) { startFileNr = startFileNr-10; - if (startFileNrminVelocity) && (y>(double)(768-ballSize)) && (y<768.0)) { velocityY = -0.70*velocityY; @@ -881,10 +899,14 @@ public: int ballNumber = 0; //Find a free ball while ((ballUsed[ballNumber])&&(ballNumber5) right = -1; - else right = board[j+1][i]; - if (i>28) over = -1; - else over = board[j][i+1]; - if (i<1) under = -1; - else under = board[j][i-1]; + if (j<1) { + left = -1; + } + else { + left = board[j-1][i]; + } + if (j>5) { + right = -1; + } + else { + right = board[j+1][i]; + } + if (i>28) { + over = -1; + } + else { + over = board[j][i+1]; + } + if (i<1) { + under = -1; + } + else { + under = board[j][i-1]; + } if ((left == number)&&(right == number)&&(over == number)&&(under == number)) + { DrawIMG(garbageFill, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left != number)&&(right == number)&&(over == number)&&(under == number)) + { DrawIMG(garbageL, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right != number)&&(over == number)&&(under == number)) + { DrawIMG(garbageR, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right == number)&&(over != number)&&(under == number)) + { DrawIMG(garbageT, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right == number)&&(over == number)&&(under != number)) + { DrawIMG(garbageB, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left != number)&&(right == number)&&(over != number)&&(under == number)) + { DrawIMG(garbageTL, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left != number)&&(right == number)&&(over == number)&&(under != number)) + { DrawIMG(garbageBL, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right != number)&&(over != number)&&(under == number)) + { DrawIMG(garbageTR, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right != number)&&(over == number)&&(under != number)) + { DrawIMG(garbageBR, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right != number)&&(over != number)&&(under != number)) + { DrawIMG(garbageMR, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left == number)&&(right == number)&&(over != number)&&(under != number)) + { DrawIMG(garbageM, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } if ((left != number)&&(right == number)&&(over != number)&&(under != number)) + { DrawIMG(garbageML, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } } if ((board[j][i]/1000000)%10==2) { if (j==0) + { DrawIMG(garbageGML, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } else if (j==5) + { DrawIMG(garbageGMR, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } else + { DrawIMG(garbageGM, sBoard, j*bsize, bsize*12-i*bsize-pixels); + } } } const int j = 0; @@ -1290,14 +1378,30 @@ private: { int left, right, over, under; int number = board[j][i]; - if (j<1) left = -1; - else left = board[j-1][i]; - if (j>5) right = -1; - else right = board[j+1][i]; - if (i>28) over = -1; - else over = board[j][i+1]; - if (i<1) under = -1; - else under = board[j][i-1]; + if (j<1) { + left = -1; + } + else { + left = board[j-1][i]; + } + if (j>5) { + right = -1; + } + else { + right = board[j+1][i]; + } + if (i>28) { + over = -1; + } + else { + over = board[j][i+1]; + } + if (i<1) { + under = -1; + } + else { + under = board[j][i-1]; + } if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) { DrawIMG(smiley[board[j][i]%4], sBoard, 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize); @@ -1315,7 +1419,9 @@ private: } for (int i=0; i<6; i++) if (board[i][0]!=-1) - DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant + { + DrawIMG(transCover, sBoard, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant + } } public: @@ -1326,7 +1432,9 @@ public: nf_standard_blue_font.setDest(sBoard); //reset to screen at the end of this funciton! PaintBricks(); - if (stageClear) DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1); + if (stageClear) { + DrawIMG(blackLine, sBoard, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1); + } if (puzzleMode&&(!bGameOver)) { //We need to write nr. of moves left! @@ -1340,9 +1448,13 @@ public: if (Level115 && currentCounter<120) + { Mix_PlayChannel(1,counterChunk,0); + } } lastCounter = currentCounter; } @@ -1428,9 +1550,13 @@ public: else { if (bDraw) + { DrawIMG(iDraw, sBoard, 0, 5*bsize); + } else + { DrawIMG(iGameOver, sBoard, 0, 5*bsize); + } } } nf_standard_blue_font.setDest(screen); @@ -1442,7 +1568,7 @@ public: BlockGame::Update(newtick); DoPaintJob(); } - + private: int topx, topy; }; @@ -1454,8 +1580,10 @@ private: void writeScreenShot() { if(verboseLevel) + { cout << "Saving screenshot" << endl; - int rightNow = (int)time(NULL); + } + int rightNow = (int)time(nullptr); /*#if defined(__unix__) char buf[514]; sprintf( buf, "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow ); @@ -1475,7 +1603,9 @@ void writeScreenShot() #endif SDL_SaveBMP( screen, buf.c_str() ); if (!NoSound) - if (SoundEnabled)Mix_PlayChannel(1,photoClick,0); + if (SoundEnabled) { + Mix_PlayChannel(1,photoClick,0); + } } //Function to return the name of a key, to be displayed... @@ -1510,7 +1640,9 @@ bool OpenDialogbox(int x, int y, char *name) strHolder.erase((int)rk.CharsBeforeCursor()); if (((SDL_GetTicks()/600)%2)==1) + { NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+76,"|"); + } SDL_Event event; @@ -1537,32 +1669,40 @@ bool OpenDialogbox(int x, int y, char *name) } else if (!(event.key.keysym.sym == SDLK_BACKSPACE)) { - if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0); + if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound)) { + Mix_PlayChannel(1,typingChunk,0); + } } else if ((event.key.keysym.sym == SDLK_BACKSPACE)&&(!repeating)) { - if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0); + if ((rk.ReadKey(event.key.keysym.sym))&&(SoundEnabled)&&(!NoSound)) { + Mix_PlayChannel(1,typingChunk,0); + } repeating = true; time=SDL_GetTicks(); } } - } //while(event) + } //while(event) if (SDL_GetTicks()>(time+repeatDelay)) { time = SDL_GetTicks(); - keys = SDL_GetKeyState(NULL); + keys = SDL_GetKeyState(nullptr); if ( (keys[SDLK_BACKSPACE])&&(repeating) ) { - if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound))Mix_PlayChannel(1,typingChunk,0); + if ((rk.ReadKey(SDLK_BACKSPACE))&&(SoundEnabled)&&(!NoSound)) { + Mix_PlayChannel(1,typingChunk,0); + } } else + { repeating = false; + } } SDL_Flip(screen); //Update screen - } //while(!done) + } //while(!done) strcpy(name,rk.GetString()); bScreenLocked = false; showDialog = false; @@ -1574,8 +1714,12 @@ void DrawHighscores(int x, int y, bool endless) { MakeBackground(xsize,ysize); DrawIMG(background,screen,0,0); - if (endless) nf_standard_blue_font.draw(x+100,y+100,_("Endless:") ); - else nf_standard_blue_font.draw(x+100,y+100,_("Time Trial:") ); + if (endless) { + nf_standard_blue_font.draw(x+100,y+100,_("Endless:") ); + } + else { + nf_standard_blue_font.draw(x+100,y+100,_("Time Trial:") ); + } for (int i =0; i<10; i++) { char playerScore[32]; @@ -1726,16 +1870,22 @@ void OpenScoresDisplay() { page++; if(page>=numberOfPages) + { page = 0; + } } else if( (event.key.keysym.sym == SDLK_LEFT)) { page--; if(page<0) + { page = numberOfPages-1; + } } else + { done = true; + } if ( event.key.keysym.sym == SDLK_F9 ) { @@ -1752,28 +1902,32 @@ void OpenScoresDisplay() } } - } //while(event) + } //while(event) // If the mouse button is released, make bMouseUp equal true - if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) + if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { bMouseUp=true; } - if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp) + if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; //The Score button: if((mousex>scoreX) && (mousexscoreY) && (mouseybackX) && (mousexbackY) && (mousey=numberOfPages) + { page = 0; + } } } @@ -1797,12 +1953,14 @@ void OpenScoresDisplay() //Open a puzzle file bool OpenFileDialogbox(int x, int y, char *name) { - bool done = false; //We are done! + bool done = false; //We are done! int mousex, mousey; ListFiles lf = ListFiles(); string folder = (string)SHAREDIR+(string)"/puzzles"; if(verboseLevel) + { cout << "Looking in " << folder << endl; + } lf.setDirectory(folder.c_str()); #ifdef __unix__ string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles"; @@ -1855,12 +2013,12 @@ bool OpenFileDialogbox(int x, int y, char *name) SDL_GetMouseState(&mousex,&mousey); // If the mouse button is released, make bMouseUp equal true - if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) + if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { bMouseUp=true; } - if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp) + if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; @@ -1962,7 +2120,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th DrawIMG(background,screen,50,60,300,50,50,60); DrawIMG(background,screen,510,60,300,50,510,60); - } + } else { DrawIMG(background,screen,0,0); } @@ -1971,11 +2129,17 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th strHolder = itoa(theGame->GetScore()+theGame->GetHandicap()); NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str()); if (theGame->GetAIenabled()) + { NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") ); + } else if (editorMode) + { NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") ); + } else if (!singlePuzzle) + { NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name); + } if (theGame->isTimeTrial()) { int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt(); @@ -1991,11 +2155,19 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000; seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000; } - if (theGame->isGameOver()) minutes=0; - if (theGame->isGameOver()) seconds=0; + if (theGame->isGameOver()) { + minutes=0; + } + if (theGame->isGameOver()) { + seconds=0; + } if (seconds>9) + { strHolder = itoa(minutes)+":"+itoa(seconds); - else strHolder = itoa(minutes)+":0"+itoa(seconds); + } + else { + strHolder = itoa(minutes)+":0"+itoa(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()); } @@ -2003,12 +2175,20 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th { int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000; int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000; - if (theGame->isGameOver()) minutes=(theGame->GetGameEndedAt()/1000/60)%100; - if (theGame->isGameOver()) seconds=(theGame->GetGameEndedAt()/1000)%60; + if (theGame->isGameOver()) { + minutes=(theGame->GetGameEndedAt()/1000/60)%100; + } + if (theGame->isGameOver()) { + seconds=(theGame->GetGameEndedAt()/1000)%60; + } if (seconds>9) + { strHolder = itoa(minutes)+":"+itoa(seconds); + } else + { strHolder = itoa(minutes)+":0"+itoa(seconds); + } NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str()); } strHolder = itoa(theGame->GetChains()); @@ -2070,18 +2250,28 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th 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() ); if(theGame->isPuzzleMode()) + { NFont_Write(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() ); + } } else + { DrawIMG(theGame2->sBoard,screen,theGame2->GetTopX(),theGame2->GetTopY()); + } strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap()); NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str()); if (theGame2->GetAIenabled()) + { NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") ); + } else + { NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name); + } if (theGame2->isTimeTrial()) { int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt(); @@ -2097,12 +2287,20 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000; seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000; } - if (theGame2->isGameOver()) minutes=0; - if (theGame2->isGameOver()) seconds=0; + if (theGame2->isGameOver()) { + minutes=0; + } + if (theGame2->isGameOver()) { + seconds=0; + } if (seconds>9) + { strHolder = itoa(minutes)+":"+itoa(seconds); + } else + { strHolder = itoa(minutes)+":0"+itoa(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()); } @@ -2110,12 +2308,20 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th { int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000; int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000; - if (theGame2->isGameOver()) minutes=(theGame2->GetGameEndedAt()/1000/60)%100; - if (theGame2->isGameOver()) seconds=(theGame2->GetGameEndedAt()/1000)%60; + if (theGame2->isGameOver()) { + minutes=(theGame2->GetGameEndedAt()/1000/60)%100; + } + if (theGame2->isGameOver()) { + seconds=(theGame2->GetGameEndedAt()/1000)%60; + } if (seconds>9) + { strHolder = itoa(minutes)+":"+itoa(seconds); + } else + { strHolder = itoa(minutes)+":0"+itoa(seconds); + } NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str()); } strHolder = itoa(theGame2->GetChains()); @@ -2132,7 +2338,9 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl *theGame, BlockGameSdl *th Frames++; if (SDL_GetTicks() >= Ticks + 1000) { - if (Frames > 999) Frames=999; + if (Frames > 999) { + Frames=999; + } sprintf(FPS, "%lu fps", Frames); Frames = 0; Ticks = SDL_GetTicks(); @@ -2153,7 +2361,9 @@ static void MakeBackground(int xsize,int ysize) int h = backgroundImage->h; for(int i=0; i*w(&tempUInt32),sizeof(Uint32)); + } stageScores[i]=tempUInt32; totalScore+=tempUInt32; } @@ -2227,7 +2441,9 @@ int PuzzleLevelSelect(int Type) { tempUInt32 = 0; if(!stageFile.eof()) + { stageFile.read(reinterpret_cast(&tempUInt32),sizeof(Uint32)); + } stageTimes[i]=tempUInt32; totalTime += tempUInt32; } @@ -2262,16 +2478,26 @@ int PuzzleLevelSelect(int Type) DrawIMG(background, screen, 0, 0); DrawIMG(iCheckBoxArea,screen,xplace,yplace); if(Type == 0) + { NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") ); + } if(Type == 1) + { NFont_Write(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); - if(i==selected) DrawIMG(iLevelCheckBoxMarked,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); - if (Type == 1 && stageCleared.at(i)==true) DrawIMG(iLevelCheck,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); + } + if (Type == 0 && PuzzleIsCleared(i)) { + DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); + } + if (Type == 1 && stageCleared.at(i)==true) { + DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); + } } SDL_Event event; @@ -2292,29 +2518,37 @@ int PuzzleLevelSelect(int Type) { ++selected; if(selected >= nrOfLevels) + { selected = 0; + } } if ( event.key.keysym.sym == SDLK_LEFT ) { --selected; if(selected < 0) + { selected = nrOfLevels-1; + } } if ( event.key.keysym.sym == SDLK_DOWN ) { selected+=10; if(selected >= nrOfLevels) + { selected-=10; + } } if ( event.key.keysym.sym == SDLK_UP ) { selected-=10; if(selected < 0) + { selected+=10; + } } } - SDL_GetKeyState(NULL); + SDL_GetKeyState(nullptr); SDL_GetMouseState(&mousex,&mousey); if(mousex != oldmousex || mousey != oldmousey) @@ -2323,7 +2557,9 @@ int PuzzleLevelSelect(int Type) int j; for (j = 0; (tmpSelected == -1) && ( (j0) + { scoreString = _("Best score: ")+itoa(stageScores.at(selected)); + } if(stageTimes.at(selected)>0) + { timeString = _("Time used: ")+itoa(stageTimes.at(selected)/1000/60)+" : "+itoa2((stageTimes.at(selected)/1000)%60); + } NFont_Write(screen, 200,200,scoreString.c_str()); NFont_Write(screen, 200,250,timeString.c_str()); @@ -2418,7 +2660,9 @@ void startVsMenu() NFont_Write(screen, xplace+50+i*40,yplace+110,levelS); DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+150); if (player1Speed==i) + { DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+150); + } } for (int i=0; i<5; i++) { @@ -2428,17 +2672,23 @@ void startVsMenu() NFont_Write(screen, xplace+300+50+i*40,yplace+110,levelS); DrawIMG(iLevelCheckBox,screen,xplace+300+50+i*40,yplace+150); if (player2Speed==i) + { DrawIMG(iLevelCheck,screen,xplace+300+50+i*40,yplace+150); + } } NFont_Write(screen, xplace+50,yplace+200,"AI: "); DrawIMG(iLevelCheckBox,screen,xplace+50+70,yplace+200); if (player1AI) + { DrawIMG(iLevelCheck,screen,xplace+50+70,yplace+200); + } NFont_Write(screen, xplace+50,yplace+250,"TT Handicap: "); NFont_Write(screen, xplace+50+300,yplace+200,"AI: "); DrawIMG(iLevelCheckBox,screen,xplace+50+70+300,yplace+200); if (player2AI) + { DrawIMG(iLevelCheck,screen,xplace+50+70+300,yplace+200); + } NFont_Write(screen, xplace+50+300,yplace+250,"TT Handicap: "); for (int i=0; i<5; i++) { @@ -2448,7 +2698,9 @@ void startVsMenu() NFont_Write(screen, xplace+50+i*40,yplace+290,levelS); DrawIMG(iLevelCheckBox,screen,xplace+50+i*40,yplace+330); if (player1handicap==i) + { DrawIMG(iLevelCheck,screen,xplace+50+i*40,yplace+330); + } } for (int i=0; i<5; i++) { @@ -2458,7 +2710,9 @@ void startVsMenu() NFont_Write(screen, xplace+50+i*40+300,yplace+290,levelS); DrawIMG(iLevelCheckBox,screen,xplace+50+i*40+300,yplace+330); if (player2handicap==i) + { DrawIMG(iLevelCheck,screen,xplace+50+i*40+300,yplace+330); + } } SDL_Event event; @@ -2481,46 +2735,60 @@ void startVsMenu() } } - SDL_GetKeyState(NULL); + SDL_GetKeyState(nullptr); SDL_GetMouseState(&mousex,&mousey); // If the mouse button is released, make bMouseUp equal true - if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) + if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { bMouseUp=true; } - if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp) + if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; if ((mousex>xplace+50+70)&&(mousey>yplace+200)&&(mousexxplace+50+70+300)&&(mousey>yplace+200)&&(mousexxplace+50+i*40)&&(mousexyplace+150)&&(mouseyxplace+50+i*40+300)&&(mousexyplace+150)&&(mouseyxplace+50+i*40)&&(mousexyplace+330)&&(mouseyxplace+50+i*40+300)&&(mousexyplace+330)&&(mouseyxsize/2-120/2)&&(mousex600)&&(mousey<640)) + { done = true; + } } //DrawIMG(mouse,screen,mousex,mousey); @@ -2539,19 +2807,23 @@ void changePuzzleLevels() char theFileName[30]; strcpy(theFileName, PuzzleGetName().c_str()); for (int i=PuzzleGetName().length(); i<30; i++) + { theFileName[i]=' '; + } theFileName[29]=0; if (OpenFileDialogbox(200,100,theFileName)) { for (int i=28; ((theFileName[i]==' ')&&(i>0)); i--) + { theFileName[i]=0; + } PuzzleSetName(theFileName); #if defined(__unix__) string home = getenv("HOME"); PuzzleSetSavePath(home+"/.gamesaves/blockattack/"+PuzzleGetName()+".save"); #elif defined(_WIN32) string home = getMyDocumentsPath(); - if (&home!=NULL) + if (&home!=nullptr) { PuzzleSetSavePath(home+"/My Games/blockattack/"+PuzzleGetName()+".save"); } @@ -2594,7 +2866,9 @@ static int StartSinglePlayerPuzzle(int level) { int myLevel = PuzzleLevelSelect(0); if(myLevel == -1) + { return 1; + } player1->NewPuzzleGame(myLevel,SDL_GetTicks()); MakeBackground(xsize,ysize,player1,player2); DrawIMG(background, screen, 0, 0); @@ -2620,9 +2894,13 @@ static void StarTwoPlayerTimeTrial() player1->setHandicap(player1handicap); player2->setHandicap(player2handicap); if(player1AI) + { player1->setAIlevel(player1AIlevel); + } if(player2AI) + { player2->setAIlevel(player2AIlevel); + } player1->name = player1name; player2->name = player2name; } @@ -2639,9 +2917,13 @@ static void StartTwoPlayerVs() player1->setHandicap(player1handicap); player2->setHandicap(player2handicap); if(player1AI) + { player1->setAIlevel(player1AIlevel); + } if(player2AI) + { player2->setAIlevel(player2AIlevel); + } int theTime = time(0); player1->putStartBlocks(theTime); player2->putStartBlocks(theTime); @@ -2657,23 +2939,29 @@ int main(int argc, char *argv[]) #if defined(__unix__) //Compiler warns about unused result. The users envisonment should normally give the user all the information he needs if(system("mkdir -p ~/.gamesaves/blockattack/screenshots")) + { cerr << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl; + } if(system("mkdir -p ~/.gamesaves/blockattack/replays")) + { cerr << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl; + } if(system("mkdir -p ~/.gamesaves/blockattack/puzzles")) + { cerr << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl; + } #elif defined(_WIN32) //Now for Windows NT/2k/xp/2k3 etc. string tempA = getMyDocumentsPath()+"\\My Games"; - CreateDirectory(tempA.c_str(),NULL); + CreateDirectory(tempA.c_str(),nullptr); tempA = getMyDocumentsPath()+"\\My Games\\blockattack"; - CreateDirectory(tempA.c_str(),NULL); + CreateDirectory(tempA.c_str(),nullptr); tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays"; - CreateDirectory(tempA.c_str(),NULL); + CreateDirectory(tempA.c_str(),nullptr); tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots"; - CreateDirectory(tempA.c_str(),NULL); + CreateDirectory(tempA.c_str(),nullptr); #endif - highPriority = false; //if true the game will take most resources, but increase framerate. + highPriority = false; //if true the game will take most resources, but increase framerate. bFullscreen = false; //Set default Config variables: Config::getInstance()->setDefault("themename","default"); @@ -2698,12 +2986,12 @@ int main(int argc, char *argv[]) if (!(strncmp(argv[argumentNr],helpString,6))) { cout << "Block Attack Help" << endl << "--help " << _("Displays this message") << - endl << "-priority " << _("Starts game in high priority") << endl << - "-forceredraw " << _("Redraw the whole screen every frame, prevents garbage") << endl << - "-forcepartdraw " << _("Only draw what is changed, sometimes cause garbage") << endl << - "-nosound " << _("No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)") << endl << - "-theme <" << _("THEMENAME") << "> " << _("Changes to the theme on startup") << endl << - "-editor " << _("Starts the build-in editor (not yet integrated)") << endl; + endl << "-priority " << _("Starts game in high priority") << endl << + "-forceredraw " << _("Redraw the whole screen every frame, prevents garbage") << endl << + "-forcepartdraw " << _("Only draw what is changed, sometimes cause garbage") << endl << + "-nosound " << _("No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)") << endl << + "-theme <" << _("THEMENAME") << "> " << _("Changes to the theme on startup") << endl << + "-editor " << _("Starts the build-in editor (not yet integrated)") << endl; #ifdef WIN32 system("Pause"); #endif @@ -2712,7 +3000,9 @@ int main(int argc, char *argv[]) if (!(strncmp(argv[argumentNr],priorityString,9))) { if(verboseLevel) + { cout << "Priority mode" << endl; + } highPriority = true; } if (!(strncmp(argv[argumentNr],forceRedrawString,12))) @@ -2727,13 +3017,19 @@ int main(int argc, char *argv[]) { singlePuzzle = true; //We will just have one puzzle if (argv[argumentNr+1][1]!=0) + { singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10; + } else + { singlePuzzleNr = (argv[argumentNr+1][0]-'0'); + } singlePuzzleFile = argv[argumentNr+2]; argumentNr+=2; if(verboseLevel) + { cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl; + } } if (!(strncmp(argv[argumentNr],noSoundAtAll,8))) { @@ -2744,7 +3040,9 @@ int main(int argc, char *argv[]) #if LEVELEDITOR editorMode = true; if(verboseLevel) + { cout << "Integrated Puzzle Editor Activated" << endl; + } #else cout << "Integrated Puzzle Editor was disabled at compile time" << endl; return -1; @@ -2754,7 +3052,9 @@ int main(int argc, char *argv[]) { argumentNr++; //Go to themename (the next argument) if(verboseLevel) + { cout << "Theme set to \"" << argv[argumentNr] << '"' << endl; + } Config::getInstance()->setString("themename",argv[argumentNr]); } if(!(strcmp(argv[argumentNr],verbose))) @@ -2768,7 +3068,7 @@ int main(int argc, char *argv[]) SoundEnabled = true; MusicEnabled = true; bScreenLocked = false; - twoPlayers = false; //true if two players splitscreen + twoPlayers = false; //true if two players splitscreen theTopScoresEndless = Highscore(1); theTopScoresTimeTrial = Highscore(2); drawBalls = true; @@ -2784,10 +3084,14 @@ int main(int argc, char *argv[]) #elif defined(_WIN32) string home = getMyDocumentsPath(); string optionsPath; - if (&home!=NULL) //Null if no APPDATA dir exists (win 9x) + if (&home!=nullptr) //Null if no APPDATA dir exists (win 9x) + { optionsPath = home+"/My Games/blockattack/options.dat"; + } else + { optionsPath = "options.dat"; + } #else string optionsPath = "options.dat"; #endif @@ -2796,7 +3100,7 @@ int main(int argc, char *argv[]) stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave"; PuzzleSetSavePath(home+"/.gamesaves/blockattack/puzzle.levels.save"); #elif defined(_WIN32) - if (&home!=NULL) + if (&home!=nullptr) { stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave"; PuzzleSetSavePath(home+"/My Games/blockattack/puzzle.levels.save"); @@ -2818,7 +3122,7 @@ int main(int argc, char *argv[]) cerr << "Unable to init SDL: " << SDL_GetError() << endl; exit(1); } - atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc) + atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc) SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); @@ -2833,18 +3137,18 @@ int main(int argc, char *argv[]) if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0) { cerr << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl - << "Sound will be disabled!" << endl; + << "Sound will be disabled!" << endl; NoSound = true; //Tries to stop all sound from playing/loading } - SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line + SDL_WM_SetCaption("Block Attack - Rise of the Blocks", nullptr); //Sets title line if(verboseLevel) { //Copyright notice: cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2011 Poul Sander" << endl << - "A SDL based game (see www.libsdl.org)" << endl << - "The game is availeble under the GPL, see COPYING for details." << endl; + "A SDL based game (see www.libsdl.org)" << endl << + "The game is availeble under the GPL, see COPYING for details." << endl; #if defined(_WIN32) cout << "Windows build" << endl; #elif defined(__linux__) @@ -2891,25 +3195,55 @@ int main(int argc, char *argv[]) joyplay1 = (bool)configSettings->getInt("joypad1"); joyplay2 = (bool)configSettings->getInt("joypad2"); - if(configSettings->exists("player1keyup")) keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup"); - if(configSettings->exists("player1keydown")) keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown"); - if(configSettings->exists("player1keyleft")) keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft"); - if(configSettings->exists("player1keyright")) keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright"); - if(configSettings->exists("player1keychange")) keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange"); - if(configSettings->exists("player1keypush")) keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush"); - - if(configSettings->exists("player2keyup")) keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup"); - if(configSettings->exists("player2keydown")) keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown"); - if(configSettings->exists("player2keyleft")) keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft"); - if(configSettings->exists("player2keyright")) keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright"); - if(configSettings->exists("player2keychange")) keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange"); - if(configSettings->exists("player2keypush")) keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush"); + if(configSettings->exists("player1keyup")) { + keySettings[0].up = (SDLKey)configSettings->getInt("player1keyup"); + } + if(configSettings->exists("player1keydown")) { + keySettings[0].down = (SDLKey)configSettings->getInt("player1keydown"); + } + if(configSettings->exists("player1keyleft")) { + keySettings[0].left = (SDLKey)configSettings->getInt("player1keyleft"); + } + if(configSettings->exists("player1keyright")) { + keySettings[0].right = (SDLKey)configSettings->getInt("player1keyright"); + } + if(configSettings->exists("player1keychange")) { + keySettings[0].change = (SDLKey)configSettings->getInt("player1keychange"); + } + if(configSettings->exists("player1keypush")) { + keySettings[0].push = (SDLKey)configSettings->getInt("player1keypush"); + } + + if(configSettings->exists("player2keyup")) { + keySettings[2].up = (SDLKey)configSettings->getInt("player2keyup"); + } + if(configSettings->exists("player2keydown")) { + keySettings[2].down = (SDLKey)configSettings->getInt("player2keydown"); + } + if(configSettings->exists("player2keyleft")) { + keySettings[2].left = (SDLKey)configSettings->getInt("player2keyleft"); + } + if(configSettings->exists("player2keyright")) { + keySettings[2].right = (SDLKey)configSettings->getInt("player2keyright"); + } + if(configSettings->exists("player2keychange")) { + keySettings[2].change = (SDLKey)configSettings->getInt("player2keychange"); + } + if(configSettings->exists("player2keypush")) { + keySettings[2].push = (SDLKey)configSettings->getInt("player2keypush"); + } if(configSettings->exists("player1name")) + { strncpy(player1name,(configSettings->getString("player1name")).c_str(),28); + } if(configSettings->exists("player2name")) + { strncpy(player2name,(configSettings->getString("player2name")).c_str(),28); + } if(verboseLevel) + { cout << "Data loaded from config file" << endl; + } } else { @@ -2947,12 +3281,16 @@ int main(int argc, char *argv[]) } optionsFile.close(); if(verboseLevel) + { cout << "Data loaded from oldstyle options file" << endl; + } } else { if(verboseLevel) + { cout << "Unable to load options file, using default values" << endl; + } } } @@ -2974,10 +3312,14 @@ int main(int argc, char *argv[]) //Open video - if ((bFullscreen)&&(!singlePuzzle)) screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT); - else screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT); + if ((bFullscreen)&&(!singlePuzzle)) { + screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT); + } + else { + screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT); + } - if ( screen == NULL ) + if ( screen == nullptr ) { cerr << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl; exit(1); @@ -2989,14 +3331,16 @@ int main(int argc, char *argv[]) loadTheme(Config::getInstance()->getString("themename")); //Now sets the icon: SDL_Surface *icon = IMG_Load2("gfx/icon.png"); - SDL_WM_SetIcon(icon,NULL); + SDL_WM_SetIcon(icon,nullptr); if(verboseLevel) + { cout << "Images loaded" << endl; + } //InitMenues(); - BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects + BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100); player1 = &theGame; player2 = &theGame2; @@ -3007,9 +3351,9 @@ int main(int argc, char *argv[]) theGame2.GetTopY()=10000; theGame2.GetTopX()=10000; }*/ - theGame.DoPaintJob(); //Makes sure what there is something to paint + theGame.DoPaintJob(); //Makes sure what there is something to paint theGame2.DoPaintJob(); - theGame.SetGameOver(); //sets the game over in the beginning + theGame.SetGameOver(); //sets the game over in the beginning theGame2.SetGameOver(); @@ -3023,9 +3367,13 @@ int main(int argc, char *argv[]) } //Draws everything to screen if (!editorMode) + { MakeBackground(xsize,ysize,&theGame,&theGame2); + } else + { MakeBackground(xsize,ysize,&theGame); + } DrawIMG(background, screen, 0, 0); DrawEverything(xsize,ysize,&theGame,&theGame2); SDL_Flip(screen); @@ -3070,11 +3418,15 @@ int main(int argc, char *argv[]) //cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; if(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 << endl; + } ct = TimeHandler::addTime("totalTime",ct); if(verboseLevel) + { cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; + } Stats::getInstance()->save(); @@ -3128,13 +3480,13 @@ int runGame(int gametype, int level) theBallManeger = ballManeger(); theExplosionManeger = explosionManeger(); - BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects + BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100); 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(); - theGame.SetGameOver(); //sets the game over in the beginning + theGame.SetGameOver(); //sets the game over in the beginning theGame2.SetGameOver(); //Takes names from file instead @@ -3151,16 +3503,22 @@ int runGame(int gametype, int level) } //Draws everything to screen if (!editorMode) + { MakeBackground(xsize,ysize,&theGame,&theGame2); + } else + { MakeBackground(xsize,ysize,&theGame); + } /*DrawIMG(background, screen, 0, 0); DrawEverything(xsize,ysize,&theGame,&theGame2); SDL_Flip(screen);*/ //game loop int done = 0; if(verboseLevel) + { cout << "Starting game loop" << endl; + } bool mustsetupgame = true; @@ -3178,7 +3536,9 @@ int runGame(int gametype, int level) { int myLevel = PuzzleLevelSelect(1); if(myLevel == -1) + { return 1; + } theGame.NewStageGame(myLevel,SDL_GetTicks()); MakeBackground(xsize,ysize,&theGame,&theGame2); DrawIMG(background, screen, 0, 0); @@ -3190,7 +3550,9 @@ int runGame(int gametype, int level) break; case 3: if(StartSinglePlayerPuzzle(level)) + { return 1; + } break; case 4: { @@ -3226,7 +3588,9 @@ int runGame(int gametype, int level) SDL_Flip(screen); } - if (!(highPriority)) SDL_Delay(10); + if (!(highPriority)) { + SDL_Delay(10); + } if ((standardBackground)&&(!editorMode)) { @@ -3386,13 +3750,15 @@ int runGame(int gametype, int level) **************************** Repeating start ************************** **********************************************************************/ - keys = SDL_GetKeyState(NULL); + keys = SDL_GetKeyState(nullptr); //Also the joysticks: //Repeating not implemented //Player 1 start if (!(keys[keySettings[player1keys].up])) + { repeatingN[0]=false; + } while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat)) { theGame.MoveCursor('N'); @@ -3400,7 +3766,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player1keys].down])) + { repeatingS[0]=false; + } while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat)) { theGame.MoveCursor('S'); @@ -3408,7 +3776,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player1keys].left])) + { repeatingW[0]=false; + } while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat)) { timesRepeatedP1W++; @@ -3416,7 +3786,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player1keys].right])) + { repeatingE[0]=false; + } while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat)) { timesRepeatedP1E++; @@ -3427,7 +3799,9 @@ int runGame(int gametype, int level) //Player 2 start if (!(keys[keySettings[player2keys].up])) + { repeatingN[1]=false; + } while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat)) { theGame2.MoveCursor('N'); @@ -3435,7 +3809,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player2keys].down])) + { repeatingS[1]=false; + } while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat)) { theGame2.MoveCursor('S'); @@ -3443,7 +3819,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player2keys].left])) + { repeatingW[1]=false; + } while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat)) { theGame2.MoveCursor('W'); @@ -3451,7 +3829,9 @@ int runGame(int gametype, int level) } if (!(keys[keySettings[player2keys].right])) + { repeatingE[1]=false; + } while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat)) { theGame2.MoveCursor('E'); @@ -3505,9 +3885,13 @@ int runGame(int gametype, int level) timesRepeatedP1E=0; } if (joypad1.but1) + { theGame.SwitchAtCursor(); + } if (joypad1.but2) + { theGame.PushLine(); + } } else { @@ -3541,9 +3925,13 @@ int runGame(int gametype, int level) timesRepeatedP2E=0; } if (joypad1.but1) + { theGame2.SwitchAtCursor(); + } if (joypad1.but2) + { theGame2.PushLine(); + } } } if (joypad2.working && !theGame2.GetAIenabled()) @@ -3580,9 +3968,13 @@ int runGame(int gametype, int level) timesRepeatedP1E=0; } if (joypad2.but1) + { theGame.SwitchAtCursor(); + } if (joypad2.but2) + { theGame.PushLine(); + } } else { @@ -3616,9 +4008,13 @@ int runGame(int gametype, int level) timesRepeatedP2E=0; } if (joypad2.but1) + { theGame2.SwitchAtCursor(); + } if (joypad2.but2) + { theGame2.PushLine(); + } } } } @@ -3628,7 +4024,7 @@ int runGame(int gametype, int level) **********************************************************************/ - SDL_GetKeyState(NULL); + SDL_GetKeyState(nullptr); SDL_GetMouseState(&mousex,&mousey); @@ -3645,15 +4041,25 @@ int runGame(int gametype, int level) yLine-=2; xLine-=1; if ((yLine>10)&&(theGame.GetTowerHeight()<12)) + { yLine=10; + } if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11)) + { yLine=11; + } if (yLine<0) + { yLine=0; + } if (xLine<0) + { xLine=0; + } if (xLine>4) + { xLine=4; + } theGame.MoveCursorTo(xLine,yLine); } @@ -3666,15 +4072,25 @@ int runGame(int gametype, int level) yLine-=2; xLine-=1; if ((yLine>10)&&(theGame2.GetTowerHeight()<12)) + { yLine=10; + } if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11)) + { yLine=11; + } if (yLine<0) + { yLine=0; + } if (xLine<0) + { xLine=0; + } if (xLine>4) + { xLine=4; + } theGame2.MoveCursorTo(xLine,yLine); } @@ -3683,13 +4099,13 @@ int runGame(int gametype, int level) ********************************************************************/ // If the mouse button is released, make bMouseUp equal true - if (!SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) + if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { bMouseUp=true; } // If the mouse button 2 is released, make bMouseUp2 equal true - if ((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(3))!=SDL_BUTTON(3)) + if ((SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(3))!=SDL_BUTTON(3)) { bMouseUp2=true; } @@ -3697,7 +4113,7 @@ int runGame(int gametype, int level) if ((!singlePuzzle)&&(!editorMode)) { //read mouse events - if (SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(1) && bMouseUp) + if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { bMouseUp = false; DrawIMG(background, screen, 0, 0); @@ -3723,15 +4139,15 @@ int runGame(int gametype, int level) ********************************************************************/ if(stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x) - &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize) - &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize)) + &&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize) + &&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize)) { //Clicked the next button after a stage clear or puzzle theGame.nextLevel(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)) + &&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize) + &&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize)) { //Clicked the retry button theGame.retryLevel(SDL_GetTicks()); @@ -3742,25 +4158,25 @@ int runGame(int gametype, int level) } //Mouse button 2: - if ((SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2) + if ((SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2) { bMouseUp2=false; //The button is pressed /******************************************************************** **************** Here comes mouse play ****************************** ********************************************************************/ - - if (mouseplay1 && !theGame.GetAIenabled()) { - //player 1 - if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600)) { - theGame.PushLine(); - } - } - if (mouseplay2 && !theGame2.GetAIenabled()) { - //player 2 - if ((mousex > xsize-500)&&(mousey>100)&&(mousex 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600)) { + theGame.PushLine(); + } + } + if (mouseplay2 && !theGame2.GetAIenabled()) { + //player 2 + if ((mousex > xsize-500)&&(mousey>100)&&(mousextheGame2.GetScore()+theGame2.GetHandicap()) + { theGame.setPlayerWon(); + } else if (theGame.GetScore()+theGame.GetHandicap()addOne("puzzlesSolved"); + } puzzleCleared[Level] = true; std::ofstream outfile; outfile.open(puzzleSavePath.c_str(), ios::binary |ios::trunc); @@ -76,8 +77,9 @@ int LoadPuzzleStages( ) PhysFS::ifstream inFile(((std::string)("puzzles/"+puzzleName)).c_str()); inFile >> nrOfPuzzles; - if (nrOfPuzzles>maxNrOfPuzzleStages) + if (nrOfPuzzles>maxNrOfPuzzleStages) { nrOfPuzzles=maxNrOfPuzzleStages; + } for (int k=0; (k> nrOfMovesAllowed[k]; @@ -101,8 +103,9 @@ int LoadPuzzleStages( ) else { tempBool = false; - for (int i=0; i