summary refs log tree commit diff stats
path: root/src/mazeoflife.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2009-06-19 10:57:53 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2009-06-19 10:57:53 -0400
commit684a27ce13a9a08f4f1d94621cdab1232d2d33cf (patch)
tree4b85d42802b588767b6ac7b6972f2093154c7196 /src/mazeoflife.cpp
parent1e3808b3338ff3b1499e000ce1f23e87d6050b8c (diff)
downloadmazeoflife-684a27ce13a9a08f4f1d94621cdab1232d2d33cf.tar.gz
mazeoflife-684a27ce13a9a08f4f1d94621cdab1232d2d33cf.tar.bz2
mazeoflife-684a27ce13a9a08f4f1d94621cdab1232d2d33cf.zip
Added GNU configure stuff
Diffstat (limited to 'src/mazeoflife.cpp')
-rw-r--r--src/mazeoflife.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/mazeoflife.cpp b/src/mazeoflife.cpp new file mode 100644 index 0000000..7819ffd --- /dev/null +++ b/src/mazeoflife.cpp
@@ -0,0 +1,90 @@
1#include "includes.h"
2
3SDL_Surface *screen;
4bool gameSleep = false;
5
6int 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
70void 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
87Uint32 getColor(int r, int g, int b)
88{
89 return SDL_MapRGB(screen->format, r, g, b);
90}