From ba90715d26e84fd176a0d44bd8e5dde826067d93 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 8 Nov 2009 13:42:14 -0500 Subject: Added global highscore list You can now view and submit highscores to the global highscore list. If the connection fails, you are allowed to retry sending it so your score is not lost. The actual global highscore list is a PHP file and MySQL database that will need to be uploaded to Four Island Other for this to work. Some other things were done. Because it was discovered that the frequent window caption changes were making Maze Of Life crash, they were removed and the player is now notified of their score by the level number appearing in 100 point font at the beginning of each level during the doneWorking stage. Also, a cheat was added that allows you to play the game in fullscreen if you press F4 on a supporting platform. The player is now also slightly faster. Closes #104 --- Makefile | 4 +- chlstate.cpp | 6 +- gamestate.cpp | 83 +++++++++++---------- gamestate.h | 4 +- hsglobal.cpp | 63 ++++++++++++++++ hsglobal.h | 18 +++++ hslist.cpp | 113 +++++++++++++++++++++++++++++ hslist.h | 12 +++ hslocal.cpp | 2 - hsnew.cpp | 5 +- hssubmit.cpp | 226 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hssubmit.h | 34 +++++++++ htpstate.cpp | 2 - includes.h | 6 ++ mazeoflife.cpp | 23 ++++-- mazeoflife.h | 2 +- titlestate.cpp | 2 - 17 files changed, 545 insertions(+), 60 deletions(-) create mode 100644 hsglobal.cpp create mode 100644 hsglobal.h create mode 100644 hssubmit.cpp create mode 100644 hssubmit.h diff --git a/Makefile b/Makefile index b4a9b9b..27d70a9 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,9 @@ WINSRC = $(addsuffix win,$(SOURCES)) RES = $(wildcard resources/*) CRES = $(patsubst resources/%,build/%,$(addsuffix .o,$(RES))) LINCCFL = `sdl-config --cflags` -LINLDFL = `sdl-config --libs` -lSDL_ttf +LINLDFL = `sdl-config --libs` -lSDL_ttf -lSDL_net WINCCFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --cflags` -DWINDOWS -WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` -lSDL_ttf +WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` -lSDL_ttf -lSDL_net all: init $(LTARGET) $(WTARGET) linux: init $(LTARGET) diff --git a/chlstate.cpp b/chlstate.cpp index 3f3000d..14182a2 100644 --- a/chlstate.cpp +++ b/chlstate.cpp @@ -6,8 +6,6 @@ ChooseHighscoreListState::ChooseHighscoreListState() LOADIMAGE(pointer,pointer) selection = 0; - - SDL_WM_SetCaption("Maze Of Life - Choose Highscore List", NULL); } void ChooseHighscoreListState::input(SDL_keysym key) @@ -26,7 +24,9 @@ void ChooseHighscoreListState::input(SDL_keysym key) changeState(new LocalHighscoreListState(false)); break; - case 1: // Go to global highscore list + case 1: + changeState(new GlobalHighscoreListState()); + break; case 2: changeState(new TitleState()); diff --git a/gamestate.cpp b/gamestate.cpp index 9a50b32..95d1769 100644 --- a/gamestate.cpp +++ b/gamestate.cpp @@ -7,35 +7,34 @@ GameState::GameState() newGame = false; - info.playerx = 1; - info.playery = 1; - info.level = Level(); - info.doneMaking = false; - board = Board(&info); - - SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); + info = new Info(); + info->playerx = 1; + info->playery = 1; + info->level = Level(); + info->doneMaking = false; + board = Board(info); } void GameState::input(SDL_keysym key) { - if (info.doneMaking) + if (info->doneMaking) { switch (key.sym) { case SDLK_LEFT: - move(info.playerx-1, info.playery); + move(info->playerx-1, info->playery); break; case SDLK_RIGHT: - move(info.playerx+1, info.playery); + move(info->playerx+1, info->playery); break; case SDLK_UP: - move(info.playerx, info.playery-1); + move(info->playerx, info->playery-1); break; case SDLK_DOWN: - move(info.playerx, info.playery+1); + move(info->playerx, info->playery+1); break; case SDLK_ESCAPE: @@ -52,7 +51,7 @@ void GameState::input(SDL_keysym key) { fclose(hslist); - changeState(new NewHighscoreState(info.level.getLevel())); + changeState(new NewHighscoreState(info->level.getLevel())); } else { for (int i=0; igetLevel() < info.level.getLevel()) + if (h->getLevel() < info->level.getLevel()) { - changeState(new NewHighscoreState(info.level.getLevel())); + changeState(new NewHighscoreState(info->level.getLevel())); } else { changeState(new LocalHighscoreListState(true)); } } } else { - changeState(new NewHighscoreState(info.level.getLevel())); + changeState(new NewHighscoreState(info->level.getLevel())); } break; @@ -93,20 +92,17 @@ void GameState::tick() { switch (rand()%4) { - case 0: info.playerx = 1; info.playery = 1; break; - case 1: info.playerx = 1; info.playery = HEIGHT-2; break; - case 2: info.playerx = WIDTH-2; info.playery = HEIGHT-2; break; - case 3: info.playerx = WIDTH-2; info.playery = 1; break; + case 0: info->playerx = 1; info->playery = 1; break; + case 1: info->playerx = 1; info->playery = HEIGHT-2; break; + case 2: info->playerx = WIDTH-2; info->playery = HEIGHT-2; break; + case 3: info->playerx = WIDTH-2; info->playery = 1; break; } - info.level.incrementLevel(); - info.doneMaking = false; - board = Board(&info); + info->level.incrementLevel(); + info->doneMaking = false; + info->gens = 0; + board = Board(info); newGame = false; - - char title[32]; - sprintf(title, "Maze Of Life - Level %d", info.level.getLevel()); - SDL_WM_SetCaption(title, NULL); } board.tick(); @@ -119,8 +115,8 @@ void GameState::move(int x, int y) if (board.isObstructed(x,y)) return; if ((x==15)&&(y==15)) newGame = true; - info.playerx = x; - info.playery = y; + info->playerx = x; + info->playery = y; } void GameState::render(SDL_Surface* screen) @@ -128,20 +124,31 @@ void GameState::render(SDL_Surface* screen) // Paint maze board.render(screen); - // Paint player + // Paint event SDL_Rect block; - block.x = info.playerx*16; - block.y = info.playery*16; + block.x = 15*16; + block.y = 15*16; block.w = 16; block.h = 16; - SDL_FillRect(screen, &block, player_color); + SDL_FillRect(screen, &block, event_color); - // Paint event - block.x = 15*16; - block.y = 15*16; + if (!info->doneMaking) + { + SDL_Color fontColor = {0, 0, 0, 0}; + char levelnum[8]; + sprintf(levelnum, "%d", info->level.getLevel()); + SDL_Surface* title = TTF_RenderText_Solid(loadFont(100), levelnum, fontColor); + SDL_Rect tSpace = {240-(title->w/2), 240-(title->h/2), title->w, title->h}; + SDL_FillRect(screen, NULL, info->level.getDeadColor()); + SDL_BlitSurface(title, NULL, screen, &tSpace); + } - SDL_FillRect(screen, &block, event_color); + // Paint player + block.x = info->playerx*16; + block.y = info->playery*16; + + SDL_FillRect(screen, &block, player_color); } GameState::Level::Level() @@ -292,7 +299,7 @@ void GameState::Board::tick() } } - if (!info->doneMaking && ++gens > 100) info->doneMaking = true; + if (!info->doneMaking && ++info->gens > 50) info->doneMaking = true; } void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) diff --git a/gamestate.h b/gamestate.h index d1b90ad..28b85c0 100644 --- a/gamestate.h +++ b/gamestate.h @@ -29,6 +29,7 @@ class GameState : public State { int playerx, playery; Level level; bool doneMaking; + int gens; }; class Board @@ -37,7 +38,6 @@ class GameState : public State { bool blocks[WIDTH][HEIGHT]; void incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick); GameState::Info* info; - int gens; public: Board(); @@ -51,7 +51,7 @@ class GameState : public State { Uint32 player_color; Uint32 event_color; bool newGame; - Info info; + Info* info; Board board; void move(int x, int y); }; diff --git a/hsglobal.cpp b/hsglobal.cpp new file mode 100644 index 0000000..37db44b --- /dev/null +++ b/hsglobal.cpp @@ -0,0 +1,63 @@ +#include "includes.h" + +GlobalHighscoreListState::GlobalHighscoreListState() +{ + LOADIMAGE(options,hlo_rtm) + LOADIMAGE(pointer,pointer) + + list = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); + Uint32 bgColor = SDL_MapRGB(list->format, 255, 255, 255); + SDL_FillRect(list, NULL, bgColor); + SDL_SetColorKey(list, SDL_SRCCOLORKEY, bgColor); + TTF_Font* dataFont = loadFont(25); + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Fetching highscores....", fontColor); + SDL_Rect aSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; + SDL_BlitSurface(text, NULL, list, &aSpace); + + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); + SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; + SDL_BlitSurface(title, NULL, list, &tSpace); + + SDL_Rect oSpace = {0, 440, options->w, options->h}; + SDL_BlitSurface(options, NULL, list, &oSpace); + + SDL_CreateThread(&LoadHighscoreList, this); +} + +int GlobalHighscoreListState::LoadHighscoreList(void* pParam) +{ + GlobalHighscoreList* lhl = new GlobalHighscoreList(); + ((GlobalHighscoreListState*)pParam)->list = lhl->render(); + + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); + SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; + SDL_BlitSurface(title, NULL, ((GlobalHighscoreListState*)pParam)->list, &tSpace); + + SDL_Rect oSpace = {0, 440, ((GlobalHighscoreListState*)pParam)->options->w, ((GlobalHighscoreListState*)pParam)->options->h}; + SDL_BlitSurface(((GlobalHighscoreListState*)pParam)->options, NULL, ((GlobalHighscoreListState*)pParam)->list, &oSpace); +} + +void GlobalHighscoreListState::input(SDL_keysym key) +{ + if (key.sym == SDLK_RETURN) + { + changeState(new ChooseHighscoreListState()); + } +} + +void GlobalHighscoreListState::render(SDL_Surface* screen) +{ + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); + + SDL_BlitSurface(list, NULL, screen, NULL); + + SDL_Rect pSpace; + pSpace.x = 137; + pSpace.y = 449; + pSpace.w = pointer->w; + pSpace.h = pointer->h; + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); +} diff --git a/hsglobal.h b/hsglobal.h new file mode 100644 index 0000000..5b92b0e --- /dev/null +++ b/hsglobal.h @@ -0,0 +1,18 @@ +#ifndef HSGLOBAL_H +#define HSGLOBAL_H + +class GlobalHighscoreListState : public State { + public: + GlobalHighscoreListState(); + void input(SDL_keysym key); + void render(SDL_Surface* screen); + + private: + static int LoadHighscoreList(void* pParam); + + SDL_Surface* list; + SDL_Surface* options; + SDL_Surface* pointer; +}; + +#endif diff --git a/hslist.cpp b/hslist.cpp index d2901b4..ec99a77 100644 --- a/hslist.cpp +++ b/hslist.cpp @@ -76,10 +76,123 @@ std::vector HighscoreList::getLocalHighscores() std::vector HighscoreList::getGlobalHighscores() { + IPaddress ipaddress; + if (SDLNet_ResolveHost(&ipaddress, "other.fourisland.com", 80) == -1) + { + printf("Could not resolve host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 1; + } + + TCPsocket tcpsock = SDLNet_TCP_Open(&ipaddress); + if (!tcpsock) + { + printf("Could not connect to host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 2; + } + + char* headers = "GET /mol/hslist.php HTTP/1.1\nHost: other.fourisland.com\nUser-Agent: Maze Of Life v2.0\nAccept: text/plain\nKeep-Alive: 300\nConnection: keep-alive\n\n"; + if (SDLNet_TCP_Send(tcpsock, headers, strlen(headers)+1) < strlen(headers)) + { + printf("Connection closed by peer: %s\n", SDLNet_GetError()); + throw 3; + } + + std::stringstream download(std::stringstream::in | std::stringstream::out); + char hslist[1024]; + SDLNet_TCP_Recv(tcpsock, hslist, 1024); + download << hslist; + SDLNet_TCP_Close(tcpsock); + + char temps[256]; + download.getline(temps,256); + while (strlen(temps) != 1) + { + download.getline(temps,256); + } + + std::vector temp = std::vector(); + int scores; + download.getline(temps, 256); + if (sscanf(temps, "%d%*c", &scores) != 1) + { + printf("Recieved data is of an invalid format: %s\n", temps); + throw 4; + } + + for (int i=0; ihslist = getLocalHighscores(); } + +GlobalHighscoreList::GlobalHighscoreList() +{ + fail = false; + + try + { + this->hslist = getGlobalHighscores(); + } catch (int e) + { + fail = true; + } +} + +SDL_Surface* GlobalHighscoreList::render() +{ + if (fail) + { + SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); + Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255); + SDL_FillRect(tmp, NULL, bgColor); + SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, bgColor); + TTF_Font* dataFont = loadFont(25); + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Error retrieving highscores", fontColor); + SDL_Rect tSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; + SDL_BlitSurface(text, NULL, tmp, &tSpace); + + return tmp; + } else { + return super::render(); + } +} diff --git a/hslist.h b/hslist.h index 88c47c4..bebb85a 100644 --- a/hslist.h +++ b/hslist.h @@ -18,4 +18,16 @@ class LocalHighscoreList : public HighscoreList { LocalHighscoreList(); }; +class GlobalHighscoreList : public HighscoreList { + public: + GlobalHighscoreList(); + SDL_Surface* render(); + + private: + typedef HighscoreList super; + + protected: + bool fail; +}; + #endif diff --git a/hslocal.cpp b/hslocal.cpp index 17cae1b..c53f397 100644 --- a/hslocal.cpp +++ b/hslocal.cpp @@ -25,8 +25,6 @@ LocalHighscoreListState::LocalHighscoreListState(bool fromGame) SDL_BlitSurface(options, NULL, list, &oSpace); selection = 0; - - SDL_WM_SetCaption("Maze Of Life - Highscore List", NULL); } void LocalHighscoreListState::input(SDL_keysym key) diff --git a/hsnew.cpp b/hsnew.cpp index 3bec468..8b752a6 100644 --- a/hsnew.cpp +++ b/hsnew.cpp @@ -38,7 +38,6 @@ NewHighscoreState::NewHighscoreState(int level) rntSpace.w = newName->w; rntSpace.h = newName->h; - SDL_WM_SetCaption("Maze Of Life - New Highscore!", NULL); SDL_EnableUNICODE(1); } @@ -99,7 +98,9 @@ void NewHighscoreState::input(SDL_keysym key) changeState(new GameState()); break; - case 1: // Submit score to Global highscore list + case 1: + changeState(new SubmitHighscoreListState(hsname, level)); + break; case 2: changeState(new TitleState()); diff --git a/hssubmit.cpp b/hssubmit.cpp new file mode 100644 index 0000000..690749a --- /dev/null +++ b/hssubmit.cpp @@ -0,0 +1,226 @@ +#include "includes.h" + +SubmitHighscoreListState::SubmitHighscoreListState(char* hsname, int level) +{ + LOADIMAGE(pointer,pointer) + + this->hsname = hsname; + this->level = level; + this->scoreSent = false; + this->selection = 0; + + list = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0); + Uint32 bgColor = SDL_MapRGB(list->format, 255, 255, 255); + SDL_FillRect(list, NULL, bgColor); + SDL_SetColorKey(list, SDL_SRCCOLORKEY, bgColor); + TTF_Font* dataFont = loadFont(25); + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* text = TTF_RenderText_Blended(dataFont, "Sending highscore....", fontColor); + SDL_Rect aSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; + SDL_BlitSurface(text, NULL, list, &aSpace); + + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); + SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; + SDL_BlitSurface(title, NULL, list, &tSpace); + + SDL_CreateThread(&LoadHighscoreList, this); +} + +int SubmitHighscoreListState::LoadHighscoreList(void* pParam) +{ + SubmitHighscoreList* lhl = new SubmitHighscoreList(((SubmitHighscoreListState*)pParam)->hsname, ((SubmitHighscoreListState*)pParam)->level); + ((SubmitHighscoreListState*)pParam)->list = lhl->render(); + + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); + SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; + SDL_BlitSurface(title, NULL, ((SubmitHighscoreListState*)pParam)->list, &tSpace); + + if (lhl->hasFailed()) + { + LOADIMAGE(((SubmitHighscoreListState*)pParam)->options,hlo_passartm) + } else { + LOADIMAGE(((SubmitHighscoreListState*)pParam)->options,hlo_paartm) + } + + SDL_Rect oSpace = {0, 440, ((SubmitHighscoreListState*)pParam)->options->w, ((SubmitHighscoreListState*)pParam)->options->h}; + SDL_BlitSurface(((SubmitHighscoreListState*)pParam)->options, NULL, ((SubmitHighscoreListState*)pParam)->list, &oSpace); + + ((SubmitHighscoreListState*)pParam)->fail = lhl->hasFailed(); + ((SubmitHighscoreListState*)pParam)->newpos = lhl->getNewPos(); + ((SubmitHighscoreListState*)pParam)->scoreSent = true; +} + +void SubmitHighscoreListState::input(SDL_keysym key) +{ + if (scoreSent) + { + if ((key.sym == SDLK_LEFT) && (selection != 0)) + { + selection--; + } else if ((key.sym == SDLK_RIGHT) && (selection != (fail?2:1))) + { + selection++; + } else if (key.sym == SDLK_RETURN) + { + if (fail) + { + switch (selection) + { + case 0: + changeState(new GameState()); + + break; + case 1: + changeState(new SubmitHighscoreListState(hsname, level)); + + break; + case 2: + changeState(new TitleState()); + + break; + } + } else { + switch (selection) + { + case 0: + changeState(new GameState()); + + break; + case 1: + changeState(new TitleState()); + + break; + } + } + } + } +} + +void SubmitHighscoreListState::render(SDL_Surface* screen) +{ + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); + + if (scoreSent) + { + SDL_Rect pSpace; + if (fail) + { + pSpace.x = (selection==0?13:(selection==1?138:284)); + pSpace.y = 448; + } else { + pSpace.x = (selection==0?52:225); + pSpace.y = 447; + } + pSpace.w = pointer->w; + pSpace.h = pointer->h; + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); + + SDL_Rect eSpace = {0, newpos*40, 480, 40}; + SDL_FillRect(screen, &eSpace, SDL_MapRGB(screen->format, 255, 255, 0)); + } + + SDL_BlitSurface(list, NULL, screen, NULL); +} + +SubmitHighscoreListState::SubmitHighscoreList::SubmitHighscoreList(char* hsname, int level) +{ + fail = false; + + try + { + IPaddress ipaddress; + + if (SDLNet_ResolveHost(&ipaddress, "other.fourisland.com", 80) == -1) + { + printf("Could not resolve host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 1; + } + + TCPsocket tcpsock = SDLNet_TCP_Open(&ipaddress); + if (!tcpsock) + { + printf("Could not connect to host \"other.fourisland.com\": %s\n", SDLNet_GetError()); + throw 2; + } + + char body[256]; + sprintf(body, "name=%s&level=%d", hsname, level); + char headers[256]; + sprintf(headers, "POST /mol/hslist.php?add HTTP/1.1\nHost: other.fourisland.com\nUser-Agent: Maze Of Life v2.0\nAccept: text/plain\nKeep-Alive: 300\nConnection: keep-alive\nContent-Type: application/x-www-form-urlencoded\nContent-Length: %d\n\n%s\n", strlen(body), body); + if (SDLNet_TCP_Send(tcpsock, headers, strlen(headers)+1) < strlen(headers)) + { + printf("Connection closed by peer: %s\n", SDLNet_GetError()); + throw 3; + } + + std::stringstream download(std::stringstream::in | std::stringstream::out); + char hslist[1024]; + SDLNet_TCP_Recv(tcpsock, hslist, 1024); + download << hslist; + SDLNet_TCP_Close(tcpsock); + + char temps[256]; + download.getline(temps,256); + while (strlen(temps) != 1) + { + download.getline(temps,256); + } + + int rank; + download.getline(temps, 256); + if (sscanf(temps, "%d%*c", &rank) != 1) + { + printf("Recieved data is of an invalid format: %s\n", temps); + throw 4; + } + + this->hslist = getGlobalHighscores(); + + if (this->hslist.empty()) + { + printf("Global Highscore List cannot be empty after adding a score to it.\n"); + throw 5; + } + + if (rank > 10) + { + Highscore temph(hsname, level); + temph.setRank(rank); + + this->hslist[9] = temph; + this->newpos = 10; + } else { + std::vector::iterator it; + bool found = false; + + for (it=this->hslist.begin(); ithslist.end(); it++) + { + Highscore h = *it; + + if (!found) + { + if ((strcmp(h.getName(),hsname) == 0) && (h.getLevel() == level)) + { + this->newpos = h.getRank(); + found = true; + } + } + } + } + } catch (int e) + { + fail = true; + } +} + +int SubmitHighscoreListState::SubmitHighscoreList::getNewPos() +{ + return newpos; +} + +bool SubmitHighscoreListState::SubmitHighscoreList::hasFailed() +{ + return fail; +} diff --git a/hssubmit.h b/hssubmit.h new file mode 100644 index 0000000..243dab8 --- /dev/null +++ b/hssubmit.h @@ -0,0 +1,34 @@ +#ifndef HSSUBMIT_H +#define HSSUBMIT_H + +class SubmitHighscoreListState : public State { + public: + SubmitHighscoreListState(char* hsname, int level); + void input(SDL_keysym key); + void render(SDL_Surface* screen); + + private: + static int LoadHighscoreList(void* pParam); + + class SubmitHighscoreList : public GlobalHighscoreList { + public: + SubmitHighscoreList(char* hsname, int level); + int getNewPos(); + bool hasFailed(); + + private: + int newpos; + }; + + SDL_Surface* list; + SDL_Surface* options; + SDL_Surface* pointer; + char* hsname; + int level; + bool scoreSent; + int selection; + int newpos; + bool fail; +}; + +#endif diff --git a/htpstate.cpp b/htpstate.cpp index da4b6a2..03d02c6 100644 --- a/htpstate.cpp +++ b/htpstate.cpp @@ -8,8 +8,6 @@ HowToPlayState::HowToPlayState() secondPage = false; selection = 0; - - SDL_WM_SetCaption("Maze Of Life - How To Play", NULL); } void HowToPlayState::input(SDL_keysym key) diff --git a/includes.h b/includes.h index cd5c1e9..b7c0d56 100644 --- a/includes.h +++ b/includes.h @@ -1,10 +1,14 @@ #include #include +#include +#include #include #include #include #include #include +#include +#include #include "state.h" #include "mazeoflife.h" #include "resources.h" @@ -16,3 +20,5 @@ #include "hslist.h" #include "hslocal.h" #include "hsnew.h" +#include "hsglobal.h" +#include "hssubmit.h" diff --git a/mazeoflife.cpp b/mazeoflife.cpp index c744b28..45fc377 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp @@ -19,9 +19,16 @@ int main(int argc, char *argv[]) exit(-1); } + if (SDLNet_Init() == -1) + { + printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); + exit(-1); + } + /* Clean up on exit */ atexit(SDL_Quit); atexit(TTF_Quit); + atexit(SDLNet_Quit); SDL_WM_SetCaption("Maze Of Life", NULL); @@ -39,7 +46,7 @@ int main(int argc, char *argv[]) exit(1); } - SDL_EnableKeyRepeat(100, 50); + SDL_EnableKeyRepeat(100, 70); state = new TitleState(); @@ -57,15 +64,16 @@ int main(int argc, char *argv[]) break; case SDL_KEYDOWN: - state->input(anEvent.key.keysym); + if (anEvent.key.keysym.sym == SDLK_F4) + { + SDL_WM_ToggleFullScreen(screen); + } else { + state->input(anEvent.key.keysym); + } break; } } - - state->render(screen); - - SDL_Flip(screen); } exit(0); @@ -101,6 +109,9 @@ void changeState(State* nState) Uint32 tick(Uint32 interval, void *param) { state->tick(); + state->render(screen); + + SDL_Flip(screen); return interval; } diff --git a/mazeoflife.h b/mazeoflife.h index 411a87b..00a31cf 100644 --- a/mazeoflife.h +++ b/mazeoflife.h @@ -3,7 +3,7 @@ const int WIDTH = 30; const int HEIGHT = 30; -const int TICKDELAY = 10; +const int TICKDELAY = 5; void wrap(int* x, int* y); Uint32 getColor(int r, int g, int b); diff --git a/titlestate.cpp b/titlestate.cpp index ae18c48..2622caa 100644 --- a/titlestate.cpp +++ b/titlestate.cpp @@ -6,8 +6,6 @@ TitleState::TitleState() LOADIMAGE(pointer,pointer) selection = 0; - - SDL_WM_SetCaption("Maze Of Life", NULL); } void TitleState::input(SDL_keysym key) -- cgit 1.4.1