summary refs log tree commit diff stats
path: root/mazeoflife.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mazeoflife.cpp')
-rw-r--r--mazeoflife.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 20bee1d..06a2ca2 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp
@@ -1,9 +1,12 @@
1#include "includes.h" 1#include "includes.h"
2 2
3SDL_Surface *screen;
3bool gameSleep = false; 4bool gameSleep = false;
4 5
5int main(int argc, char *argv[]) 6int main(int argc, char *argv[])
6{ 7{
8 srand(time(NULL));
9
7 /* Initialize defaults, Video and Audio */ 10 /* Initialize defaults, Video and Audio */
8 if((SDL_Init(SDL_INIT_VIDEO)==-1)) { 11 if((SDL_Init(SDL_INIT_VIDEO)==-1)) {
9 printf("Could not initialize SDL: %s.\n", SDL_GetError()); 12 printf("Could not initialize SDL: %s.\n", SDL_GetError());
@@ -17,7 +20,7 @@ int main(int argc, char *argv[])
17 * Initialize the display in a 640x480 8-bit palettized mode, 20 * Initialize the display in a 640x480 8-bit palettized mode,
18 * requesting a software surface 21 * requesting a software surface
19 */ 22 */
20 SDL_Surface *screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF); 23 screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF);
21 if ( screen == NULL ) { 24 if ( screen == NULL ) {
22 fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError()); 25 fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError());
23 exit(1); 26 exit(1);
@@ -61,3 +64,24 @@ int main(int argc, char *argv[])
61 exit(0); 64 exit(0);
62} 65}
63 66
67void wrap(int* x, int* y)
68{
69 if (*x < 0)
70 {
71 *x = WIDTH-(0-*x);
72 } else if (*y < 0)
73 {
74 *y = HEIGHT-(0-*y);
75 } else if (*x >= WIDTH)
76 {
77 *x = *x-WIDTH;
78 } else if (*y >= HEIGHT)
79 {
80 *y = *y-HEIGHT;
81 }
82}
83
84Uint32 getColor(int r, int g, int b)
85{
86 return SDL_MapRGB(screen->format, r, g, b);
87}