From 10ccc825777c7ce8797fc58e1484dd93f19368cf Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger 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 +#include +#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