1
///////////////////////////////////////////////
3
// Snipe2d ludum dare 48h compo entry
8
///////////////////////////////////////////////
10
///////////////////////////////////////////////
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.
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:
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.
28
// (eg. same as ZLIB license)
30
///////////////////////////////////////////////
32
// Houses are taken from a satellite picture of glasgow.
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 =)
41
void fillrect(int x1, int y1, int x2, int y2, int color)
48
int sdlcolor = SDL_MapRGB(Game.Screen->format,
52
SDL_FillRect(Game.Screen, &r, sdlcolor);
57
void gameoverscreen(int aReason)
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");
70
bool vertical_buttons = true;
74
printShadow(240, row, "You left your post!"); row += 8;
77
printShadow(240, row, "You shot a VIP!"); row += 8;
80
printShadow(240, row, "You let a VIP die!"); 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;
88
print(240, row, (Game.Score<=0)?COLOR_RED:COLOR_GREEN, "Your final score was: %d", Game.Score); row += 8;
92
switch (gPrefs.difficulty)
95
printShadow(240, row, "Difficulty: Easy");
98
printShadow(240, row, "Difficulty: Medium");
101
printShadow(240, row, "Difficulty: Hard");
105
printShadow(240, row, "Based on your score, your retirement will be:"); row += 8;
107
if (Game.Score < -10000)
108
printShadow(240, row, "Slow and extremely painful.");
111
printShadow(240, row, "Quick and painless.");
113
if (Game.Score < 25000)
114
printShadow(240, row, "Poor.");
116
if (Game.Score < 50000)
117
printShadow(240, row, "Decent.");
119
if (Game.Score < 100000)
120
printShadow(240, row, "Above average.");
122
printShadow(240, row, "Welcome to heaven, baby!");
127
printShadow(240, row, "Stats:"); 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;
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();
146
while ( SDL_PollEvent(&event) )
151
if (event.key.keysym.sym == SDLK_ESCAPE)
156
case SDL_MOUSEBUTTONUP:
157
if (!((SDL_GetTicks() - startTick) > 500))
159
if (vertical_buttons)
161
if (hovering (456, 166, 174, 24))
165
if (hovering (456, 328, 174, 24))
167
std::cout<< "Exiting normally\n";
170
if (hovering (456, 274, 174, 24))
173
vertical_buttons = false;
175
if (hovering (456, 220, 174, 24))
177
// create prefs window here
180
if (hovering (29, 446, 174, 24))
184
if (hovering (238, 446, 174, 24))
186
// create prefs window (again, hehe)
188
if (hovering (437, 446, 174, 24))
190
std::cout<<"Exiting normally\n";
198
if (vertical_buttons)
200
if (!hovering (456, 166, 174, 24))
201
draw_button (gButton.startgame, 440, 160);
203
draw_button (gButton.startgameh, 440, 160);
204
if (!hovering (456, 220, 174, 24))
205
draw_button (gButton.prefs, 440, 214);
207
draw_button (gButton.prefsh, 440, 214);
208
if (!hovering (456, 274, 174, 24))
209
draw_button (gButton.hiscores, 440, 268);
211
draw_button (gButton.hiscoresh, 440, 268);
212
if (!hovering (456, 328, 174, 24))
213
draw_button (gButton.quit, 440, 322);
215
draw_button (gButton.quith, 440, 322);
217
if (!hovering (29, 446, 174, 24))
218
draw_button (gButton.startgame, 13, 440);
220
draw_button (gButton.startgameh, 13, 440);
221
if (!hovering (238, 446, 174, 24))
222
draw_button (gButton.prefs, 222, 440);
224
draw_button (gButton.prefsh, 222, 440);
225
if (!hovering (437, 446, 174, 24))
226
draw_button (gButton.quit, 431, 440);
228
draw_button (gButton.quith, 431, 440);
230
SDL_Flip (Game.Screen);
238
draw_gameover (SDL_Surface *screen, const SDL_Rect *r)
240
int row, i, min, sec, ticks;
244
int xp, xq, yp, yq; /* horizontal, vertical scaling (p/q) */
246
x = r->x; y = r->y; w = r->w; h = r->h;
247
/* map 640 * p/q => screen->w */
252
// Game.GameOverTicks = SDL_GetTicks();
254
// Game.BGM.depress();
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");
267
switch (Game.GameOverReason)
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;
274
printShadow(X(240), Y(row), reason); 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;
280
print(X(240), Y(row), (Game.Score<=0)?COLOR_RED:COLOR_GREEN, "Your final score was: %d", Game.Score); row += 8;
284
switch (gPrefs.difficulty)
287
printShadow(X(240), Y(row), "Difficulty: Easy");
290
printShadow(X(240), Y(row), "Difficulty: Medium");
293
printShadow(X(240), Y(row), "Difficulty: Hard");
297
printShadow(X(240), Y(row), "Based on your score, your retirement will be:"); row += 8;
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;
310
printShadow(X(240), Y(row), "Stats:"); 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;
317
sec = (ticks % 1000) % 60;
318
printShadow(240, row, "Game time: %02d:%02d", min, sec); row += 8;
320
for (i = 0; i < 56; i++)
321
print(X(162), Y(83 + i * 6), COLOR_YELLOW, "%u%u", rand(), rand());