summary refs log tree commit diff stats
path: root/gamestate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gamestate.cpp')
-rw-r--r--gamestate.cpp36
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
265void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) 257void 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}