diff options
Diffstat (limited to 'mazeoflife.cpp')
| -rw-r--r-- | mazeoflife.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
| 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[]) | |||
| 7 | { | 7 | { |
| 8 | srand(time(NULL)); | 8 | srand(time(NULL)); |
| 9 | 9 | ||
| 10 | if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)==-1)) { | 10 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) |
| 11 | { | ||
| 11 | printf("Could not initialize SDL: %s.\n", SDL_GetError()); | 12 | printf("Could not initialize SDL: %s.\n", SDL_GetError()); |
| 12 | exit(-1); | 13 | exit(-1); |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 16 | if (TTF_Init() == -1) | ||
| 17 | { | ||
| 18 | printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError()); | ||
| 19 | exit(-1); | ||
| 20 | } | ||
| 21 | |||
| 15 | /* Clean up on exit */ | 22 | /* Clean up on exit */ |
| 16 | atexit(SDL_Quit); | 23 | atexit(SDL_Quit); |
| 24 | atexit(TTF_Quit); | ||
| 17 | 25 | ||
| 18 | SDL_WM_SetCaption("Maze Of Life", NULL); | 26 | SDL_WM_SetCaption("Maze Of Life", NULL); |
| 19 | 27 | ||
| @@ -49,7 +57,7 @@ int main(int argc, char *argv[]) | |||
| 49 | 57 | ||
| 50 | break; | 58 | break; |
| 51 | case SDL_KEYDOWN: | 59 | case SDL_KEYDOWN: |
| 52 | state->input(anEvent.key.keysym.sym); | 60 | state->input(anEvent.key.keysym); |
| 53 | 61 | ||
| 54 | break; | 62 | break; |
| 55 | } | 63 | } |
| @@ -96,3 +104,28 @@ Uint32 tick(Uint32 interval, void *param) | |||
| 96 | 104 | ||
| 97 | return interval; | 105 | return interval; |
| 98 | } | 106 | } |
| 107 | |||
| 108 | TTF_Font* loadFont(int size) | ||
| 109 | { | ||
| 110 | SDL_RWops* mono_rw = SDL_RWFromMem(&RESNAME(mono_ttf,start), (int) &RESNAME(mono_ttf,size)); | ||
| 111 | TTF_Font* tmpfont = TTF_OpenFontRW(mono_rw, 1, size); | ||
| 112 | |||
| 113 | if (tmpfont == NULL) | ||
| 114 | { | ||
| 115 | printf("Unable to load font: %s\n", TTF_GetError()); | ||
| 116 | exit(1); | ||
| 117 | } | ||
| 118 | |||
| 119 | return tmpfont; | ||
| 120 | } | ||
| 121 | |||
| 122 | const char* getDataFile() | ||
| 123 | { | ||
| 124 | #ifdef WINDOWS | ||
| 125 | char* dir = getenv("USERPROFILE"); | ||
| 126 | #else | ||
| 127 | char* dir = getenv("HOME"); | ||
| 128 | #endif | ||
| 129 | |||
| 130 | return (std::string(dir) + "/.molhslist").c_str(); | ||
| 131 | } | ||
