summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--gamestate.cpp50
-rw-r--r--gamestate.h2
2 files changed, 31 insertions, 21 deletions
diff --git a/gamestate.cpp b/gamestate.cpp index 40229ba..39d589d 100644 --- a/gamestate.cpp +++ b/gamestate.cpp
@@ -10,6 +10,7 @@ GameState::GameState()
10 info.playerx = 1; 10 info.playerx = 1;
11 info.playery = 1; 11 info.playery = 1;
12 info.level = Level(); 12 info.level = Level();
13 info.doneMaking = false;
13 board = Board(&info); 14 board = Board(&info);
14 15
15 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); 16 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
@@ -17,35 +18,39 @@ GameState::GameState()
17 18
18void GameState::input(SDLKey key) 19void GameState::input(SDLKey key)
19{ 20{
20 switch (key) 21 if (info.doneMaking)
21 { 22 {
22 case SDLK_LEFT: 23 switch (key)
23 move(info.playerx-1, info.playery); 24 {
25 case SDLK_LEFT:
26 move(info.playerx-1, info.playery);
24 27
25 break; 28 break;
26 case SDLK_RIGHT: 29 case SDLK_RIGHT:
27 move(info.playerx+1, info.playery); 30 move(info.playerx+1, info.playery);
28 31
29 break; 32 break;
30 case SDLK_UP: 33 case SDLK_UP:
31 move(info.playerx, info.playery-1); 34 move(info.playerx, info.playery-1);
32 35
33 break; 36 break;
34 case SDLK_DOWN: 37 case SDLK_DOWN:
35 move(info.playerx, info.playery+1); 38 move(info.playerx, info.playery+1);
36 39
37 break; 40 break;
38 case SDLK_ESCAPE: 41 case SDLK_ESCAPE:
39 newGame = false; 42 newGame = false;
40 43
41 info.playerx = 1; 44 info.playerx = 1;
42 info.playery = 1; 45 info.playery = 1;
43 info.level = Level(); 46 info.level = Level();
44 board = Board(&info); 47 info.doneMaking = false;
48 board = Board(&info);
45 49
46 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); 50 SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
47 51
48 break; 52 break;
53 }
49 } 54 }
50} 55}
51 56
@@ -62,6 +67,7 @@ void GameState::tick()
62 } 67 }
63 68
64 info.level.incrementLevel(); 69 info.level.incrementLevel();
70 info.doneMaking = false;
65 board = Board(&info); 71 board = Board(&info);
66 newGame = false; 72 newGame = false;
67 73
@@ -252,6 +258,8 @@ void GameState::Board::tick()
252 } 258 }
253 } 259 }
254 } 260 }
261
262 if (!info->doneMaking && ++gens > 100) info->doneMaking = true;
255} 263}
256 264
257void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) 265void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick)
diff --git a/gamestate.h b/gamestate.h index 5537b51..7d9d798 100644 --- a/gamestate.h +++ b/gamestate.h
@@ -28,6 +28,7 @@ class GameState : public State {
28 struct Info { 28 struct Info {
29 int playerx, playery; 29 int playerx, playery;
30 Level level; 30 Level level;
31 bool doneMaking;
31 }; 32 };
32 33
33 class Board 34 class Board
@@ -36,6 +37,7 @@ class GameState : public State {
36 bool blocks[WIDTH][HEIGHT]; 37 bool blocks[WIDTH][HEIGHT];
37 void incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick); 38 void incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick);
38 GameState::Info* info; 39 GameState::Info* info;
40 int gens;
39 41
40 public: 42 public:
41 Board(); 43 Board();