diff options
Diffstat (limited to 'src/mazeoflife.cpp')
| -rw-r--r-- | src/mazeoflife.cpp | 90 |
1 files changed, 0 insertions, 90 deletions
| diff --git a/src/mazeoflife.cpp b/src/mazeoflife.cpp deleted file mode 100644 index 7819ffd..0000000 --- a/src/mazeoflife.cpp +++ /dev/null | |||
| @@ -1,90 +0,0 @@ | |||
| 1 | #include "includes.h" | ||
| 2 | |||
| 3 | SDL_Surface *screen; | ||
| 4 | bool gameSleep = false; | ||
| 5 | |||
| 6 | int main(int argc, char *argv[]) | ||
| 7 | { | ||
| 8 | srand(time(NULL)); | ||
| 9 | |||
| 10 | /* Initialize defaults, Video and Audio */ | ||
| 11 | if((SDL_Init(SDL_INIT_VIDEO)==-1)) { | ||
| 12 | printf("Could not initialize SDL: %s.\n", SDL_GetError()); | ||
| 13 | exit(-1); | ||
| 14 | } | ||
| 15 | |||
| 16 | /* Clean up on exit */ | ||
| 17 | atexit(SDL_Quit); | ||
| 18 | |||
| 19 | SDL_WM_SetCaption("Maze Of Life", NULL); | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Initialize the display in a 640x480 8-bit palettized mode, | ||
| 23 | * requesting a software surface | ||
| 24 | */ | ||
| 25 | screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF); | ||
| 26 | if ( screen == NULL ) { | ||
| 27 | fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError()); | ||
| 28 | exit(1); | ||
| 29 | } | ||
| 30 | |||
| 31 | SDL_EnableKeyRepeat(100, 50); | ||
| 32 | |||
| 33 | State* state = new GameState(); | ||
| 34 | |||
| 35 | SDL_Event anEvent; | ||
| 36 | for (;;) | ||
| 37 | { | ||
| 38 | state->tick(); | ||
| 39 | |||
| 40 | while (SDL_PollEvent(&anEvent)) | ||
| 41 | { | ||
| 42 | switch (anEvent.type) | ||
| 43 | { | ||
| 44 | case SDL_ACTIVEEVENT: | ||
| 45 | if (anEvent.active.state == SDL_APPINPUTFOCUS) | ||
| 46 | { | ||
| 47 | gameSleep = !anEvent.active.gain; | ||
| 48 | } | ||
| 49 | |||
| 50 | break; | ||
| 51 | case SDL_QUIT: | ||
| 52 | exit(0); | ||
| 53 | |||
| 54 | break; | ||
| 55 | case SDL_KEYDOWN: | ||
| 56 | state->input(anEvent.key.keysym.sym); | ||
| 57 | |||
| 58 | break; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | state->render(screen); | ||
| 63 | |||
| 64 | SDL_Flip(screen); | ||
| 65 | } | ||
| 66 | |||
| 67 | exit(0); | ||
| 68 | } | ||
| 69 | |||
| 70 | void wrap(int* x, int* y) | ||
| 71 | { | ||
| 72 | if (*x < 0) | ||
| 73 | { | ||
| 74 | *x = WIDTH-(0-*x); | ||
| 75 | } else if (*y < 0) | ||
| 76 | { | ||
| 77 | *y = HEIGHT-(0-*y); | ||
| 78 | } else if (*x >= WIDTH) | ||
| 79 | { | ||
| 80 | *x = *x-WIDTH; | ||
| 81 | } else if (*y >= HEIGHT) | ||
| 82 | { | ||
| 83 | *y = *y-HEIGHT; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | Uint32 getColor(int r, int g, int b) | ||
| 88 | { | ||
| 89 | return SDL_MapRGB(screen->format, r, g, b); | ||
| 90 | } | ||
