summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--dummystate.h12
-rw-r--r--includes.h4
-rw-r--r--mazeoflife.cpp8
-rw-r--r--mazeoflife.h1
-rw-r--r--pointer.bmpbin0 -> 2038 bytes
-rw-r--r--state.h2
-rw-r--r--title.bmpbin0 -> 921738 bytes
-rw-r--r--titlestate.cpp47
-rw-r--r--titlestate.h16
10 files changed, 88 insertions, 4 deletions
diff --git a/Makefile b/Makefile index 7e812d9..b79fe63 100644 --- a/Makefile +++ b/Makefile
@@ -1,4 +1,4 @@
1OBJS = mazeoflife.o gamestate.o 1OBJS = mazeoflife.o titlestate.o gamestate.o
2CC = g++ 2CC = g++
3CFLAGS = `pkg-config sdl --cflags` 3CFLAGS = `pkg-config sdl --cflags`
4LIBS = `pkg-config sdl --libs` 4LIBS = `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 @@
1#ifndef DUMMYSTATE_H
2#define DUMMYSTATE_H
3
4class DummyState : public State
5{
6 public:
7 DummyState() {};
8 void input(SDLKey key) {};
9 void render(SDL_Surface* screen) {};
10};
11
12#endif
diff --git a/includes.h b/includes.h index a47a307..aec00e7 100644 --- a/includes.h +++ b/includes.h
@@ -2,6 +2,8 @@
2#include <stdio.h> 2#include <stdio.h>
3#include <time.h> 3#include <time.h>
4#include <string> 4#include <string>
5#include "mazeoflife.h"
6#include "state.h" 5#include "state.h"
6#include "dummystate.h"
7#include "mazeoflife.h"
8#include "titlestate.h"
7#include "gamestate.h" 9#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 @@
2 2
3SDL_Surface *screen; 3SDL_Surface *screen;
4bool gameSleep = false; 4bool gameSleep = false;
5State* state = new DummyState();
5 6
6int main(int argc, char *argv[]) 7int main(int argc, char *argv[])
7{ 8{
@@ -30,7 +31,7 @@ int main(int argc, char *argv[])
30 31
31 SDL_EnableKeyRepeat(100, 50); 32 SDL_EnableKeyRepeat(100, 50);
32 33
33 State* state = new GameState(); 34 state = new TitleState();
34 35
35 SDL_Event anEvent; 36 SDL_Event anEvent;
36 for (;;) 37 for (;;)
@@ -88,3 +89,8 @@ Uint32 getColor(int r, int g, int b)
88{ 89{
89 return SDL_MapRGB(screen->format, r, g, b); 90 return SDL_MapRGB(screen->format, r, g, b);
90} 91}
92
93void changeState(State* nState)
94{
95 state = nState;
96}
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;
6 6
7void wrap(int* x, int* y); 7void wrap(int* x, int* y);
8Uint32 getColor(int r, int g, int b); 8Uint32 getColor(int r, int g, int b);
9void changeState(State* nState);
9 10
10#endif 11#endif
diff --git a/pointer.bmp b/pointer.bmp new file mode 100644 index 0000000..e1cee4e --- /dev/null +++ b/pointer.bmp
Binary files 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
5{ 5{
6 public: 6 public:
7 virtual void input(SDLKey key) = 0; 7 virtual void input(SDLKey key) = 0;
8 virtual void tick() = 0; 8 virtual void tick() {};
9 virtual void render(SDL_Surface* screen) = 0; 9 virtual void render(SDL_Surface* screen) = 0;
10}; 10};
11 11
diff --git a/title.bmp b/title.bmp new file mode 100644 index 0000000..d816447 --- /dev/null +++ b/title.bmp
Binary files 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 @@
1#include "includes.h"
2
3TitleState::TitleState()
4{
5 background = SDL_LoadBMP("title.bmp");
6 pointer = SDL_LoadBMP("pointer.bmp");
7 selection = 0;
8}
9
10void TitleState::input(SDLKey key)
11{
12 if ((key == SDLK_UP) && (selection != 0))
13 {
14 selection--;
15 } else if ((key == SDLK_DOWN) && (selection != 3))
16 {
17 selection++;
18 } else if (key == SDLK_RETURN)
19 {
20 switch (selection)
21 {
22 case 0:
23 changeState(new GameState());
24
25 break;
26 case 1: // Add How To Play
27 break;
28 case 2: // Add choose highscore list
29 break;
30 case 3:
31 exit(0);
32 }
33 }
34}
35
36void TitleState::render(SDL_Surface* screen)
37{
38 SDL_BlitSurface(background, NULL, screen, NULL);
39
40 SDL_Rect pSpace;
41 pSpace.x = 136;
42 pSpace.y = (selection==0?316:(selection==1?350:(selection==2?381:417)));
43 pSpace.w = screen->w;
44 pSpace.h = screen->h;
45
46 SDL_BlitSurface(pointer, NULL, screen, &pSpace);
47}
diff --git a/titlestate.h b/titlestate.h new file mode 100644 index 0000000..9056626 --- /dev/null +++ b/titlestate.h
@@ -0,0 +1,16 @@
1#ifndef TITLESTATE_H
2#define TITLESTATE_H
3
4class TitleState : public State {
5 public:
6 TitleState();
7 void input(SDLKey key);
8 void render(SDL_Surface* screen);
9
10 private:
11 SDL_Surface* background;
12 SDL_Surface* pointer;
13 int selection;
14};
15
16#endif