summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2009-06-18 16:24:02 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2009-06-18 16:24:02 -0400
commit10ccc825777c7ce8797fc58e1484dd93f19368cf (patch)
tree75333f5f5abc653a621e442129613fd4fdade8c1
downloadmazeoflife-10ccc825777c7ce8797fc58e1484dd93f19368cf.tar.gz
mazeoflife-10ccc825777c7ce8797fc58e1484dd93f19368cf.tar.bz2
mazeoflife-10ccc825777c7ce8797fc58e1484dd93f19368cf.zip
Created base
-rw-r--r--Makefile13
-rw-r--r--gamestate.cpp35
-rw-r--r--gamestate.h15
-rw-r--r--includes.h5
-rw-r--r--mazeoflife.cpp58
-rw-r--r--mazeoflife.h7
-rw-r--r--state.h10
7 files changed, 143 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0eb1738 --- /dev/null +++ b/Makefile
@@ -0,0 +1,13 @@
1OBJS = mazeoflife.o gamestate.o
2CC = g++
3CFLAGS = `pkg-config sdl --cflags`
4LIBS = `pkg-config sdl --libs`
5
6mazeoflife: $(OBJS)
7 $(CC) $(OBJS) $(LIBS) -o mazeoflife
8
9%.o: %.cpp
10 $(CC) -c $< $(CFLAGS) -o $@
11
12clean:
13 rm -rdfv $(OBJS) mazeoflife
diff --git a/gamestate.cpp b/gamestate.cpp new file mode 100644 index 0000000..dac5272 --- /dev/null +++ b/gamestate.cpp
@@ -0,0 +1,35 @@
1#include "includes.h"
2
3GameState::GameState(SDL_PixelFormat* fmt)
4{
5 int x,y;
6 for (y=0;y<HEIGHT;y++)
7 {
8 for (x=0;x<WIDTH;x++)
9 {
10 blocks[x][y] = false;
11 }
12 }
13
14 on = SDL_MapRGB(fmt, 0, 0, 0);
15 off = SDL_MapRGB(fmt, 255, 255, 255);
16}
17
18void GameState::render(SDL_Surface* screen)
19{
20 int x,y;
21
22 for (y=0;y<HEIGHT;y++)
23 {
24 for (x=0;x<WIDTH;x++)
25 {
26 SDL_Rect block;
27 block.x = x*16;
28 block.y = y*16;
29 block.w = 16;
30 block.h = 16;
31
32 SDL_FillRect(screen, &block, (blocks[x][y] ? on : off));
33 }
34 }
35}
diff --git a/gamestate.h b/gamestate.h new file mode 100644 index 0000000..f906bf6 --- /dev/null +++ b/gamestate.h
@@ -0,0 +1,15 @@
1#ifndef GAMESTATE_H
2#define GAMESTATE_H
3
4class GameState : public State {
5 private:
6 bool blocks[WIDTH][HEIGHT];
7 Uint32 on;
8 Uint32 off;
9
10 public:
11 GameState(SDL_PixelFormat* fmt);
12 void render(SDL_Surface* screen);
13};
14
15#endif
diff --git a/includes.h b/includes.h new file mode 100644 index 0000000..83f3619 --- /dev/null +++ b/includes.h
@@ -0,0 +1,5 @@
1#include <SDL.h>
2#include <stdio.h>
3#include "mazeoflife.h"
4#include "state.h"
5#include "gamestate.h"
diff --git a/mazeoflife.cpp b/mazeoflife.cpp new file mode 100644 index 0000000..0e3464a --- /dev/null +++ b/mazeoflife.cpp
@@ -0,0 +1,58 @@
1#include "includes.h"
2
3bool gameSleep = false;
4
5int main(int argc, char *argv[])
6{
7 /* Initialize defaults, Video and Audio */
8 if((SDL_Init(SDL_INIT_VIDEO)==-1)) {
9 printf("Could not initialize SDL: %s.\n", SDL_GetError());
10 exit(-1);
11 }
12
13 /* Clean up on exit */
14 atexit(SDL_Quit);
15
16 /*
17 * Initialize the display in a 640x480 8-bit palettized mode,
18 * requesting a software surface
19 */
20 SDL_Surface *screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF);
21 if ( screen == NULL ) {
22 fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError());
23 exit(1);
24 }
25
26 SDL_WM_SetCaption("Maze Of Life", NULL);
27
28 State* state = new GameState(screen->format);
29
30 SDL_Event anEvent;
31 for (;;)
32 {
33 while (SDL_PollEvent(&anEvent))
34 {
35 switch (anEvent.type)
36 {
37 case SDL_ACTIVEEVENT:
38 if (anEvent.active.state == SDL_APPINPUTFOCUS)
39 {
40 // gameSleep = !anEvent.active.gain;
41 }
42
43 break;
44 case SDL_QUIT:
45 exit(0);
46
47 break;
48 }
49 }
50
51 state->render(screen);
52
53 SDL_Flip(screen);
54 }
55
56 exit(0);
57}
58
diff --git a/mazeoflife.h b/mazeoflife.h new file mode 100644 index 0000000..3cc6d6d --- /dev/null +++ b/mazeoflife.h
@@ -0,0 +1,7 @@
1#ifndef MAZEOFLIFE_H
2#define MAZEOFLIFE_H
3
4const int WIDTH = 30;
5const int HEIGHT = 30;
6
7#endif
diff --git a/state.h b/state.h new file mode 100644 index 0000000..dd5e52b --- /dev/null +++ b/state.h
@@ -0,0 +1,10 @@
1#ifndef STATE_H
2#define STATE_H
3
4class State
5{
6 public:
7 virtual void render(SDL_Surface* screen) = 0;
8};
9
10#endif