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 /gamestate.cpp | |
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.
Diffstat (limited to 'gamestate.cpp')
-rw-r--r-- | gamestate.cpp | 36 |
1 files changed, 17 insertions, 19 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 | } |