2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 extern void doMusicInfo(unsigned int);
27 * Displays the skill level widgets and hide the others
29 void showSkillLevels()
31 engine.showWidgetGroup("skill", true);
32 engine.showWidgetGroup("mainMenu", false);
33 engine.showWidgetGroup("gameSlots", false);
35 engine.showWidget("back", true);
37 engine.highlightWidget("normal");
39 engine.enableWidget("extreme", engine.extremeAvailable);
43 * Displays the save game widgets and hide the others
47 engine.showWidgetGroup("gameSlots", true);
48 engine.showWidgetGroup("mainMenu", false);
50 engine.showWidget("back", true);
52 engine.highlightWidget("slot1");
57 engine.showWidgetGroup("saveGames", true);
58 engine.showWidgetGroup("mainMenu", false);
60 engine.showWidget("back", true);
62 engine.highlightWidget("save1");
66 * Displays the manual widgets and hide the others
73 engine.showWidgetGroup("help", true);
74 engine.showWidgetGroup("mainMenu", false);
76 engine.showWidget("back", true);
78 engine.highlightWidget("back");
83 * Displays the title widgets and hide the others.
84 * Also disables Continue and Load Game if games are not
85 * available to be loaded.
87 void showTitleWidgets()
89 engine.showWidgetGroup("skill", false);
90 engine.showWidgetGroup("saveGames", false);
91 engine.showWidgetGroup("gameSlots", false);
92 engine.showWidgetGroup("help", false);
93 engine.showWidget("back", false);
95 engine.showWidgetGroup("mainMenu", true);
97 engine.highlightWidget("newGame");
99 if (!engine.continueSaveSlot)
101 engine.enableWidget("loadGame", false);
102 engine.enableWidget("continue", false);
106 engine.highlightWidget("continue");
111 * Creates the data labels for the save game slots
112 * according to the save game data available
114 void setupSaveWidgets()
119 for (int i = 0 ; i < 5 ; i++)
121 snprintf(widgetName, sizeof widgetName, "save%d", i + 1);
122 strlcpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
124 if ((strstr(engine.saveSlot[i], _("Empty"))) || (strstr(engine.saveSlot[i], _("Corrupt"))))
126 engine.enableWidget(widgetName, false);
129 snprintf(widgetName, sizeof widgetName, "slot%d", i + 1);
130 strlcpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
135 * Loads the title widgets
137 void loadTitleWidgets()
139 if (!engine.loadWidgets(_("data/titleWidgets")))
141 graphics.showErrorAndExit(ERR_FILE, _("data/titleWidgets"));
148 Widget *widget = engine.getWidgetByName("labelManual");
149 strlcpy(widget->label, GAMEPLAYMANUAL, sizeof widget->label);
155 * Does the main game title sequence
156 * @return The section to proceed to (see main.cpp)
163 SDL_FillRect(graphics.screen, NULL, graphics.black);
164 graphics.delay(1000);
171 float titleAlpha = 0;
172 bool allFadedOn = false;
174 graphics.quickSprite("cheatHeader", graphics.loadImage("gfx/main/cheats.png"));
175 graphics.quickSprite("optionsHeader", graphics.loadImage("gfx/main/options.png"));
176 graphics.quickSprite("keyHeader", graphics.loadImage("gfx/main/keyConfig.png"));
177 graphics.quickSprite("joystickHeader", graphics.loadImage("gfx/main/joystickConfig.png"));
178 graphics.quickSprite("optionsBackground", graphics.loadImage("gfx/main/optionsBackground.png"));
180 SDL_Surface *prlogo = graphics.quickSprite("PRLogo", graphics.loadImage("gfx/main/prlogo.gif"));
181 SDL_Surface *title = graphics.quickSprite("Title", graphics.loadImage("gfx/main/title.png"));
183 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
185 graphics.setFontSize(3);
186 SDL_Surface *presents = graphics.quickSprite("Presents", graphics.getString(_("Presents"), true));
187 SDL_Surface *sdl = graphics.quickSprite("SDL", graphics.getString(_("An SDL Game"), true));
189 graphics.setFontSize(2);
190 SDL_Surface *subTitle = graphics.quickSprite("SubTitle", graphics.getString(_("Blob Wars : Episode I"), true));
192 graphics.setFontSize(0);
193 SDL_Surface *copyright[] = {
194 graphics.quickSprite("Copyright1", graphics.getString(_("Copyright (C) 2011-2015 Perpendicular Dimensions"), true)),
195 graphics.quickSprite("Copyright2", graphics.getString(_("Copyright (C) 2004-2011 Parallel Realities"), true)),
200 #define STRINGIFY_VALUE(x) STRINGIFY(x)
201 #define STRINGIFY(x) #x
202 snprintf(v, sizeof v, _("Version %s"), STRINGIFY_VALUE(VERSION));
203 SDL_Surface *version = graphics.quickSprite("Version", graphics.getString(v, true));
205 SDL_SetAlpha(title, 0);
207 audio.loadMusic("music/title");
209 graphics.loadBackground("gfx/main/CircuitBoard.jpg");
210 SDL_SetAlpha(graphics.background, 0);
212 int startNewGame, options, quit, help, easy, normal, hard, extreme, back, practice;
213 int load, cont, save[5], slot[6];
216 startNewGame = options = quit = easy = normal = hard = extreme = back = help = practice = 0;
217 load = cont = save[0] = save[1] = save[2] = save[3] = save[4] = 0;
218 slot[0] = slot[1] = slot[2] = slot[3] = slot[4] = slot[5] = 0;
221 engine.setWidgetVariable("newGame", &startNewGame);
222 engine.setWidgetVariable("loadGame", &load);
223 engine.setWidgetVariable("continue", &cont);
224 engine.setWidgetVariable("options", &options);
225 engine.setWidgetVariable("help", &help);
226 engine.setWidgetVariable("quit", &quit);
235 Uint32 now = SDL_GetTicks();
237 unsigned int frameLimit = SDL_GetTicks() + 16;
241 unsigned int ticks = SDL_GetTicks();
242 graphics.updateScreen();
247 for (int x = (int)offX ; x < 640 ; x += graphics.background->w)
249 for (int y = 0 ; y < 480 ; y += graphics.background->h)
251 graphics.blit(graphics.background, x, y, graphics.screen, false);
257 if ((ticks >= now + 2000) && (ticks <= now + 10000))
259 graphics.blit(prlogo, 320, 240, graphics.screen, true);
261 else if ((ticks >= now + 13000) && (ticks <= now + 19000))
263 graphics.blit(presents, 320, 240, graphics.screen, true);
265 else if ((ticks >= now + 22000) && (ticks <= now + 27000))
267 graphics.blit(sdl, 320, 240, graphics.screen, true);
270 if (engine.userAccepts())
277 SDL_SetAlpha(graphics.background, backAlpha);
278 SDL_SetAlpha(title, titleAlpha);
282 if ((ticks >= now + 4000) || (allFadedOn))
287 SDL_SetAlpha(graphics.background, backAlpha);
291 if ((ticks >= now + 29000) || (allFadedOn))
293 if (titleAlpha < 255)
296 SDL_SetAlpha(title, titleAlpha);
300 graphics.blit(subTitle, 320, 180, graphics.screen, true);
301 for (int i = 0; copyright[i]; i++)
302 graphics.blit(copyright[i], 10, 460 - i * 18, graphics.screen, false);
303 graphics.blit(version, (630 - version->w), 460, graphics.screen, false);
307 doMusicInfo(ticks - (now + 39000));
310 Math::wrapFloat(&(offX -= 0.25), -graphics.background->w, 0);
314 graphics.blit(title, 320, 100, graphics.screen, true);
320 audio.playMenuSound(engine.processWidgets());
327 engine.setWidgetVariable("newGame", &startNewGame);
328 engine.setWidgetVariable("loadGame", &load);
329 engine.setWidgetVariable("continue", &cont);
330 engine.setWidgetVariable("options", &options);
331 engine.setWidgetVariable("help", &help);
332 engine.setWidgetVariable("quit", &quit);
340 engine.setWidgetVariable("back", &back);
347 engine.setWidgetVariable("slot1", &slot[0]);
348 engine.setWidgetVariable("slot2", &slot[1]);
349 engine.setWidgetVariable("slot3", &slot[2]);
350 engine.setWidgetVariable("slot4", &slot[3]);
351 engine.setWidgetVariable("slot5", &slot[4]);
352 engine.setWidgetVariable("slot6", &slot[5]);
353 engine.setWidgetVariable("back", &back);
357 for (int i = 0 ; i < 6 ; i++)
362 engine.setWidgetVariable("practice", &practice);
363 engine.setWidgetVariable("easy", &easy);
364 engine.setWidgetVariable("normal", &normal);
365 engine.setWidgetVariable("hard", &hard);
366 engine.setWidgetVariable("extreme", &extreme);
367 engine.setWidgetVariable("back", &back);
376 engine.setWidgetVariable("save1", &save[0]);
377 engine.setWidgetVariable("save2", &save[1]);
378 engine.setWidgetVariable("save3", &save[2]);
379 engine.setWidgetVariable("save4", &save[3]);
380 engine.setWidgetVariable("save5", &save[4]);
381 engine.setWidgetVariable("back", &back);
385 if (easy) {engine.skill = 0; break;}
386 if (normal) {engine.skill = 1; break;}
387 if (hard) {engine.skill = 2; break;}
388 if (extreme) {engine.skill = 3; break;}
389 if (practice) {engine.skill = -1; break;}
391 if (cont) {load = engine.continueSaveSlot; break;}
393 if (save[0]) {load = 1; break;}
394 if (save[1]) {load = 2; break;}
395 if (save[2]) {load = 3; break;}
396 if (save[3]) {load = 4; break;}
397 if (save[4]) {load = 5; break;}
399 if (engine.keyState[SDL_SCANCODE_ESCAPE])
401 audio.playMenuSound(2);
418 engine.delay(frameLimit);
419 frameLimit = SDL_GetTicks() + 16;
422 engine.deleteWidgets();
424 SDL_FillRect(graphics.screen, NULL, graphics.black);
425 graphics.updateScreen();
436 (autoSaveSlot < 5) ? game.autoSaveSlot = autoSaveSlot : game.autoSave = false;
442 debug(("Map Name = %s", game.mapName))
444 else if (engine.skill == -1)
446 game.setMapName("data/practice");
447 game.setStageName("Training Mission");
448 engine.practice = true;
452 else if (engine.skill == 3)
455 game.hasAquaLung = game.hasJetPack = true;
458 if (strcmp(game.mapName, "data/spaceStation") == 0)
460 game.setMapName("data/finalBattle");
461 game.setStageName("Final Battle");
469 * Loads and shows the credits at the end of the game.
478 int numberOfCredits = 0;
479 int pos1 = 0, pos2 = 0, size = 0;
482 SDL_Surface *backdrop = graphics.quickSprite("CreditsBackGround", graphics.loadImage("gfx/main/creditsBack.png"));
484 engine.loadData(_("data/credits"));
486 line = strtok((char*)engine.dataBuffer, "\n");
488 sscanf(line, "%d", &numberOfCredits);
490 y = new float[numberOfCredits];
491 SDL_Surface **credit = new SDL_Surface*[numberOfCredits];
493 line = strtok(NULL, "\n");
497 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
501 sscanf(line, "%d %d %[^\n\r]", &pos2, &size, string);
507 graphics.setFontSize(size);
508 credit[i] = graphics.quickSprite("credit", graphics.getString(string, true));
512 if (i == numberOfCredits)
517 line = strtok(NULL, "\n");
520 SDL_Surface *device = graphics.quickSprite("credit", graphics.loadImage("gfx/main/creditsDevice.png"));
521 float deviceY = y[numberOfCredits - 7] - 50;
523 audio.loadMusic("music/credits");
526 engine.resetTimeDifference();
527 Uint32 now = SDL_GetTicks();
529 while (y[numberOfCredits - 1] > 350)
531 graphics.updateScreen();
535 engine.doTimeDifference();
537 SDL_FillRect(graphics.screen, NULL, graphics.black);
538 graphics.blit(backdrop, 0, 365, graphics.screen, false);
540 deviceY -= (0.25 * engine.getTimeDifference());
542 if ((deviceY > 10) && (deviceY < 470))
544 graphics.blit(device, 320, (int)deviceY, graphics.screen, true);
547 for (i = 0 ; i < numberOfCredits ; i++)
549 y[i] -= (0.25 * engine.getTimeDifference());
551 if ((y[i] > 10) && (y[i] < 470))
553 graphics.blit(credit[i], 320, (int)y[i], graphics.screen, true);
556 graphics.drawRect(0, 450, 640, 30, graphics.black, graphics.screen);
557 graphics.drawRect(0, 0, 640, 30, graphics.black, graphics.screen);
560 doMusicInfo(SDL_GetTicks() - (now + 10000));
565 graphics.delay(12000);
567 graphics.fadeToBlack();
574 * Shows the exit screen, mentioning the sequel and the book by Stephen Sweeney
578 SDL_FillRect(graphics.screen, NULL, graphics.black);
579 SDL_Surface *sequel = graphics.loadImage("gfx/main/sequel.png");
580 SDL_Surface *book = graphics.loadImage("gfx/main/book.png");
582 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
583 graphics.setFontSize(1);
584 graphics.drawString(_("If you like Blob Wars: Metal Blob Solid, you might also like:"), 320, 20, true, graphics.screen);
585 graphics.blit(sequel, 160, 200, graphics.screen, true);
586 graphics.blit(book, 480, 200, graphics.screen, true);
587 graphics.setFontSize(0);
588 graphics.drawString("http://blobandconquer.sf.net", 160, 380, true, graphics.screen);
589 graphics.drawString("http://www.battleforthesolarsystem.com", 480, 380, true, graphics.screen);
590 graphics.setFontSize(3);
591 graphics.drawString(_("Thank you for playing Blob Wars!"), 320, 430, true, graphics.screen);
592 graphics.setFontSize(0);
593 graphics.drawString(_("Press Space to Exit."), 320, 460, true, graphics.screen);
595 graphics.updateScreen();
600 } while(!engine.userAccepts());