diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-06-19 22:46:29 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-06-19 22:46:29 -0400 |
commit | 150a240098c3b45799ff04411715866b9dc58f4f (patch) | |
tree | a2ce9296ec53f0bdcce7eaeddc3a6292edf5bcf7 | |
parent | 1941186fa99ce9a9e333d9ab0deb928937e1ea61 (diff) | |
download | mazeoflife-150a240098c3b45799ff04411715866b9dc58f4f.tar.gz mazeoflife-150a240098c3b45799ff04411715866b9dc58f4f.tar.bz2 mazeoflife-150a240098c3b45799ff04411715866b9dc58f4f.zip |
Fixed solver wrapping issue
Previously, the generated mazes didn't wrap and it would be very difficult to wrap. This has been fixed. Plus, titles have been added to all states and the "gameSleep" variable has been removed due to it's not-usefulness.
-rw-r--r-- | gamestate.cpp | 36 | ||||
-rw-r--r-- | htpstate.cpp | 2 | ||||
-rw-r--r-- | mazeoflife.cpp | 8 | ||||
-rw-r--r-- | titlestate.cpp | 2 |
4 files changed, 21 insertions, 27 deletions
diff --git a/gamestate.cpp b/gamestate.cpp index 39d589d..c312bfe 100644 --- a/gamestate.cpp +++ b/gamestate.cpp | |||
@@ -39,15 +39,7 @@ void GameState::input(SDLKey key) | |||
39 | 39 | ||
40 | break; | 40 | break; |
41 | case SDLK_ESCAPE: | 41 | case SDLK_ESCAPE: |
42 | newGame = false; | 42 | changeState(new TitleState()); |
43 | |||
44 | info.playerx = 1; | ||
45 | info.playery = 1; | ||
46 | info.level = Level(); | ||
47 | info.doneMaking = false; | ||
48 | board = Board(&info); | ||
49 | |||
50 | SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); | ||
51 | 43 | ||
52 | break; | 44 | break; |
53 | } | 45 | } |
@@ -241,14 +233,14 @@ void GameState::Board::tick() | |||
241 | 233 | ||
242 | int neighbors = 0; | 234 | int neighbors = 0; |
243 | 235 | ||
244 | if ((x>0)&&(y>0)) incrementIfNeighbor(x-1,y-1,temp,&neighbors); | 236 | incrementIfNeighbor(x-1,y-1,temp,&neighbors); |
245 | if ((x>0)) incrementIfNeighbor(x-1,y,temp,&neighbors); | 237 | incrementIfNeighbor(x-1,y,temp,&neighbors); |
246 | if ((x>0)&&(y<HEIGHT-1)) incrementIfNeighbor(x-1,y+1,temp,&neighbors); | 238 | incrementIfNeighbor(x-1,y+1,temp,&neighbors); |
247 | if ((y>0)) incrementIfNeighbor(x,y-1,temp,&neighbors); | 239 | incrementIfNeighbor(x,y-1,temp,&neighbors); |
248 | if ((y<HEIGHT-1)) incrementIfNeighbor(x,y+1,temp,&neighbors); | 240 | incrementIfNeighbor(x,y+1,temp,&neighbors); |
249 | if ((x<WIDTH-1)&&(y>0)) incrementIfNeighbor(x+1,y-1,temp,&neighbors); | 241 | incrementIfNeighbor(x+1,y-1,temp,&neighbors); |
250 | if ((x<WIDTH-1)) incrementIfNeighbor(x+1,y,temp,&neighbors); | 242 | incrementIfNeighbor(x+1,y,temp,&neighbors); |
251 | if ((x<WIDTH-1)&&(y<HEIGHT-1)) incrementIfNeighbor(x+1,y+1,temp,&neighbors); | 243 | incrementIfNeighbor(x+1,y+1,temp,&neighbors); |
252 | 244 | ||
253 | if (temp[x][y]) | 245 | if (temp[x][y]) |
254 | { | 246 | { |
@@ -264,10 +256,16 @@ void GameState::Board::tick() | |||
264 | 256 | ||
265 | void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) | 257 | void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) |
266 | { | 258 | { |
259 | int nx = x; | ||
260 | int ny = y; | ||
261 | |||
267 | wrap(&x, &y); | 262 | wrap(&x, &y); |
268 | 263 | ||
269 | if ((temp[x][y])||((info->playerx==x)&&(info->playery==y))||((x==15)&&(y==15))) | 264 | if (!((nx!=x)&&(ny!=y))) |
270 | { | 265 | { |
271 | ++*tick; | 266 | if ((temp[x][y])||((info->playerx==x)&&(info->playery==y))||((x==15)&&(y==15))) |
267 | { | ||
268 | ++*tick; | ||
269 | } | ||
272 | } | 270 | } |
273 | } | 271 | } |
diff --git a/htpstate.cpp b/htpstate.cpp index 273392e..ad830da 100644 --- a/htpstate.cpp +++ b/htpstate.cpp | |||
@@ -7,6 +7,8 @@ HowToPlayState::HowToPlayState() | |||
7 | pointer = SDL_LoadBMP("pointer.bmp"); | 7 | pointer = SDL_LoadBMP("pointer.bmp"); |
8 | secondPage = false; | 8 | secondPage = false; |
9 | selection = 0; | 9 | selection = 0; |
10 | |||
11 | SDL_WM_SetCaption("Maze Of Life - How To Play", NULL); | ||
10 | } | 12 | } |
11 | 13 | ||
12 | void HowToPlayState::input(SDLKey key) | 14 | void HowToPlayState::input(SDLKey key) |
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index e962f2e..4ec9250 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp | |||
@@ -1,7 +1,6 @@ | |||
1 | #include "includes.h" | 1 | #include "includes.h" |
2 | 2 | ||
3 | SDL_Surface *screen; | 3 | SDL_Surface *screen; |
4 | bool gameSleep = false; | ||
5 | State* state; | 4 | State* state; |
6 | 5 | ||
7 | int main(int argc, char *argv[]) | 6 | int main(int argc, char *argv[]) |
@@ -42,13 +41,6 @@ int main(int argc, char *argv[]) | |||
42 | { | 41 | { |
43 | switch (anEvent.type) | 42 | switch (anEvent.type) |
44 | { | 43 | { |
45 | case SDL_ACTIVEEVENT: | ||
46 | if (anEvent.active.state == SDL_APPINPUTFOCUS) | ||
47 | { | ||
48 | gameSleep = !anEvent.active.gain; | ||
49 | } | ||
50 | |||
51 | break; | ||
52 | case SDL_QUIT: | 44 | case SDL_QUIT: |
53 | exit(0); | 45 | exit(0); |
54 | 46 | ||
diff --git a/titlestate.cpp b/titlestate.cpp index 144148a..425e4ca 100644 --- a/titlestate.cpp +++ b/titlestate.cpp | |||
@@ -5,6 +5,8 @@ TitleState::TitleState() | |||
5 | background = SDL_LoadBMP("title.bmp"); | 5 | background = SDL_LoadBMP("title.bmp"); |
6 | pointer = SDL_LoadBMP("pointer.bmp"); | 6 | pointer = SDL_LoadBMP("pointer.bmp"); |
7 | selection = 0; | 7 | selection = 0; |
8 | |||
9 | SDL_WM_SetCaption("Maze Of Life", NULL); | ||
8 | } | 10 | } |
9 | 11 | ||
10 | void TitleState::input(SDLKey key) | 12 | void TitleState::input(SDLKey key) |