| 1 | /////////////////////////////////////////////// |
| 2 | // |
| 3 | // Snipe2d ludum dare 48h compo entry |
| 4 | // |
| 5 | // Jari Komppa aka Sol |
| 6 | // http://iki.fi/sol |
| 7 | // |
| 8 | /////////////////////////////////////////////// |
| 9 | // License |
| 10 | /////////////////////////////////////////////// |
| 11 | // |
| 12 | // This software is provided 'as-is', without any express or implied |
| 13 | // warranty. In no event will the authors be held liable for any damages |
| 14 | // arising from the use of this software. |
| 15 | // |
| 16 | // Permission is granted to anyone to use this software for any purpose, |
| 17 | // including commercial applications, and to alter it and redistribute it |
| 18 | // freely, subject to the following restrictions: |
| 19 | // |
| 20 | // 1. The origin of this software must not be misrepresented; you must not |
| 21 | // claim that you wrote the original software. If you use this software |
| 22 | // in a product, an acknowledgment in the product documentation would be |
| 23 | // appreciated but is not required. |
| 24 | // 2. Altered source versions must be plainly marked as such, and must not be |
| 25 | // misrepresented as being the original software. |
| 26 | // 3. This notice may not be removed or altered from any source distribution. |
| 27 | // |
| 28 | // (eg. same as ZLIB license) |
| 29 | // |
| 30 | /////////////////////////////////////////////// |
| 31 | // |
| 32 | // Houses are taken from a satellite picture of glasgow. |
| 33 | // |
| 34 | // The sources are a mess, as I didn't even try to do anything |
| 35 | // really organized here.. and hey, it's a 48h compo =) |
| 36 | // |
| 37 | #include "snipe2d.h" |
| 38 | |
| 39 | extern PREFS gPrefs; |
| 40 | |
| 41 | void fillrect(int x1, int y1, int x2, int y2, int color) |
| 42 | { |
| 43 | SDL_Rect r; |
| 44 | r.x = x1; |
| 45 | r.y = y1; |
| 46 | r.w = x2-x1; |
| 47 | r.h = y2-y1; |
| 48 | int sdlcolor = SDL_MapRGB(Game.Screen->format, |
| 49 | (color >> 16) & 0xff, |
| 50 | (color >> 8) & 0xff, |
| 51 | (color >> 0) & 0xff); |
| 52 | SDL_FillRect(Game.Screen, &r, sdlcolor); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | #if 0 |
| 57 | void gameoverscreen(int aReason) |
| 58 | { |
| 59 | Game.BGM.depress(); |
| 60 | process_hiscore(); |
| 61 | Game.GameState = 0; |
| 62 | SDL_ShowCursor (1); |
| 63 | fillrect(0,0,640,480,0); |
| 64 | fillrect(159,59,437,421,0x007f00); |
| 65 | fillrect(160,60,436,420,0x003f00); |
| 66 | fillrect(159,80,437,81,0x007f00); |
| 67 | print(290, 68, COLOR_GREEN, "game over"); |
| 68 | print(260 + 12, 412, COLOR_GREEN, "press ESC to quit"); |
| 69 | int row = 88 + 40; |
| 70 | bool vertical_buttons = true; |
| 71 | switch (aReason) |
| 72 | { |
| 73 | case 0: |
| 74 | printShadow(240, row, "You left your post!"); row += 8; |
| 75 | break; |
| 76 | case 1: |
| 77 | printShadow(240, row, "You shot a VIP!"); row += 8; |
| 78 | break; |
| 79 | case 2: |
| 80 | printShadow(240, row, "You let a VIP die!"); row += 8; |
| 81 | break; |
| 82 | } |
| 83 | row += 8; |
| 84 | printShadow(240, row, "The VIP protection bureau has found your "); row += 8; |
| 85 | printShadow(240, row, "actions unacceptable, and thus has decided"); row += 8; |
| 86 | printShadow(240, row, "to let you go."); row += 8; |
| 87 | row += 8; |
| 88 | print(240, row, (Game.Score<=0)?COLOR_RED:COLOR_GREEN, "Your final score was: %d", Game.Score); row += 8; |
| 89 | row += 8; |
| 90 | row += 8; |
| 91 | row += 8; |
| 92 | switch (gPrefs.difficulty) |
| 93 | { |
| 94 | case 1: |
| 95 | printShadow(240, row, "Difficulty: Easy"); |
| 96 | break; |
| 97 | case 2: |
| 98 | printShadow(240, row, "Difficulty: Medium"); |
| 99 | break; |
| 100 | case 3: |
| 101 | printShadow(240, row, "Difficulty: Hard"); |
| 102 | break; |
| 103 | } |
| 104 | row += 8; |
| 105 | printShadow(240, row, "Based on your score, your retirement will be:"); row += 8; |
| 106 | row += 8; |
| 107 | if (Game.Score < -10000) |
| 108 | printShadow(240, row, "Slow and extremely painful."); |
| 109 | else |
| 110 | if (Game.Score < 0) |
| 111 | printShadow(240, row, "Quick and painless."); |
| 112 | else |
| 113 | if (Game.Score < 25000) |
| 114 | printShadow(240, row, "Poor."); |
| 115 | else |
| 116 | if (Game.Score < 50000) |
| 117 | printShadow(240, row, "Decent."); |
| 118 | else |
| 119 | if (Game.Score < 100000) |
| 120 | printShadow(240, row, "Above average."); |
| 121 | else |
| 122 | printShadow(240, row, "Welcome to heaven, baby!"); |
| 123 | row += 8; |
| 124 | row += 8; |
| 125 | row += 8; |
| 126 | row += 8; |
| 127 | printShadow(240, row, "Stats:"); row += 8; |
| 128 | row += 8; |
| 129 | printShadow(240, row, "Threats neutralized:%4d", Game.baddy.dead); row += 8; |
| 130 | printShadow(240, row, "VIPs with safe trip:%4d", Game.vip.goal); row += 8; |
| 131 | printShadow(240, row, "Pedestrians wasted: %4d", Game.pedestrian.dead); row += 8; |
| 132 | printShadow(240, row, "Game time: %02d:%02d", ((SDL_GetTicks() - |
| 133 | Game.GameStartTick) / 60000), ((SDL_GetTicks() - Game.GameStartTick) / 1000)%60); row += 8; |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | int i = 0; |
| 139 | for (i = 0; i < 56; i++) |
| 140 | print(162, 83 + i * 6, COLOR_YELLOW, "%u%u", rand(), rand()); |
| 141 | SDL_Flip(Game.Screen); |
| 142 | int startTick = SDL_GetTicks(); |
| 143 | while (1) |
| 144 | { |
| 145 | SDL_Event event; |
| 146 | while ( SDL_PollEvent(&event) ) |
| 147 | { |
| 148 | switch (event.type) |
| 149 | { |
| 150 | case SDL_KEYUP: |
| 151 | if (event.key.keysym.sym == SDLK_ESCAPE) |
| 152 | exit(0); |
| 153 | case SDLK_F12: |
| 154 | show_hiscores(); |
| 155 | break; |
| 156 | case SDL_MOUSEBUTTONUP: |
| 157 | if (!((SDL_GetTicks() - startTick) > 500)) |
| 158 | continue; |
| 159 | if (vertical_buttons) |
| 160 | { |
| 161 | if (hovering (456, 166, 174, 24)) |
| 162 | { |
| 163 | return; |
| 164 | } |
| 165 | if (hovering (456, 328, 174, 24)) |
| 166 | { |
| 167 | std::cout<< "Exiting normally\n"; |
| 168 | exit (0); |
| 169 | } |
| 170 | if (hovering (456, 274, 174, 24)) |
| 171 | { |
| 172 | show_hiscores(); |
| 173 | vertical_buttons = false; |
| 174 | } |
| 175 | if (hovering (456, 220, 174, 24)) |
| 176 | { |
| 177 | // create prefs window here |
| 178 | } |
| 179 | } else { |
| 180 | if (hovering (29, 446, 174, 24)) |
| 181 | { |
| 182 | return; |
| 183 | } |
| 184 | if (hovering (238, 446, 174, 24)) |
| 185 | { |
| 186 | // create prefs window (again, hehe) |
| 187 | } |
| 188 | if (hovering (437, 446, 174, 24)) |
| 189 | { |
| 190 | std::cout<<"Exiting normally\n"; |
| 191 | exit (0); |
| 192 | } |
| 193 | } |
| 194 | break; |
| 195 | case SDL_QUIT: |
| 196 | exit(0); |
| 197 | } |
| 198 | if (vertical_buttons) |
| 199 | { |
| 200 | if (!hovering (456, 166, 174, 24)) |
| 201 | draw_button (gButton.startgame, 440, 160); |
| 202 | else |
| 203 | draw_button (gButton.startgameh, 440, 160); |
| 204 | if (!hovering (456, 220, 174, 24)) |
| 205 | draw_button (gButton.prefs, 440, 214); |
| 206 | else |
| 207 | draw_button (gButton.prefsh, 440, 214); |
| 208 | if (!hovering (456, 274, 174, 24)) |
| 209 | draw_button (gButton.hiscores, 440, 268); |
| 210 | else |
| 211 | draw_button (gButton.hiscoresh, 440, 268); |
| 212 | if (!hovering (456, 328, 174, 24)) |
| 213 | draw_button (gButton.quit, 440, 322); |
| 214 | else |
| 215 | draw_button (gButton.quith, 440, 322); |
| 216 | } else { |
| 217 | if (!hovering (29, 446, 174, 24)) |
| 218 | draw_button (gButton.startgame, 13, 440); |
| 219 | else |
| 220 | draw_button (gButton.startgameh, 13, 440); |
| 221 | if (!hovering (238, 446, 174, 24)) |
| 222 | draw_button (gButton.prefs, 222, 440); |
| 223 | else |
| 224 | draw_button (gButton.prefsh, 222, 440); |
| 225 | if (!hovering (437, 446, 174, 24)) |
| 226 | draw_button (gButton.quit, 431, 440); |
| 227 | else |
| 228 | draw_button (gButton.quith, 431, 440); |
| 229 | } |
| 230 | SDL_Flip (Game.Screen); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | #endif /* 0 */ |
| 235 | |
| 236 | |
| 237 | int |
| 238 | draw_gameover (SDL_Surface *screen, const SDL_Rect *r) |
| 239 | { |
| 240 | int row, i, min, sec, ticks; |
| 241 | const char *reason; |
| 242 | const char *pension; |
| 243 | int x, y, w, h; |
| 244 | int xp, xq, yp, yq; /* horizontal, vertical scaling (p/q) */ |
| 245 | |
| 246 | x = r->x; y = r->y; w = r->w; h = r->h; |
| 247 | /* map 640 * p/q => screen->w */ |
| 248 | xp = screen->w; |
| 249 | yp = screen->h; |
| 250 | xq = 640; |
| 251 | yq = 480; |
| 252 | // Game.GameOverTicks = SDL_GetTicks(); |
| 253 | process_hiscore(); |
| 254 | // Game.BGM.depress(); |
| 255 | Game.GameState = 0; |
| 256 | SDL_ShowCursor (1); |
| 257 | #define X(n) (x + n * xp / xq) |
| 258 | #define Y(n) (y + n * yp / yq) |
| 259 | oes_fillrect(screen, X(0), Y(0), X(640), Y(480), 0); |
| 260 | oes_fillrect(screen, X(159), Y(59), X(437), Y(421), 0x007f00); |
| 261 | oes_fillrect(screen, X(160), Y(60), X(436), Y(420), 0x003f00); |
| 262 | oes_fillrect(screen, X(159), Y(80), X(437), Y(81), 0x007f00); |
| 263 | print(X(290), Y(68), COLOR_GREEN, "game over"); |
| 264 | print(X(260 + 12), Y(412), COLOR_GREEN, "press ESC to quit"); |
| 265 | row = 88 + 40; |
| 266 | |
| 267 | switch (Game.GameOverReason) |
| 268 | { |
| 269 | case OESREASON_AWOL: reason = "You left your post!"; break; |
| 270 | case OESREASON_FRAG: reason = "You shot a VIP!"; break; |
| 271 | case OESREASON_NEGLIGENT: reason = "You let a VIP die!"; break; |
| 272 | default: reason = "(invalid)"; break; |
| 273 | } |
| 274 | printShadow(X(240), Y(row), reason); row += 8; |
| 275 | row += 8; |
| 276 | printShadow(X(240), Y(row), "The VIP protection bureau has found your "); row += 8; |
| 277 | printShadow(X(240), Y(row), "actions unacceptable, and thus has decided"); row += 8; |
| 278 | printShadow(X(240), Y(row), "to let you go."); row += 8; |
| 279 | row += 8; |
| 280 | print(X(240), Y(row), (Game.Score<=0)?COLOR_RED:COLOR_GREEN, "Your final score was: %d", Game.Score); row += 8; |
| 281 | row += 8; |
| 282 | row += 8; |
| 283 | row += 8; |
| 284 | switch (gPrefs.difficulty) |
| 285 | { |
| 286 | case 1: |
| 287 | printShadow(X(240), Y(row), "Difficulty: Easy"); |
| 288 | break; |
| 289 | case 2: |
| 290 | printShadow(X(240), Y(row), "Difficulty: Medium"); |
| 291 | break; |
| 292 | case 3: |
| 293 | printShadow(X(240), Y(row), "Difficulty: Hard"); |
| 294 | break; |
| 295 | } |
| 296 | row += 8; |
| 297 | printShadow(X(240), Y(row), "Based on your score, your retirement will be:"); row += 8; |
| 298 | row += 8; |
| 299 | if (0); |
| 300 | else if (Game.Score < -10000) pension = "Slow and extremely painful."; |
| 301 | else if (Game.Score < 0) pension = "Quick and painless."; |
| 302 | else if (Game.Score < 25000) pension = "Poor."; |
| 303 | else if (Game.Score < 50000) pension = "Decent."; |
| 304 | else if (Game.Score < 100000) pension = "Above average."; |
| 305 | else pension = "Welcome to heaven, baby!"; |
| 306 | printShadow(X(240), Y(row), pension); row += 8; |
| 307 | row += 8; |
| 308 | row += 8; |
| 309 | row += 8; |
| 310 | printShadow(X(240), Y(row), "Stats:"); row += 8; |
| 311 | row += 8; |
| 312 | printShadow(X(240), Y(row), "Threats neutralized:%4d", Game.baddy.dead); row += 8; |
| 313 | printShadow(X(240), Y(row), "VIPs with safe trip:%4d", Game.vip.goal); row += 8; |
| 314 | printShadow(X(240), Y(row), "Pedestrians wasted: %4d", Game.pedestrian.dead); row += 8; |
| 315 | ticks = Game.GameOverTicks - Game.GameStartTick; |
| 316 | min = ticks / 60000; |
| 317 | sec = (ticks % 1000) % 60; |
| 318 | printShadow(240, row, "Game time: %02d:%02d", min, sec); row += 8; |
| 319 | |
| 320 | for (i = 0; i < 56; i++) |
| 321 | print(X(162), Y(83 + i * 6), COLOR_YELLOW, "%u%u", rand(), rand()); |
| 322 | |
| 323 | #undef X |
| 324 | #undef Y |
| 325 | return 1; |
| 326 | } |