From 1941186fa99ce9a9e333d9ab0deb928937e1ea61 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 19 Jun 2009 21:22:34 -0400 Subject: Added How To Play Closes #103 --- Makefile | 2 +- htp1.bmp | Bin 0 -> 921738 bytes htp2.bmp | Bin 0 -> 921738 bytes htpstate.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ htpstate.h | 18 ++++++++++++++++++ includes.h | 1 + titlestate.cpp | 4 +++- 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 htp1.bmp create mode 100644 htp2.bmp create mode 100644 htpstate.cpp create mode 100644 htpstate.h diff --git a/Makefile b/Makefile index b79fe63..7f503ba 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -OBJS = mazeoflife.o titlestate.o gamestate.o +OBJS = mazeoflife.o titlestate.o htpstate.o gamestate.o CC = g++ CFLAGS = `pkg-config sdl --cflags` LIBS = `pkg-config sdl --libs` diff --git a/htp1.bmp b/htp1.bmp new file mode 100644 index 0000000..df06101 Binary files /dev/null and b/htp1.bmp differ diff --git a/htp2.bmp b/htp2.bmp new file mode 100644 index 0000000..5dcb4c4 Binary files /dev/null and b/htp2.bmp differ diff --git a/htpstate.cpp b/htpstate.cpp new file mode 100644 index 0000000..273392e --- /dev/null +++ b/htpstate.cpp @@ -0,0 +1,56 @@ +#include "includes.h" + +HowToPlayState::HowToPlayState() +{ + background1 = SDL_LoadBMP("htp1.bmp"); + background2 = SDL_LoadBMP("htp2.bmp"); + pointer = SDL_LoadBMP("pointer.bmp"); + secondPage = false; + selection = 0; +} + +void HowToPlayState::input(SDLKey key) +{ + if ((key == SDLK_LEFT) && (selection != 0)) + { + selection--; + } else if ((key == SDLK_RIGHT) && (selection != 1)) + { + selection++; + } else if (key == SDLK_RETURN) + { + switch (selection) + { + case 0: + secondPage = !secondPage; + + break; + case 1: + changeState(new TitleState()); + + break; + } + } +} + +void HowToPlayState::render(SDL_Surface* screen) +{ + SDL_Rect pSpace; + + if (!secondPage) + { + SDL_BlitSurface(background1, NULL, screen, NULL); + + pSpace.x = (selection==0?74:216); + } else { + SDL_BlitSurface(background2, NULL, screen, NULL); + + pSpace.x = (selection==0?45:238); + } + + pSpace.y = 430; + pSpace.w = screen->w; + pSpace.h = screen->h; + + SDL_BlitSurface(pointer, NULL, screen, &pSpace); +} diff --git a/htpstate.h b/htpstate.h new file mode 100644 index 0000000..2639d1a --- /dev/null +++ b/htpstate.h @@ -0,0 +1,18 @@ +#ifndef HTPSTATE_H +#define HTPSTATE_H + +class HowToPlayState : public State { + public: + HowToPlayState(); + void input(SDLKey key); + void render(SDL_Surface* screen); + + private: + SDL_Surface* background1; + SDL_Surface* background2; + SDL_Surface* pointer; + bool secondPage; + int selection; +}; + +#endif diff --git a/includes.h b/includes.h index d066b8e..fa6abeb 100644 --- a/includes.h +++ b/includes.h @@ -5,4 +5,5 @@ #include "state.h" #include "mazeoflife.h" #include "titlestate.h" +#include "htpstate.h" #include "gamestate.h" diff --git a/titlestate.cpp b/titlestate.cpp index ee6a2b5..144148a 100644 --- a/titlestate.cpp +++ b/titlestate.cpp @@ -23,7 +23,9 @@ void TitleState::input(SDLKey key) changeState(new GameState()); break; - case 1: // Add How To Play + case 1: + changeState(new HowToPlayState()); + break; case 2: // Add choose highscore list break; -- cgit 1.4.1