From ab18806cddf99514e7ac8d970587e5f1d6d01603 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 19 Jun 2009 20:46:53 -0400 Subject: Added title screen Refs #103 --- Makefile | 2 +- dummystate.h | 12 ++++++++++++ includes.h | 4 +++- mazeoflife.cpp | 8 +++++++- mazeoflife.h | 1 + pointer.bmp | Bin 0 -> 2038 bytes state.h | 2 +- title.bmp | Bin 0 -> 921738 bytes titlestate.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ titlestate.h | 16 ++++++++++++++++ 10 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 dummystate.h create mode 100644 pointer.bmp create mode 100644 title.bmp create mode 100644 titlestate.cpp create mode 100644 titlestate.h diff --git a/Makefile b/Makefile index 7e812d9..b79fe63 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -OBJS = mazeoflife.o gamestate.o +OBJS = mazeoflife.o titlestate.o gamestate.o CC = g++ CFLAGS = `pkg-config sdl --cflags` LIBS = `pkg-config sdl --libs` diff --git a/dummystate.h b/dummystate.h new file mode 100644 index 0000000..0f1e48b --- /dev/null +++ b/dummystate.h @@ -0,0 +1,12 @@ +#ifndef DUMMYSTATE_H +#define DUMMYSTATE_H + +class DummyState : public State +{ + public: + DummyState() {}; + void input(SDLKey key) {}; + void render(SDL_Surface* screen) {}; +}; + +#endif diff --git a/includes.h b/includes.h index a47a307..aec00e7 100644 --- a/includes.h +++ b/includes.h @@ -2,6 +2,8 @@ #include #include #include -#include "mazeoflife.h" #include "state.h" +#include "dummystate.h" +#include "mazeoflife.h" +#include "titlestate.h" #include "gamestate.h" diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 7819ffd..ad1fda3 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp @@ -2,6 +2,7 @@ SDL_Surface *screen; bool gameSleep = false; +State* state = new DummyState(); int main(int argc, char *argv[]) { @@ -30,7 +31,7 @@ int main(int argc, char *argv[]) SDL_EnableKeyRepeat(100, 50); - State* state = new GameState(); + state = new TitleState(); SDL_Event anEvent; for (;;) @@ -88,3 +89,8 @@ Uint32 getColor(int r, int g, int b) { return SDL_MapRGB(screen->format, r, g, b); } + +void changeState(State* nState) +{ + state = nState; +} diff --git a/mazeoflife.h b/mazeoflife.h index 6af0cf4..d81c3ea 100644 --- a/mazeoflife.h +++ b/mazeoflife.h @@ -6,5 +6,6 @@ const int HEIGHT = 30; void wrap(int* x, int* y); Uint32 getColor(int r, int g, int b); +void changeState(State* nState); #endif diff --git a/pointer.bmp b/pointer.bmp new file mode 100644 index 0000000..e1cee4e Binary files /dev/null and b/pointer.bmp differ diff --git a/state.h b/state.h index 1a97a1b..aa83718 100644 --- a/state.h +++ b/state.h @@ -5,7 +5,7 @@ class State { public: virtual void input(SDLKey key) = 0; - virtual void tick() = 0; + virtual void tick() {}; virtual void render(SDL_Surface* screen) = 0; }; diff --git a/title.bmp b/title.bmp new file mode 100644 index 0000000..d816447 Binary files /dev/null and b/title.bmp differ diff --git a/titlestate.cpp b/titlestate.cpp new file mode 100644 index 0000000..ee6a2b5 --- /dev/null +++ b/titlestate.cpp @@ -0,0 +1,47 @@ +#include "includes.h" + +TitleState::TitleState() +{ + background = SDL_LoadBMP("title.bmp"); + pointer = SDL_LoadBMP("pointer.bmp"); + selection = 0; +} + +void TitleState::input(SDLKey key) +{ + if ((key == SDLK_UP) && (selection != 0)) + { + selection--; + } else if ((key == SDLK_DOWN) && (selection != 3)) + { + selection++; + } else if (key == SDLK_RETURN) + { + switch (selection) + { + case 0: + changeState(new GameState()); + + break; + case 1: // Add How To Play + break; + case 2: // Add choose highscore list + break; + case 3: + exit(0); + } + } +} + +void TitleState::render(SDL_Surface* screen) +{ + SDL_BlitSurface(background, NULL, screen, NULL); + + SDL_Rect pSpace; + pSpace.x = 136; + pSpace.y = (selection==0?316:(selection==1?350:(selection==2?381:417))); + pSpace.w = screen->w; + pSpace.h = screen->h; + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); +} diff --git a/titlestate.h b/titlestate.h new file mode 100644 index 0000000..9056626 --- /dev/null +++ b/titlestate.h @@ -0,0 +1,16 @@ +#ifndef TITLESTATE_H +#define TITLESTATE_H + +class TitleState : public State { + public: + TitleState(); + void input(SDLKey key); + void render(SDL_Surface* screen); + + private: + SDL_Surface* background; + SDL_Surface* pointer; + int selection; +}; + +#endif -- cgit 1.4.1