From 10ccc825777c7ce8797fc58e1484dd93f19368cf Mon Sep 17 00:00:00 2001
From: Kelly Rauchenberger <fefferburbia@gmail.com>
Date: Thu, 18 Jun 2009 16:24:02 -0400
Subject: Created base

---
 Makefile       | 13 +++++++++++++
 gamestate.cpp  | 35 +++++++++++++++++++++++++++++++++++
 gamestate.h    | 15 +++++++++++++++
 includes.h     |  5 +++++
 mazeoflife.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mazeoflife.h   |  7 +++++++
 state.h        | 10 ++++++++++
 7 files changed, 143 insertions(+)
 create mode 100644 Makefile
 create mode 100644 gamestate.cpp
 create mode 100644 gamestate.h
 create mode 100644 includes.h
 create mode 100644 mazeoflife.cpp
 create mode 100644 mazeoflife.h
 create mode 100644 state.h

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0eb1738
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+OBJS = mazeoflife.o gamestate.o
+CC = g++
+CFLAGS = `pkg-config sdl --cflags`
+LIBS = `pkg-config sdl --libs`
+
+mazeoflife: $(OBJS)
+	$(CC) $(OBJS) $(LIBS) -o mazeoflife
+
+%.o: %.cpp
+	$(CC) -c $< $(CFLAGS) -o $@
+
+clean:
+	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 @@
+#include "includes.h"
+
+GameState::GameState(SDL_PixelFormat* fmt)
+{
+	int x,y;
+	for (y=0;y<HEIGHT;y++)
+	{
+		for (x=0;x<WIDTH;x++)
+		{
+			blocks[x][y] = false;
+		}
+	}
+
+	on = SDL_MapRGB(fmt, 0, 0, 0);
+	off = SDL_MapRGB(fmt, 255, 255, 255);
+}
+
+void GameState::render(SDL_Surface* screen)
+{
+	int x,y;
+
+	for (y=0;y<HEIGHT;y++)
+	{
+		for (x=0;x<WIDTH;x++)
+		{
+			SDL_Rect block;
+			block.x = x*16;
+			block.y = y*16;
+			block.w = 16;
+			block.h = 16;
+
+			SDL_FillRect(screen, &block, (blocks[x][y] ? on : off));
+		}
+	}
+}
diff --git a/gamestate.h b/gamestate.h
new file mode 100644
index 0000000..f906bf6
--- /dev/null
+++ b/gamestate.h
@@ -0,0 +1,15 @@
+#ifndef GAMESTATE_H
+#define GAMESTATE_H
+
+class GameState : public State {
+	private:
+		bool blocks[WIDTH][HEIGHT];
+		Uint32 on;
+		Uint32 off;
+
+	public:
+		GameState(SDL_PixelFormat* fmt);
+		void render(SDL_Surface* screen);
+};
+
+#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 @@
+#include <SDL.h>
+#include <stdio.h>
+#include "mazeoflife.h"
+#include "state.h"
+#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 @@
+#include "includes.h"
+
+bool gameSleep = false;
+
+int main(int argc, char *argv[])
+{    
+	/* Initialize defaults, Video and Audio */
+	if((SDL_Init(SDL_INIT_VIDEO)==-1)) { 
+		printf("Could not initialize SDL: %s.\n", SDL_GetError());
+		exit(-1);
+	}
+
+	/* Clean up on exit */
+	atexit(SDL_Quit);
+
+	/*
+	* Initialize the display in a 640x480 8-bit palettized mode,
+	* requesting a software surface
+	*/
+	SDL_Surface *screen = SDL_SetVideoMode(WIDTH*16, HEIGHT*16, 8, SDL_DOUBLEBUF);
+	if ( screen == NULL ) {
+		fprintf(stderr, "Couldn't set %dx%dx8 video mode: %s\n", WIDTH*16, WIDTH*16, SDL_GetError());
+		exit(1);
+	}
+
+	SDL_WM_SetCaption("Maze Of Life", NULL);
+
+	State* state = new GameState(screen->format);
+
+	SDL_Event anEvent;
+	for (;;)
+	{
+		while (SDL_PollEvent(&anEvent))
+		{
+			switch (anEvent.type)
+			{
+				case SDL_ACTIVEEVENT:
+					if (anEvent.active.state == SDL_APPINPUTFOCUS)
+					{
+						//	gameSleep = !anEvent.active.gain;
+					}
+
+					break;
+				case SDL_QUIT:
+					exit(0);
+
+					break;
+			}
+		}
+
+		state->render(screen);
+
+		SDL_Flip(screen);
+	}
+
+	exit(0);
+}
+
diff --git a/mazeoflife.h b/mazeoflife.h
new file mode 100644
index 0000000..3cc6d6d
--- /dev/null
+++ b/mazeoflife.h
@@ -0,0 +1,7 @@
+#ifndef MAZEOFLIFE_H
+#define MAZEOFLIFE_H
+
+const int WIDTH = 30;
+const int HEIGHT = 30;
+
+#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 @@
+#ifndef STATE_H
+#define STATE_H
+
+class State
+{
+	public:
+		virtual void render(SDL_Surface* screen) = 0;
+};
+
+#endif
-- 
cgit 1.4.1