From c027f1b9cd6c9deb60931a7f9f75bb4ee130291b Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Oct 2009 15:24:07 -0400 Subject: Added local highscore list You can now view and add to a local highscore list. A change to State was necessary due to how the user's name would be entered into the highscore list and thus all states have been modified. Refs #104 --- Makefile | 4 +- chlstate.cpp | 12 +-- chlstate.h | 2 +- gamestate.cpp | 47 +++++++++- gamestate.h | 2 +- highscore.cpp | 27 ++++++ highscore.h | 18 ++++ hslist.cpp | 85 ++++++++++++++++++ hslist.h | 21 +++++ hslocal.cpp | 84 +++++++++++++++++ hslocal.h | 18 ++++ hsnew.cpp | 219 +++++++++++++++++++++++++++++++++++++++++++++ hsnew.h | 35 ++++++++ htpstate.cpp | 8 +- htpstate.h | 2 +- includes.h | 7 ++ mazeoflife.cpp | 37 +++++++- mazeoflife.h | 2 + resources.h | 4 + resources/hlo_paartm.bmp | Bin 0 -> 76938 bytes resources/hlo_passartm.bmp | Bin 0 -> 76938 bytes resources/hlo_rtm.bmp | Bin 0 -> 76938 bytes resources/mono.ttf | Bin 0 -> 259628 bytes state.h | 2 +- titlestate.cpp | 8 +- titlestate.h | 2 +- 26 files changed, 621 insertions(+), 25 deletions(-) create mode 100644 highscore.cpp create mode 100644 highscore.h create mode 100644 hslist.cpp create mode 100644 hslist.h create mode 100644 hslocal.cpp create mode 100644 hslocal.h create mode 100644 hsnew.cpp create mode 100644 hsnew.h create mode 100644 resources/hlo_paartm.bmp create mode 100644 resources/hlo_passartm.bmp create mode 100644 resources/hlo_rtm.bmp create mode 100644 resources/mono.ttf diff --git a/Makefile b/Makefile index 9bad9b2..b4a9b9b 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` +LINLDFL = `sdl-config --libs` -lSDL_ttf 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` +WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` -lSDL_ttf all: init $(LTARGET) $(WTARGET) linux: init $(LTARGET) diff --git a/chlstate.cpp b/chlstate.cpp index 24dd674..3f3000d 100644 --- a/chlstate.cpp +++ b/chlstate.cpp @@ -10,19 +10,21 @@ ChooseHighscoreListState::ChooseHighscoreListState() SDL_WM_SetCaption("Maze Of Life - Choose Highscore List", NULL); } -void ChooseHighscoreListState::input(SDLKey key) +void ChooseHighscoreListState::input(SDL_keysym key) { - if ((key == SDLK_UP) && (selection != 0)) + if ((key.sym == SDLK_UP) && (selection != 0)) { selection--; - } else if ((key == SDLK_DOWN) && (selection != 2)) + } else if ((key.sym == SDLK_DOWN) && (selection != 2)) { selection++; - } else if (key == SDLK_RETURN) + } else if (key.sym == SDLK_RETURN) { switch (selection) { - case 0: // Go to local highscore list + case 0: + changeState(new LocalHighscoreListState(false)); + break; case 1: // Go to global highscore list break; diff --git a/chlstate.h b/chlstate.h index a8905e2..15f1d05 100644 --- a/chlstate.h +++ b/chlstate.h @@ -4,7 +4,7 @@ class ChooseHighscoreListState : public State { public: ChooseHighscoreListState(); - void input(SDLKey key); + void input(SDL_keysym key); void render(SDL_Surface* screen); private: diff --git a/gamestate.cpp b/gamestate.cpp index c312bfe..9a50b32 100644 --- a/gamestate.cpp +++ b/gamestate.cpp @@ -16,11 +16,11 @@ GameState::GameState() SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); } -void GameState::input(SDLKey key) +void GameState::input(SDL_keysym key) { if (info.doneMaking) { - switch (key) + switch (key.sym) { case SDLK_LEFT: move(info.playerx-1, info.playery); @@ -39,7 +39,48 @@ void GameState::input(SDLKey key) break; case SDLK_ESCAPE: - changeState(new TitleState()); + std::ifstream exists(getDataFile()); + if (exists) + { + FILE* hslist = fopen(getDataFile(), "r"); + int scores; + Highscore* h; + + fscanf(hslist, "%d%*c", &scores); + + if (scores < 10) + { + fclose(hslist); + + changeState(new NewHighscoreState(info.level.getLevel())); + } else { + for (int i=0; igetLevel() < info.level.getLevel()) + { + changeState(new NewHighscoreState(info.level.getLevel())); + } else { + changeState(new LocalHighscoreListState(true)); + } + } + } else { + changeState(new NewHighscoreState(info.level.getLevel())); + } break; } diff --git a/gamestate.h b/gamestate.h index 7d9d798..d1b90ad 100644 --- a/gamestate.h +++ b/gamestate.h @@ -4,7 +4,7 @@ class GameState : public State { public: GameState(); - void input(SDLKey key); + void input(SDL_keysym key); void tick(); void render(SDL_Surface* screen); diff --git a/highscore.cpp b/highscore.cpp new file mode 100644 index 0000000..6811fa8 --- /dev/null +++ b/highscore.cpp @@ -0,0 +1,27 @@ +#include "includes.h" + +Highscore::Highscore(char* name, int level) +{ + this->name = name; + this->level = level; +} + +char* Highscore::getName() +{ + return name; +} + +int Highscore::getLevel() +{ + return level; +} + +void Highscore::setRank(int rank) +{ + this->rank = rank; +} + +int Highscore::getRank() +{ + return rank; +} diff --git a/highscore.h b/highscore.h new file mode 100644 index 0000000..721b226 --- /dev/null +++ b/highscore.h @@ -0,0 +1,18 @@ +#ifndef HIGHSCORE_H +#define HIGHSCORE_H + +class Highscore { + public: + Highscore(char* name, int level); + char* getName(); + int getLevel(); + void setRank(int rank); + int getRank(); + + private: + char* name; + int level; + int rank; +}; + +#endif diff --git a/hslist.cpp b/hslist.cpp new file mode 100644 index 0000000..d2901b4 --- /dev/null +++ b/hslist.cpp @@ -0,0 +1,85 @@ +#include "includes.h" + +SDL_Surface* HighscoreList::render() +{ + 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* posFont = loadFont(40); + TTF_Font* dataFont = loadFont(25); + SDL_Color fontColor = {0, 0, 0, 0}; + + for (int i=0; i HighscoreList::getLocalHighscores() +{ + std::vector temp = std::vector(); + + std::ifstream exists(getDataFile()); + if (exists) + { + FILE* hslist = fopen(getDataFile(), "r"); + int scores; + fscanf(hslist, "%d%*c", &scores); + + for (int i=0; i HighscoreList::getGlobalHighscores() +{ + +} + +LocalHighscoreList::LocalHighscoreList() +{ + this->hslist = getLocalHighscores(); +} diff --git a/hslist.h b/hslist.h new file mode 100644 index 0000000..88c47c4 --- /dev/null +++ b/hslist.h @@ -0,0 +1,21 @@ +#ifndef HSLIST_H +#define HSLIST_H + +class HighscoreList +{ + public: + SDL_Surface* render(); + + protected: + std::vector getLocalHighscores(); + std::vector getGlobalHighscores(); + + std::vector hslist; +}; + +class LocalHighscoreList : public HighscoreList { + public: + LocalHighscoreList(); +}; + +#endif diff --git a/hslocal.cpp b/hslocal.cpp new file mode 100644 index 0000000..17cae1b --- /dev/null +++ b/hslocal.cpp @@ -0,0 +1,84 @@ +#include "includes.h" + +LocalHighscoreListState::LocalHighscoreListState(bool fromGame) +{ + this->fromGame = fromGame; + + if (fromGame) + { + LOADIMAGE(options,hlo_paartm) + } else { + LOADIMAGE(options,hlo_rtm) + } + + LOADIMAGE(pointer,pointer) + + LocalHighscoreList* lhl = new LocalHighscoreList(); + 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, list, &tSpace); + + SDL_Rect oSpace = {0, 440, options->w, options->h}; + SDL_BlitSurface(options, NULL, list, &oSpace); + + selection = 0; + + SDL_WM_SetCaption("Maze Of Life - Highscore List", NULL); +} + +void LocalHighscoreListState::input(SDL_keysym key) +{ + if (fromGame) + { + if ((key.sym == SDLK_LEFT) && (selection != 0)) + { + selection--; + } else if ((key.sym == SDLK_RIGHT) && (selection != 1)) + { + selection++; + } else if (key.sym == SDLK_RETURN) + { + switch (selection) + { + case 0: + changeState(new GameState()); + + break; + case 1: + changeState(new TitleState()); + + break; + } + } + } else { + if (key.sym == SDLK_RETURN) + { + changeState(new ChooseHighscoreListState()); + } + } +} + +void LocalHighscoreListState::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.w = pointer->w; + pSpace.h = pointer->h; + + if (fromGame) + { + pSpace.x = (selection==0?52:225); + pSpace.y = 447; + } else { + pSpace.x = 137; + pSpace.y = 449; + } + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); +} diff --git a/hslocal.h b/hslocal.h new file mode 100644 index 0000000..8708d03 --- /dev/null +++ b/hslocal.h @@ -0,0 +1,18 @@ +#ifndef HSLOCAL_H +#define HSLOCAL_H + +class LocalHighscoreListState : public State { + public: + LocalHighscoreListState(bool fromGame); + void input(SDL_keysym key); + void render(SDL_Surface* screen); + + private: + SDL_Surface* list; + SDL_Surface* options; + SDL_Surface* pointer; + int selection; + bool fromGame; +}; + +#endif diff --git a/hsnew.cpp b/hsnew.cpp new file mode 100644 index 0000000..3bec468 --- /dev/null +++ b/hsnew.cpp @@ -0,0 +1,219 @@ +#include "includes.h" + +NewHighscoreState::NewHighscoreState(int level) +{ + this->level = level; + + LOADIMAGE(options,hlo_passartm) + LOADIMAGE(pointer,pointer) + + lhl = new NewHighscoreList(level); + newpos = lhl->getNewPos(); + list = lhl->render(); + + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor); + SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; + SDL_BlitSurface(title, NULL, list, &tSpace); + + this->enterName = true; + this->lp = 0; + this->hsname = (char*) calloc(25, sizeof(char)); + + SDL_Surface* text = TTF_RenderText_Blended(loadFont(25), "Enter Your Name", fontColor); + SDL_Rect oSpace = {240-(text->w/2), 440, text->w, text->h}; + SDL_BlitSurface(text, NULL, list, &oSpace); + + selection = 0; + + int posw, posh; + char pos[3]; // 2 max characters in rank plus the colon at the end + sprintf(pos, "%d:", newpos); + char name[26]; // 25 max characters in username plus the space at the beginning + sprintf(name, " %s", hsname); + newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); + TTF_SizeText(loadFont(40), pos, &posw, &posh); + rntSpace.x = posw; + rntSpace.y = newpos*40+((posh/2)-(newName->h/2)); + rntSpace.w = newName->w; + rntSpace.h = newName->h; + + SDL_WM_SetCaption("Maze Of Life - New Highscore!", NULL); + SDL_EnableUNICODE(1); +} + +void NewHighscoreState::input(SDL_keysym key) +{ + if (enterName) + { + if ((key.sym == SDLK_BACKSPACE) && (lp > 0)) + { + hsname[--lp] = 0; + + SDL_Color fontColor = {0, 0, 0, 0}; + char name[26]; // 25 max characters in username plus the space at the beginning + sprintf(name, " %s", hsname); + newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); + rntSpace.w = newName->w; + rntSpace.h = newName->h; + } else if ((key.sym == SDLK_RETURN) && (hsname[0] != 0)) + { + SDL_EnableUNICODE(0); + enterName = false; + + lhl->addToList(hsname); + LocalHighscoreList* lhl2 = new LocalHighscoreList(); + list = lhl2->render(); + + SDL_Color fontColor = {0, 0, 0, 0}; + SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", 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); + } else if (((key.unicode & 0xFF80) == 0) && (key.unicode >= 32 && key.unicode < 127) && (lp < 25)) + { + hsname[lp++] = key.unicode & 0x7f; + hsname[lp] = 0; + + SDL_Color fontColor = {0, 0, 0, 0}; + char name[26]; // 25 max characters in username plus the space at the beginning + sprintf(name, " %s", hsname); + newName = TTF_RenderText_Blended(loadFont(25), name, fontColor); + rntSpace.w = newName->w; + rntSpace.h = newName->h; + } + } else { + if ((key.sym == SDLK_LEFT) && (selection != 0)) + { + selection--; + } else if ((key.sym == SDLK_RIGHT) && (selection != 2)) + { + selection++; + } else if (key.sym == SDLK_RETURN) + { + switch (selection) + { + case 0: + changeState(new GameState()); + + break; + case 1: // Submit score to Global highscore list + break; + case 2: + changeState(new TitleState()); + + break; + } + } + } +} + +void NewHighscoreState::render(SDL_Surface* screen) +{ + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); + + 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); + + if (enterName) + { + SDL_BlitSurface(newName, NULL, screen, &rntSpace); + } else { + SDL_Rect pSpace; + pSpace.x = (selection==0?13:(selection==1?138:284)); + pSpace.y = 448; + pSpace.w = pointer->w; + pSpace.h = pointer->h; + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); + } +} + +NewHighscoreState::NewHighscoreList::NewHighscoreList(int level) +{ + this->hslist = getLocalHighscores(); + + if (this->hslist.empty()) + { + Highscore n = Highscore("", level); + n.setRank(1); + + this->hslist.push_back(n); + this->newpos = n.getRank(); + } else { + std::vector::iterator it; + bool found = false; + int lastrank; + int i=0; + + for (it=this->hslist.begin(); ithslist.end(); it++) + { + Highscore h = *it; + lastrank = h.getRank(); + + if (!found) + { + if (h.getLevel() < level) + { + Highscore n = Highscore("", level); + n.setRank(h.getRank()); + + this->hslist.insert(it, n); + this->newpos = n.getRank(); + + if (this->hslist.size() > 10) + { + this->hslist.pop_back(); + } + + found = true; + } + } else { + //this->hslist[i].setRank(h.getRank()+1); + } + + i++; + } + + if (!found) + { + Highscore n = Highscore("", level); + n.setRank(lastrank+1); + + this->hslist.push_back(n); + this->newpos = n.getRank(); + } + } +} + +int NewHighscoreState::NewHighscoreList::getNewPos() +{ + return newpos; +} + +void NewHighscoreState::NewHighscoreList::addToList(char* name) +{ + FILE* hsfile = fopen(getDataFile(), "w"); + fprintf(hsfile, "%d ", this->hslist.size()); + + std::vector::iterator it; + + for (it=this->hslist.begin(); ithslist.end(); it++) + { + Highscore h = *it; + + if (h.getName() == "") + { + h = Highscore(name, h.getLevel()); + h.setRank(newpos); + } + + fprintf(hsfile, "%d%s%d ", strlen(h.getName()), h.getName(), h.getLevel()); + } + + fclose(hsfile); +} diff --git a/hsnew.h b/hsnew.h new file mode 100644 index 0000000..123ac53 --- /dev/null +++ b/hsnew.h @@ -0,0 +1,35 @@ +#ifndef HSNEW_H +#define HSNEW_H + +class NewHighscoreState : public State { + public: + NewHighscoreState(int level); + void input(SDL_keysym key); + void render(SDL_Surface* screen); + + private: + class NewHighscoreList : public HighscoreList { + public: + NewHighscoreList(int level); + int getNewPos(); + void addToList(char* name); + + private: + int newpos; + }; + + SDL_Surface* list; + SDL_Surface* options; + SDL_Surface* pointer; + int selection; + int level; + int newpos; + int lp; + char* hsname; + bool enterName; + SDL_Rect rntSpace; + SDL_Surface* newName; + NewHighscoreList* lhl; +}; + +#endif diff --git a/htpstate.cpp b/htpstate.cpp index 711dca4..da4b6a2 100644 --- a/htpstate.cpp +++ b/htpstate.cpp @@ -12,15 +12,15 @@ HowToPlayState::HowToPlayState() SDL_WM_SetCaption("Maze Of Life - How To Play", NULL); } -void HowToPlayState::input(SDLKey key) +void HowToPlayState::input(SDL_keysym key) { - if ((key == SDLK_LEFT) && (selection != 0)) + if ((key.sym == SDLK_LEFT) && (selection != 0)) { selection--; - } else if ((key == SDLK_RIGHT) && (selection != 1)) + } else if ((key.sym == SDLK_RIGHT) && (selection != 1)) { selection++; - } else if (key == SDLK_RETURN) + } else if (key.sym == SDLK_RETURN) { switch (selection) { diff --git a/htpstate.h b/htpstate.h index 2639d1a..79c66ba 100644 --- a/htpstate.h +++ b/htpstate.h @@ -4,7 +4,7 @@ class HowToPlayState : public State { public: HowToPlayState(); - void input(SDLKey key); + void input(SDL_keysym key); void render(SDL_Surface* screen); private: diff --git a/includes.h b/includes.h index a36c456..cd5c1e9 100644 --- a/includes.h +++ b/includes.h @@ -1,7 +1,10 @@ #include +#include #include #include #include +#include +#include #include "state.h" #include "mazeoflife.h" #include "resources.h" @@ -9,3 +12,7 @@ #include "htpstate.h" #include "chlstate.h" #include "gamestate.h" +#include "highscore.h" +#include "hslist.h" +#include "hslocal.h" +#include "hsnew.h" diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 0dbca55..c744b28 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp @@ -7,13 +7,21 @@ int main(int argc, char *argv[]) { srand(time(NULL)); - if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)==-1)) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) + { printf("Could not initialize SDL: %s.\n", SDL_GetError()); exit(-1); } + if (TTF_Init() == -1) + { + printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError()); + exit(-1); + } + /* Clean up on exit */ atexit(SDL_Quit); + atexit(TTF_Quit); SDL_WM_SetCaption("Maze Of Life", NULL); @@ -49,7 +57,7 @@ int main(int argc, char *argv[]) break; case SDL_KEYDOWN: - state->input(anEvent.key.keysym.sym); + state->input(anEvent.key.keysym); break; } @@ -96,3 +104,28 @@ Uint32 tick(Uint32 interval, void *param) return interval; } + +TTF_Font* loadFont(int size) +{ + SDL_RWops* mono_rw = SDL_RWFromMem(&RESNAME(mono_ttf,start), (int) &RESNAME(mono_ttf,size)); + TTF_Font* tmpfont = TTF_OpenFontRW(mono_rw, 1, size); + + if (tmpfont == NULL) + { + printf("Unable to load font: %s\n", TTF_GetError()); + exit(1); + } + + return tmpfont; +} + +const char* getDataFile() +{ +#ifdef WINDOWS + char* dir = getenv("USERPROFILE"); +#else + char* dir = getenv("HOME"); +#endif + + return (std::string(dir) + "/.molhslist").c_str(); +} diff --git a/mazeoflife.h b/mazeoflife.h index 1f43214..411a87b 100644 --- a/mazeoflife.h +++ b/mazeoflife.h @@ -9,5 +9,7 @@ void wrap(int* x, int* y); Uint32 getColor(int r, int g, int b); void changeState(State* nState); Uint32 tick(Uint32 interval, void *param); +TTF_Font* loadFont(int size); +const char* getDataFile(); #endif diff --git a/resources.h b/resources.h index fc9229a..4743950 100644 --- a/resources.h +++ b/resources.h @@ -16,5 +16,9 @@ DEFRES(pointer_bmp) DEFRES(htp1_bmp) DEFRES(htp2_bmp) DEFRES(chl_bmp) +DEFRES(hlo_rtm_bmp) +DEFRES(hlo_paartm_bmp) +DEFRES(hlo_passartm_bmp) +DEFRES(mono_ttf) #endif diff --git a/resources/hlo_paartm.bmp b/resources/hlo_paartm.bmp new file mode 100644 index 0000000..72a1bf2 Binary files /dev/null and b/resources/hlo_paartm.bmp differ diff --git a/resources/hlo_passartm.bmp b/resources/hlo_passartm.bmp new file mode 100644 index 0000000..6c57e98 Binary files /dev/null and b/resources/hlo_passartm.bmp differ diff --git a/resources/hlo_rtm.bmp b/resources/hlo_rtm.bmp new file mode 100644 index 0000000..c05c208 Binary files /dev/null and b/resources/hlo_rtm.bmp differ diff --git a/resources/mono.ttf b/resources/mono.ttf new file mode 100644 index 0000000..1feefc2 Binary files /dev/null and b/resources/mono.ttf differ diff --git a/state.h b/state.h index bcc7e4a..7373940 100644 --- a/state.h +++ b/state.h @@ -4,7 +4,7 @@ class State { public: - virtual void input(SDLKey key) {}; + virtual void input(SDL_keysym key) {}; virtual void tick() {}; virtual void render(SDL_Surface* screen) {}; }; diff --git a/titlestate.cpp b/titlestate.cpp index 980e3b6..ae18c48 100644 --- a/titlestate.cpp +++ b/titlestate.cpp @@ -10,15 +10,15 @@ TitleState::TitleState() SDL_WM_SetCaption("Maze Of Life", NULL); } -void TitleState::input(SDLKey key) +void TitleState::input(SDL_keysym key) { - if ((key == SDLK_UP) && (selection != 0)) + if ((key.sym == SDLK_UP) && (selection != 0)) { selection--; - } else if ((key == SDLK_DOWN) && (selection != 3)) + } else if ((key.sym == SDLK_DOWN) && (selection != 3)) { selection++; - } else if (key == SDLK_RETURN) + } else if (key.sym == SDLK_RETURN) { switch (selection) { diff --git a/titlestate.h b/titlestate.h index 9056626..6519ecf 100644 --- a/titlestate.h +++ b/titlestate.h @@ -4,7 +4,7 @@ class TitleState : public State { public: TitleState(); - void input(SDLKey key); + void input(SDL_keysym key); void render(SDL_Surface* screen); private: -- cgit 1.4.1