summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--chlstate.cpp12
-rw-r--r--chlstate.h2
-rw-r--r--gamestate.cpp47
-rw-r--r--gamestate.h2
-rw-r--r--highscore.cpp27
-rw-r--r--highscore.h18
-rw-r--r--hslist.cpp85
-rw-r--r--hslist.h21
-rw-r--r--hslocal.cpp84
-rw-r--r--hslocal.h18
-rw-r--r--hsnew.cpp219
-rw-r--r--hsnew.h35
-rw-r--r--htpstate.cpp8
-rw-r--r--htpstate.h2
-rw-r--r--includes.h7
-rw-r--r--mazeoflife.cpp37
-rw-r--r--mazeoflife.h2
-rw-r--r--resources.h4
-rw-r--r--resources/hlo_paartm.bmpbin0 -> 76938 bytes
-rw-r--r--resources/hlo_passartm.bmpbin0 -> 76938 bytes
-rw-r--r--resources/hlo_rtm.bmpbin0 -> 76938 bytes
-rw-r--r--resources/mono.ttfbin0 -> 259628 bytes
-rw-r--r--state.h2
-rw-r--r--titlestate.cpp8
-rw-r--r--titlestate.h2
26 files changed, 621 insertions, 25 deletions
diff --git a/Makefile b/Makefile index 9bad9b2..b4a9b9b 100644 --- a/Makefile +++ b/Makefile
@@ -12,9 +12,9 @@ WINSRC = $(addsuffix win,$(SOURCES))
12RES = $(wildcard resources/*) 12RES = $(wildcard resources/*)
13CRES = $(patsubst resources/%,build/%,$(addsuffix .o,$(RES))) 13CRES = $(patsubst resources/%,build/%,$(addsuffix .o,$(RES)))
14LINCCFL = `sdl-config --cflags` 14LINCCFL = `sdl-config --cflags`
15LINLDFL = `sdl-config --libs` 15LINLDFL = `sdl-config --libs` -lSDL_ttf
16WINCCFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --cflags` -DWINDOWS 16WINCCFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --cflags` -DWINDOWS
17WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` 17WINLDFL = `/opt/SDL-1.2.9/bin/i386-mingw32msvc-sdl-config --libs` -lSDL_ttf
18 18
19all: init $(LTARGET) $(WTARGET) 19all: init $(LTARGET) $(WTARGET)
20linux: init $(LTARGET) 20linux: init $(LTARGET)
diff --git a/chlstate.cpp b/chlstate.cpp index 24dd674..3f3000d 100644 --- a/chlstate.cpp +++ b/chlstate.cpp
@@ -10,19 +10,21 @@ ChooseHighscoreListState::ChooseHighscoreListState()
10 SDL_WM_SetCaption("Maze Of Life - Choose Highscore List", NULL); 10 SDL_WM_SetCaption("Maze Of Life - Choose Highscore List", NULL);
11} 11}
12 12
13void ChooseHighscoreListState::input(SDLKey key) 13void ChooseHighscoreListState::input(SDL_keysym key)
14{ 14{
15 if ((key == SDLK_UP) && (selection != 0)) 15 if ((key.sym == SDLK_UP) && (selection != 0))
16 { 16 {
17 selection--; 17 selection--;
18 } else if ((key == SDLK_DOWN) && (selection != 2)) 18 } else if ((key.sym == SDLK_DOWN) && (selection != 2))
19 { 19 {
20 selection++; 20 selection++;
21 } else if (key == SDLK_RETURN) 21 } else if (key.sym == SDLK_RETURN)
22 { 22 {
23 switch (selection) 23 switch (selection)
24 { 24 {
25 case 0: // Go to local highscore list 25 case 0:
26 changeState(new LocalHighscoreListState(false));
27
26 break; 28 break;
27 case 1: // Go to global highscore list 29 case 1: // Go to global highscore list
28 break; 30 break;
diff --git a/chlstate.h b/chlstate.h index a8905e2..15f1d05 100644 --- a/chlstate.h +++ b/chlstate.h
@@ -4,7 +4,7 @@
4class ChooseHighscoreListState : public State { 4class ChooseHighscoreListState : public State {
5 public: 5 public:
6 ChooseHighscoreListState(); 6 ChooseHighscoreListState();
7 void input(SDLKey key); 7 void input(SDL_keysym key);
8 void render(SDL_Surface* screen); 8 void render(SDL_Surface* screen);
9 9
10 private: 10 private:
diff --git a/gamestate.cpp b/gamestate.cpp index c312bfe..9a50b32 100644 --- a/gamestate.cpp +++ b/gamestate.cpp
@@ -16,11 +16,11 @@ GameState::GameState()
16 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); 16 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
17} 17}
18 18
19void GameState::input(SDLKey key) 19void GameState::input(SDL_keysym key)
20{ 20{
21 if (info.doneMaking) 21 if (info.doneMaking)
22 { 22 {
23 switch (key) 23 switch (key.sym)
24 { 24 {
25 case SDLK_LEFT: 25 case SDLK_LEFT:
26 move(info.playerx-1, info.playery); 26 move(info.playerx-1, info.playery);
@@ -39,7 +39,48 @@ void GameState::input(SDLKey key)
39 39
40 break; 40 break;
41 case SDLK_ESCAPE: 41 case SDLK_ESCAPE:
42 changeState(new TitleState()); 42 std::ifstream exists(getDataFile());
43 if (exists)
44 {
45 FILE* hslist = fopen(getDataFile(), "r");
46 int scores;
47 Highscore* h;
48
49 fscanf(hslist, "%d%*c", &scores);
50
51 if (scores < 10)
52 {
53 fclose(hslist);
54
55 changeState(new NewHighscoreState(info.level.getLevel()));
56 } else {
57 for (int i=0; i<scores; i++)
58 {
59 int namelen;
60 char namelens[4];
61 char* name = (char*) calloc(25, sizeof(char));
62 int score;
63
64 fscanf(hslist, "%d", &namelen);
65 sprintf(namelens, "%%%dc", namelen);
66 fscanf(hslist, namelens, name);
67 fscanf(hslist, "%d%*c", &score);
68
69 h = new Highscore(name, score);
70 }
71
72 fclose(hslist);
73
74 if (h->getLevel() < info.level.getLevel())
75 {
76 changeState(new NewHighscoreState(info.level.getLevel()));
77 } else {
78 changeState(new LocalHighscoreListState(true));
79 }
80 }
81 } else {
82 changeState(new NewHighscoreState(info.level.getLevel()));
83 }
43 84
44 break; 85 break;
45 } 86 }
diff --git a/gamestate.h b/gamestate.h index 7d9d798..d1b90ad 100644 --- a/gamestate.h +++ b/gamestate.h
@@ -4,7 +4,7 @@
4class GameState : public State { 4class GameState : public State {
5 public: 5 public:
6 GameState(); 6 GameState();
7 void input(SDLKey key); 7 void input(SDL_keysym key);
8 void tick(); 8 void tick();
9 void render(SDL_Surface* screen); 9 void render(SDL_Surface* screen);
10 10
diff --git a/highscore.cpp b/highscore.cpp new file mode 100644 index 0000000..6811fa8 --- /dev/null +++ b/highscore.cpp
@@ -0,0 +1,27 @@
1#include "includes.h"
2
3Highscore::Highscore(char* name, int level)
4{
5 this->name = name;
6 this->level = level;
7}
8
9char* Highscore::getName()
10{
11 return name;
12}
13
14int Highscore::getLevel()
15{
16 return level;
17}
18
19void Highscore::setRank(int rank)
20{
21 this->rank = rank;
22}
23
24int Highscore::getRank()
25{
26 return rank;
27}
diff --git a/highscore.h b/highscore.h new file mode 100644 index 0000000..721b226 --- /dev/null +++ b/highscore.h
@@ -0,0 +1,18 @@
1#ifndef HIGHSCORE_H
2#define HIGHSCORE_H
3
4class Highscore {
5 public:
6 Highscore(char* name, int level);
7 char* getName();
8 int getLevel();
9 void setRank(int rank);
10 int getRank();
11
12 private:
13 char* name;
14 int level;
15 int rank;
16};
17
18#endif
diff --git a/hslist.cpp b/hslist.cpp new file mode 100644 index 0000000..d2901b4 --- /dev/null +++ b/hslist.cpp
@@ -0,0 +1,85 @@
1#include "includes.h"
2
3SDL_Surface* HighscoreList::render()
4{
5 SDL_Surface* tmp = SDL_CreateRGBSurface(SDL_SWSURFACE || SDL_SRCCOLORKEY, 480, 480, 32, 0,0,0,0);
6 Uint32 bgColor = SDL_MapRGB(tmp->format, 255, 255, 255);
7 SDL_FillRect(tmp, NULL, bgColor);
8 SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, bgColor);
9 TTF_Font* posFont = loadFont(40);
10 TTF_Font* dataFont = loadFont(25);
11 SDL_Color fontColor = {0, 0, 0, 0};
12
13 for (int i=0; i<hslist.size(); i++)
14 {
15 Highscore h = hslist[i];
16
17 int posw, posh;
18 char pos[3]; // 2 max characters in rank plus the colon at the end
19 sprintf(pos, "%d:", h.getRank());
20 TTF_SizeText(posFont, pos, &posw, &posh);
21 SDL_Rect posSpace = {0, (i+1)*40, posw, posh};
22 SDL_BlitSurface(TTF_RenderText_Blended(posFont, pos, fontColor), NULL, tmp, &posSpace);
23
24 int namew, nameh;
25 char name[26]; // 25 max characters in username plus the space at the beginning
26 sprintf(name, " %s", h.getName());
27 TTF_SizeText(dataFont, name, &namew, &nameh);
28 SDL_Rect nameSpace = {posw, (i+1)*40+((posh/2)-(nameh/2)), namew, nameh};
29 SDL_BlitSurface(TTF_RenderText_Blended(dataFont, name, fontColor), NULL, tmp, &nameSpace);
30
31 int lvlw, lvlh;
32 char lvl[10]; // 10 max characters in level (based off the fact that 2^32-1 is 10 characters long, and is the highest int)
33 sprintf(lvl, "%d", h.getLevel());
34 TTF_SizeText(dataFont, lvl, &lvlw, &lvlh);
35 SDL_Rect lvlSpace = {480-lvlw, (i+1)*40+((posh/2)-(nameh/2)), lvlw, lvlh};
36 SDL_BlitSurface(TTF_RenderText_Blended(dataFont, lvl, fontColor), NULL, tmp, &lvlSpace);
37 }
38
39 return tmp;
40}
41
42std::vector<Highscore> HighscoreList::getLocalHighscores()
43{
44 std::vector<Highscore> temp = std::vector<Highscore>();
45
46 std::ifstream exists(getDataFile());
47 if (exists)
48 {
49 FILE* hslist = fopen(getDataFile(), "r");
50 int scores;
51 fscanf(hslist, "%d%*c", &scores);
52
53 for (int i=0; i<scores; i++)
54 {
55 int namelen;
56 char namelens[4];
57 char* name = (char*) calloc(25, sizeof(char));
58 int score;
59
60 fscanf(hslist, "%d", &namelen);
61 sprintf(namelens, "%%%dc", namelen);
62 fscanf(hslist, namelens, name);
63 fscanf(hslist, "%d%*c", &score);
64
65 Highscore h = Highscore(name, score);
66 h.setRank(i+1);
67
68 temp.push_back(h);
69 }
70
71 fclose(hslist);
72 }
73
74 return temp;
75}
76
77std::vector<Highscore> HighscoreList::getGlobalHighscores()
78{
79
80}
81
82LocalHighscoreList::LocalHighscoreList()
83{
84 this->hslist = getLocalHighscores();
85}
diff --git a/hslist.h b/hslist.h new file mode 100644 index 0000000..88c47c4 --- /dev/null +++ b/hslist.h
@@ -0,0 +1,21 @@
1#ifndef HSLIST_H
2#define HSLIST_H
3
4class HighscoreList
5{
6 public:
7 SDL_Surface* render();
8
9 protected:
10 std::vector<Highscore> getLocalHighscores();
11 std::vector<Highscore> getGlobalHighscores();
12
13 std::vector<Highscore> hslist;
14};
15
16class LocalHighscoreList : public HighscoreList {
17 public:
18 LocalHighscoreList();
19};
20
21#endif
diff --git a/hslocal.cpp b/hslocal.cpp new file mode 100644 index 0000000..17cae1b --- /dev/null +++ b/hslocal.cpp
@@ -0,0 +1,84 @@
1#include "includes.h"
2
3LocalHighscoreListState::LocalHighscoreListState(bool fromGame)
4{
5 this->fromGame = fromGame;
6
7 if (fromGame)
8 {
9 LOADIMAGE(options,hlo_paartm)
10 } else {
11 LOADIMAGE(options,hlo_rtm)
12 }
13
14 LOADIMAGE(pointer,pointer)
15
16 LocalHighscoreList* lhl = new LocalHighscoreList();
17 list = lhl->render();
18
19 SDL_Color fontColor = {0, 0, 0, 0};
20 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor);
21 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
22 SDL_BlitSurface(title, NULL, list, &tSpace);
23
24 SDL_Rect oSpace = {0, 440, options->w, options->h};
25 SDL_BlitSurface(options, NULL, list, &oSpace);
26
27 selection = 0;
28
29 SDL_WM_SetCaption("Maze Of Life - Highscore List", NULL);
30}
31
32void LocalHighscoreListState::input(SDL_keysym key)
33{
34 if (fromGame)
35 {
36 if ((key.sym == SDLK_LEFT) && (selection != 0))
37 {
38 selection--;
39 } else if ((key.sym == SDLK_RIGHT) && (selection != 1))
40 {
41 selection++;
42 } else if (key.sym == SDLK_RETURN)
43 {
44 switch (selection)
45 {
46 case 0:
47 changeState(new GameState());
48
49 break;
50 case 1:
51 changeState(new TitleState());
52
53 break;
54 }
55 }
56 } else {
57 if (key.sym == SDLK_RETURN)
58 {
59 changeState(new ChooseHighscoreListState());
60 }
61 }
62}
63
64void LocalHighscoreListState::render(SDL_Surface* screen)
65{
66 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
67
68 SDL_BlitSurface(list, NULL, screen, NULL);
69
70 SDL_Rect pSpace;
71 pSpace.w = pointer->w;
72 pSpace.h = pointer->h;
73
74 if (fromGame)
75 {
76 pSpace.x = (selection==0?52:225);
77 pSpace.y = 447;
78 } else {
79 pSpace.x = 137;
80 pSpace.y = 449;
81 }
82
83 SDL_BlitSurface(pointer, NULL, screen, &pSpace);
84}
diff --git a/hslocal.h b/hslocal.h new file mode 100644 index 0000000..8708d03 --- /dev/null +++ b/hslocal.h
@@ -0,0 +1,18 @@
1#ifndef HSLOCAL_H
2#define HSLOCAL_H
3
4class LocalHighscoreListState : public State {
5 public:
6 LocalHighscoreListState(bool fromGame);
7 void input(SDL_keysym key);
8 void render(SDL_Surface* screen);
9
10 private:
11 SDL_Surface* list;
12 SDL_Surface* options;
13 SDL_Surface* pointer;
14 int selection;
15 bool fromGame;
16};
17
18#endif
diff --git a/hsnew.cpp b/hsnew.cpp new file mode 100644 index 0000000..3bec468 --- /dev/null +++ b/hsnew.cpp
@@ -0,0 +1,219 @@
1#include "includes.h"
2
3NewHighscoreState::NewHighscoreState(int level)
4{
5 this->level = level;
6
7 LOADIMAGE(options,hlo_passartm)
8 LOADIMAGE(pointer,pointer)
9
10 lhl = new NewHighscoreList(level);
11 newpos = lhl->getNewPos();
12 list = lhl->render();
13
14 SDL_Color fontColor = {0, 0, 0, 0};
15 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor);
16 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
17 SDL_BlitSurface(title, NULL, list, &tSpace);
18
19 this->enterName = true;
20 this->lp = 0;
21 this->hsname = (char*) calloc(25, sizeof(char));
22
23 SDL_Surface* text = TTF_RenderText_Blended(loadFont(25), "Enter Your Name", fontColor);
24 SDL_Rect oSpace = {240-(text->w/2), 440, text->w, text->h};
25 SDL_BlitSurface(text, NULL, list, &oSpace);
26
27 selection = 0;
28
29 int posw, posh;
30 char pos[3]; // 2 max characters in rank plus the colon at the end
31 sprintf(pos, "%d:", newpos);
32 char name[26]; // 25 max characters in username plus the space at the beginning
33 sprintf(name, " %s", hsname);
34 newName = TTF_RenderText_Blended(loadFont(25), name, fontColor);
35 TTF_SizeText(loadFont(40), pos, &posw, &posh);
36 rntSpace.x = posw;
37 rntSpace.y = newpos*40+((posh/2)-(newName->h/2));
38 rntSpace.w = newName->w;
39 rntSpace.h = newName->h;
40
41 SDL_WM_SetCaption("Maze Of Life - New Highscore!", NULL);
42 SDL_EnableUNICODE(1);
43}
44
45void NewHighscoreState::input(SDL_keysym key)
46{
47 if (enterName)
48 {
49 if ((key.sym == SDLK_BACKSPACE) && (lp > 0))
50 {
51 hsname[--lp] = 0;
52
53 SDL_Color fontColor = {0, 0, 0, 0};
54 char name[26]; // 25 max characters in username plus the space at the beginning
55 sprintf(name, " %s", hsname);
56 newName = TTF_RenderText_Blended(loadFont(25), name, fontColor);
57 rntSpace.w = newName->w;
58 rntSpace.h = newName->h;
59 } else if ((key.sym == SDLK_RETURN) && (hsname[0] != 0))
60 {
61 SDL_EnableUNICODE(0);
62 enterName = false;
63
64 lhl->addToList(hsname);
65 LocalHighscoreList* lhl2 = new LocalHighscoreList();
66 list = lhl2->render();
67
68 SDL_Color fontColor = {0, 0, 0, 0};
69 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor);
70 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
71 SDL_BlitSurface(title, NULL, list, &tSpace);
72
73 SDL_Rect oSpace = {0, 440, options->w, options->h};
74 SDL_BlitSurface(options, NULL, list, &oSpace);
75 } else if (((key.unicode & 0xFF80) == 0) && (key.unicode >= 32 && key.unicode < 127) && (lp < 25))
76 {
77 hsname[lp++] = key.unicode & 0x7f;
78 hsname[lp] = 0;
79
80 SDL_Color fontColor = {0, 0, 0, 0};
81 char name[26]; // 25 max characters in username plus the space at the beginning
82 sprintf(name, " %s", hsname);
83 newName = TTF_RenderText_Blended(loadFont(25), name, fontColor);
84 rntSpace.w = newName->w;
85 rntSpace.h = newName->h;
86 }
87 } else {
88 if ((key.sym == SDLK_LEFT) && (selection != 0))
89 {
90 selection--;
91 } else if ((key.sym == SDLK_RIGHT) && (selection != 2))
92 {
93 selection++;
94 } else if (key.sym == SDLK_RETURN)
95 {
96 switch (selection)
97 {
98 case 0:
99 changeState(new GameState());
100
101 break;
102 case 1: // Submit score to Global highscore list
103 break;
104 case 2:
105 changeState(new TitleState());
106
107 break;
108 }
109 }
110 }
111}
112
113void NewHighscoreState::render(SDL_Surface* screen)
114{
115 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
116
117 SDL_Rect eSpace = {0, newpos*40, 480, 40};
118 SDL_FillRect(screen, &eSpace, SDL_MapRGB(screen->format, 255, 255, 0));
119
120 SDL_BlitSurface(list, NULL, screen, NULL);
121
122 if (enterName)
123 {
124 SDL_BlitSurface(newName, NULL, screen, &rntSpace);
125 } else {
126 SDL_Rect pSpace;
127 pSpace.x = (selection==0?13:(selection==1?138:284));
128 pSpace.y = 448;
129 pSpace.w = pointer->w;
130 pSpace.h = pointer->h;
131
132 SDL_BlitSurface(pointer, NULL, screen, &pSpace);
133 }
134}
135
136NewHighscoreState::NewHighscoreList::NewHighscoreList(int level)
137{
138 this->hslist = getLocalHighscores();
139
140 if (this->hslist.empty())
141 {
142 Highscore n = Highscore("", level);
143 n.setRank(1);
144
145 this->hslist.push_back(n);
146 this->newpos = n.getRank();
147 } else {
148 std::vector<Highscore>::iterator it;
149 bool found = false;
150 int lastrank;
151 int i=0;
152
153 for (it=this->hslist.begin(); it<this->hslist.end(); it++)
154 {
155 Highscore h = *it;
156 lastrank = h.getRank();
157
158 if (!found)
159 {
160 if (h.getLevel() < level)
161 {
162 Highscore n = Highscore("", level);
163 n.setRank(h.getRank());
164
165 this->hslist.insert(it, n);
166 this->newpos = n.getRank();
167
168 if (this->hslist.size() > 10)
169 {
170 this->hslist.pop_back();
171 }
172
173 found = true;
174 }
175 } else {
176 //this->hslist[i].setRank(h.getRank()+1);
177 }
178
179 i++;
180 }
181
182 if (!found)
183 {
184 Highscore n = Highscore("", level);
185 n.setRank(lastrank+1);
186
187 this->hslist.push_back(n);
188 this->newpos = n.getRank();
189 }
190 }
191}
192
193int NewHighscoreState::NewHighscoreList::getNewPos()
194{
195 return newpos;
196}
197
198void NewHighscoreState::NewHighscoreList::addToList(char* name)
199{
200 FILE* hsfile = fopen(getDataFile(), "w");
201 fprintf(hsfile, "%d ", this->hslist.size());
202
203 std::vector<Highscore>::iterator it;
204
205 for (it=this->hslist.begin(); it<this->hslist.end(); it++)
206 {
207 Highscore h = *it;
208
209 if (h.getName() == "")
210 {
211 h = Highscore(name, h.getLevel());
212 h.setRank(newpos);
213 }
214
215 fprintf(hsfile, "%d%s%d ", strlen(h.getName()), h.getName(), h.getLevel());
216 }
217
218 fclose(hsfile);
219}
diff --git a/hsnew.h b/hsnew.h new file mode 100644 index 0000000..123ac53 --- /dev/null +++ b/hsnew.h
@@ -0,0 +1,35 @@
1#ifndef HSNEW_H
2#define HSNEW_H
3
4class NewHighscoreState : public State {
5 public:
6 NewHighscoreState(int level);
7 void input(SDL_keysym key);
8 void render(SDL_Surface* screen);
9
10 private:
11 class NewHighscoreList : public HighscoreList {
12 public:
13 NewHighscoreList(int level);
14 int getNewPos();
15 void addToList(char* name);
16
17 private:
18 int newpos;
19 };
20
21 SDL_Surface* list;
22 SDL_Surface* options;
23 SDL_Surface* pointer;
24 int selection;
25 int level;
26 int newpos;
27 int lp;
28 char* hsname;
29 bool enterName;
30 SDL_Rect rntSpace;
31 SDL_Surface* newName;
32 NewHighscoreList* lhl;
33};
34
35#endif
diff --git a/htpstate.cpp b/htpstate.cpp index 711dca4..da4b6a2 100644 --- a/htpstate.cpp +++ b/htpstate.cpp
@@ -12,15 +12,15 @@ HowToPlayState::HowToPlayState()
12 SDL_WM_SetCaption("Maze Of Life - How To Play", NULL); 12 SDL_WM_SetCaption("Maze Of Life - How To Play", NULL);
13} 13}
14 14
15void HowToPlayState::input(SDLKey key) 15void HowToPlayState::input(SDL_keysym key)
16{ 16{
17 if ((key == SDLK_LEFT) && (selection != 0)) 17 if ((key.sym == SDLK_LEFT) && (selection != 0))
18 { 18 {
19 selection--; 19 selection--;
20 } else if ((key == SDLK_RIGHT) && (selection != 1)) 20 } else if ((key.sym == SDLK_RIGHT) && (selection != 1))
21 { 21 {
22 selection++; 22 selection++;
23 } else if (key == SDLK_RETURN) 23 } else if (key.sym == SDLK_RETURN)
24 { 24 {
25 switch (selection) 25 switch (selection)
26 { 26 {
diff --git a/htpstate.h b/htpstate.h index 2639d1a..79c66ba 100644 --- a/htpstate.h +++ b/htpstate.h
@@ -4,7 +4,7 @@
4class HowToPlayState : public State { 4class HowToPlayState : public State {
5 public: 5 public:
6 HowToPlayState(); 6 HowToPlayState();
7 void input(SDLKey key); 7 void input(SDL_keysym key);
8 void render(SDL_Surface* screen); 8 void render(SDL_Surface* screen);
9 9
10 private: 10 private:
diff --git a/includes.h b/includes.h index a36c456..cd5c1e9 100644 --- a/includes.h +++ b/includes.h
@@ -1,7 +1,10 @@
1#include <SDL.h> 1#include <SDL.h>
2#include <SDL_ttf.h>
2#include <stdio.h> 3#include <stdio.h>
3#include <time.h> 4#include <time.h>
4#include <string> 5#include <string>
6#include <vector>
7#include <fstream>
5#include "state.h" 8#include "state.h"
6#include "mazeoflife.h" 9#include "mazeoflife.h"
7#include "resources.h" 10#include "resources.h"
@@ -9,3 +12,7 @@
9#include "htpstate.h" 12#include "htpstate.h"
10#include "chlstate.h" 13#include "chlstate.h"
11#include "gamestate.h" 14#include "gamestate.h"
15#include "highscore.h"
16#include "hslist.h"
17#include "hslocal.h"
18#include "hsnew.h"
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index 0dbca55..c744b28 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp
@@ -7,13 +7,21 @@ int main(int argc, char *argv[])
7{ 7{
8 srand(time(NULL)); 8 srand(time(NULL));
9 9
10 if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)==-1)) { 10 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
11 {
11 printf("Could not initialize SDL: %s.\n", SDL_GetError()); 12 printf("Could not initialize SDL: %s.\n", SDL_GetError());
12 exit(-1); 13 exit(-1);
13 } 14 }
14 15
16 if (TTF_Init() == -1)
17 {
18 printf("Could not initialize SDL_ttf: %s.\n", TTF_GetError());
19 exit(-1);
20 }
21
15 /* Clean up on exit */ 22 /* Clean up on exit */
16 atexit(SDL_Quit); 23 atexit(SDL_Quit);
24 atexit(TTF_Quit);
17 25
18 SDL_WM_SetCaption("Maze Of Life", NULL); 26 SDL_WM_SetCaption("Maze Of Life", NULL);
19 27
@@ -49,7 +57,7 @@ int main(int argc, char *argv[])
49 57
50 break; 58 break;
51 case SDL_KEYDOWN: 59 case SDL_KEYDOWN:
52 state->input(anEvent.key.keysym.sym); 60 state->input(anEvent.key.keysym);
53 61
54 break; 62 break;
55 } 63 }
@@ -96,3 +104,28 @@ Uint32 tick(Uint32 interval, void *param)
96 104
97 return interval; 105 return interval;
98} 106}
107
108TTF_Font* loadFont(int size)
109{
110 SDL_RWops* mono_rw = SDL_RWFromMem(&RESNAME(mono_ttf,start), (int) &RESNAME(mono_ttf,size));
111 TTF_Font* tmpfont = TTF_OpenFontRW(mono_rw, 1, size);
112
113 if (tmpfont == NULL)
114 {
115 printf("Unable to load font: %s\n", TTF_GetError());
116 exit(1);
117 }
118
119 return tmpfont;
120}
121
122const char* getDataFile()
123{
124#ifdef WINDOWS
125 char* dir = getenv("USERPROFILE");
126#else
127 char* dir = getenv("HOME");
128#endif
129
130 return (std::string(dir) + "/.molhslist").c_str();
131}
diff --git a/mazeoflife.h b/mazeoflife.h index 1f43214..411a87b 100644 --- a/mazeoflife.h +++ b/mazeoflife.h
@@ -9,5 +9,7 @@ void wrap(int* x, int* y);
9Uint32 getColor(int r, int g, int b); 9Uint32 getColor(int r, int g, int b);
10void changeState(State* nState); 10void changeState(State* nState);
11Uint32 tick(Uint32 interval, void *param); 11Uint32 tick(Uint32 interval, void *param);
12TTF_Font* loadFont(int size);
13const char* getDataFile();
12 14
13#endif 15#endif
diff --git a/resources.h b/resources.h index fc9229a..4743950 100644 --- a/resources.h +++ b/resources.h
@@ -16,5 +16,9 @@ DEFRES(pointer_bmp)
16DEFRES(htp1_bmp) 16DEFRES(htp1_bmp)
17DEFRES(htp2_bmp) 17DEFRES(htp2_bmp)
18DEFRES(chl_bmp) 18DEFRES(chl_bmp)
19DEFRES(hlo_rtm_bmp)
20DEFRES(hlo_paartm_bmp)
21DEFRES(hlo_passartm_bmp)
22DEFRES(mono_ttf)
19 23
20#endif 24#endif
diff --git a/resources/hlo_paartm.bmp b/resources/hlo_paartm.bmp new file mode 100644 index 0000000..72a1bf2 --- /dev/null +++ b/resources/hlo_paartm.bmp
Binary files differ
diff --git a/resources/hlo_passartm.bmp b/resources/hlo_passartm.bmp new file mode 100644 index 0000000..6c57e98 --- /dev/null +++ b/resources/hlo_passartm.bmp
Binary files differ
diff --git a/resources/hlo_rtm.bmp b/resources/hlo_rtm.bmp new file mode 100644 index 0000000..c05c208 --- /dev/null +++ b/resources/hlo_rtm.bmp
Binary files differ
diff --git a/resources/mono.ttf b/resources/mono.ttf new file mode 100644 index 0000000..1feefc2 --- /dev/null +++ b/resources/mono.ttf
Binary files differ
diff --git a/state.h b/state.h index bcc7e4a..7373940 100644 --- a/state.h +++ b/state.h
@@ -4,7 +4,7 @@
4class State 4class State
5{ 5{
6 public: 6 public:
7 virtual void input(SDLKey key) {}; 7 virtual void input(SDL_keysym key) {};
8 virtual void tick() {}; 8 virtual void tick() {};
9 virtual void render(SDL_Surface* screen) {}; 9 virtual void render(SDL_Surface* screen) {};
10}; 10};
diff --git a/titlestate.cpp b/titlestate.cpp index 980e3b6..ae18c48 100644 --- a/titlestate.cpp +++ b/titlestate.cpp
@@ -10,15 +10,15 @@ TitleState::TitleState()
10 SDL_WM_SetCaption("Maze Of Life", NULL); 10 SDL_WM_SetCaption("Maze Of Life", NULL);
11} 11}
12 12
13void TitleState::input(SDLKey key) 13void TitleState::input(SDL_keysym key)
14{ 14{
15 if ((key == SDLK_UP) && (selection != 0)) 15 if ((key.sym == SDLK_UP) && (selection != 0))
16 { 16 {
17 selection--; 17 selection--;
18 } else if ((key == SDLK_DOWN) && (selection != 3)) 18 } else if ((key.sym == SDLK_DOWN) && (selection != 3))
19 { 19 {
20 selection++; 20 selection++;
21 } else if (key == SDLK_RETURN) 21 } else if (key.sym == SDLK_RETURN)
22 { 22 {
23 switch (selection) 23 switch (selection)
24 { 24 {
diff --git a/titlestate.h b/titlestate.h index 9056626..6519ecf 100644 --- a/titlestate.h +++ b/titlestate.h
@@ -4,7 +4,7 @@
4class TitleState : public State { 4class TitleState : public State {
5 public: 5 public:
6 TitleState(); 6 TitleState();
7 void input(SDLKey key); 7 void input(SDL_keysym key);
8 void render(SDL_Surface* screen); 8 void render(SDL_Surface* screen);
9 9
10 private: 10 private: