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 --- mazeoflife.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'mazeoflife.cpp') 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(); +} -- cgit 1.4.1