diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-11-08 13:42:14 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2009-11-08 13:42:14 -0500 |
commit | ba90715d26e84fd176a0d44bd8e5dde826067d93 (patch) | |
tree | a5f0ca481895197f1d0e5db341e7263e3fcc0529 /gamestate.cpp | |
parent | c027f1b9cd6c9deb60931a7f9f75bb4ee130291b (diff) | |
download | mazeoflife-ba90715d26e84fd176a0d44bd8e5dde826067d93.tar.gz mazeoflife-ba90715d26e84fd176a0d44bd8e5dde826067d93.tar.bz2 mazeoflife-ba90715d26e84fd176a0d44bd8e5dde826067d93.zip |
Added global highscore list
You can now view and submit highscores to the global highscore list. If the connection fails, you are allowed to retry sending it so your score is not lost. The actual global highscore list is a PHP file and MySQL database that will need to be uploaded to Four Island Other for this to work. Some other things were done. Because it was discovered that the frequent window caption changes were making Maze Of Life crash, they were removed and the player is now notified of their score by the level number appearing in 100 point font at the beginning of each level during the doneWorking stage. Also, a cheat was added that allows you to play the game in fullscreen if you press F4 on a supporting platform. The player is now also slightly faster. Closes #104
Diffstat (limited to 'gamestate.cpp')
-rw-r--r-- | gamestate.cpp | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/gamestate.cpp b/gamestate.cpp index 9a50b32..95d1769 100644 --- a/gamestate.cpp +++ b/gamestate.cpp | |||
@@ -7,35 +7,34 @@ GameState::GameState() | |||
7 | 7 | ||
8 | newGame = false; | 8 | newGame = false; |
9 | 9 | ||
10 | info.playerx = 1; | 10 | info = new Info(); |
11 | info.playery = 1; | 11 | info->playerx = 1; |
12 | info.level = Level(); | 12 | info->playery = 1; |
13 | info.doneMaking = false; | 13 | info->level = Level(); |
14 | board = Board(&info); | 14 | info->doneMaking = false; |
15 | 15 | board = Board(info); | |
16 | SDL_WM_SetCaption("Maze Of Life - Level 1", NULL); | ||
17 | } | 16 | } |
18 | 17 | ||
19 | void GameState::input(SDL_keysym key) | 18 | void GameState::input(SDL_keysym key) |
20 | { | 19 | { |
21 | if (info.doneMaking) | 20 | if (info->doneMaking) |
22 | { | 21 | { |
23 | switch (key.sym) | 22 | switch (key.sym) |
24 | { | 23 | { |
25 | case SDLK_LEFT: | 24 | case SDLK_LEFT: |
26 | move(info.playerx-1, info.playery); | 25 | move(info->playerx-1, info->playery); |
27 | 26 | ||
28 | break; | 27 | break; |
29 | case SDLK_RIGHT: | 28 | case SDLK_RIGHT: |
30 | move(info.playerx+1, info.playery); | 29 | move(info->playerx+1, info->playery); |
31 | 30 | ||
32 | break; | 31 | break; |
33 | case SDLK_UP: | 32 | case SDLK_UP: |
34 | move(info.playerx, info.playery-1); | 33 | move(info->playerx, info->playery-1); |
35 | 34 | ||
36 | break; | 35 | break; |
37 | case SDLK_DOWN: | 36 | case SDLK_DOWN: |
38 | move(info.playerx, info.playery+1); | 37 | move(info->playerx, info->playery+1); |
39 | 38 | ||
40 | break; | 39 | break; |
41 | case SDLK_ESCAPE: | 40 | case SDLK_ESCAPE: |
@@ -52,7 +51,7 @@ void GameState::input(SDL_keysym key) | |||
52 | { | 51 | { |
53 | fclose(hslist); | 52 | fclose(hslist); |
54 | 53 | ||
55 | changeState(new NewHighscoreState(info.level.getLevel())); | 54 | changeState(new NewHighscoreState(info->level.getLevel())); |
56 | } else { | 55 | } else { |
57 | for (int i=0; i<scores; i++) | 56 | for (int i=0; i<scores; i++) |
58 | { | 57 | { |
@@ -71,15 +70,15 @@ void GameState::input(SDL_keysym key) | |||
71 | 70 | ||
72 | fclose(hslist); | 71 | fclose(hslist); |
73 | 72 | ||
74 | if (h->getLevel() < info.level.getLevel()) | 73 | if (h->getLevel() < info->level.getLevel()) |
75 | { | 74 | { |
76 | changeState(new NewHighscoreState(info.level.getLevel())); | 75 | changeState(new NewHighscoreState(info->level.getLevel())); |
77 | } else { | 76 | } else { |
78 | changeState(new LocalHighscoreListState(true)); | 77 | changeState(new LocalHighscoreListState(true)); |
79 | } | 78 | } |
80 | } | 79 | } |
81 | } else { | 80 | } else { |
82 | changeState(new NewHighscoreState(info.level.getLevel())); | 81 | changeState(new NewHighscoreState(info->level.getLevel())); |
83 | } | 82 | } |
84 | 83 | ||
85 | break; | 84 | break; |
@@ -93,20 +92,17 @@ void GameState::tick() | |||
93 | { | 92 | { |
94 | switch (rand()%4) | 93 | switch (rand()%4) |
95 | { | 94 | { |
96 | case 0: info.playerx = 1; info.playery = 1; break; | 95 | case 0: info->playerx = 1; info->playery = 1; break; |
97 | case 1: info.playerx = 1; info.playery = HEIGHT-2; break; | 96 | case 1: info->playerx = 1; info->playery = HEIGHT-2; break; |
98 | case 2: info.playerx = WIDTH-2; info.playery = HEIGHT-2; break; | 97 | case 2: info->playerx = WIDTH-2; info->playery = HEIGHT-2; break; |
99 | case 3: info.playerx = WIDTH-2; info.playery = 1; break; | 98 | case 3: info->playerx = WIDTH-2; info->playery = 1; break; |
100 | } | 99 | } |
101 | 100 | ||
102 | info.level.incrementLevel(); | 101 | info->level.incrementLevel(); |
103 | info.doneMaking = false; | 102 | info->doneMaking = false; |
104 | board = Board(&info); | 103 | info->gens = 0; |
104 | board = Board(info); | ||
105 | newGame = false; | 105 | newGame = false; |
106 | |||
107 | char title[32]; | ||
108 | sprintf(title, "Maze Of Life - Level %d", info.level.getLevel()); | ||
109 | SDL_WM_SetCaption(title, NULL); | ||
110 | } | 106 | } |
111 | 107 | ||
112 | board.tick(); | 108 | board.tick(); |
@@ -119,8 +115,8 @@ void GameState::move(int x, int y) | |||
119 | if (board.isObstructed(x,y)) return; | 115 | if (board.isObstructed(x,y)) return; |
120 | if ((x==15)&&(y==15)) newGame = true; | 116 | if ((x==15)&&(y==15)) newGame = true; |
121 | 117 | ||
122 | info.playerx = x; | 118 | info->playerx = x; |
123 | info.playery = y; | 119 | info->playery = y; |
124 | } | 120 | } |
125 | 121 | ||
126 | void GameState::render(SDL_Surface* screen) | 122 | void GameState::render(SDL_Surface* screen) |
@@ -128,20 +124,31 @@ void GameState::render(SDL_Surface* screen) | |||
128 | // Paint maze | 124 | // Paint maze |
129 | board.render(screen); | 125 | board.render(screen); |
130 | 126 | ||
131 | // Paint player | 127 | // Paint event |
132 | SDL_Rect block; | 128 | SDL_Rect block; |
133 | block.x = info.playerx*16; | 129 | block.x = 15*16; |
134 | block.y = info.playery*16; | 130 | block.y = 15*16; |
135 | block.w = 16; | 131 | block.w = 16; |
136 | block.h = 16; | 132 | block.h = 16; |
137 | 133 | ||
138 | SDL_FillRect(screen, &block, player_color); | 134 | SDL_FillRect(screen, &block, event_color); |
139 | 135 | ||
140 | // Paint event | 136 | if (!info->doneMaking) |
141 | block.x = 15*16; | 137 | { |
142 | block.y = 15*16; | 138 | SDL_Color fontColor = {0, 0, 0, 0}; |
139 | char levelnum[8]; | ||
140 | sprintf(levelnum, "%d", info->level.getLevel()); | ||
141 | SDL_Surface* title = TTF_RenderText_Solid(loadFont(100), levelnum, fontColor); | ||
142 | SDL_Rect tSpace = {240-(title->w/2), 240-(title->h/2), title->w, title->h}; | ||
143 | SDL_FillRect(screen, NULL, info->level.getDeadColor()); | ||
144 | SDL_BlitSurface(title, NULL, screen, &tSpace); | ||
145 | } | ||
143 | 146 | ||
144 | SDL_FillRect(screen, &block, event_color); | 147 | // Paint player |
148 | block.x = info->playerx*16; | ||
149 | block.y = info->playery*16; | ||
150 | |||
151 | SDL_FillRect(screen, &block, player_color); | ||
145 | } | 152 | } |
146 | 153 | ||
147 | GameState::Level::Level() | 154 | GameState::Level::Level() |
@@ -292,7 +299,7 @@ void GameState::Board::tick() | |||
292 | } | 299 | } |
293 | } | 300 | } |
294 | 301 | ||
295 | if (!info->doneMaking && ++gens > 100) info->doneMaking = true; | 302 | if (!info->doneMaking && ++info->gens > 50) info->doneMaking = true; |
296 | } | 303 | } |
297 | 304 | ||
298 | void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) | 305 | void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick) |