2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 extern void doMusicInfo(unsigned int);
26 * Displays the skill level widgets and hide the others
28 void showSkillLevels()
30 engine.showWidgetGroup("skill", true);
31 engine.showWidgetGroup("mainMenu", false);
32 engine.showWidgetGroup("gameSlots", false);
34 engine.showWidget("back", true);
36 engine.highlightWidget("normal");
38 engine.enableWidget("extreme", engine.extremeAvailable);
42 * Displays the save game widgets and hide the others
46 engine.showWidgetGroup("gameSlots", true);
47 engine.showWidgetGroup("mainMenu", false);
49 engine.showWidget("back", true);
51 engine.highlightWidget("slot1");
56 engine.showWidgetGroup("saveGames", true);
57 engine.showWidgetGroup("mainMenu", false);
59 engine.showWidget("back", true);
61 engine.highlightWidget("save1");
65 * Displays the manual widgets and hide the others
72 engine.showWidgetGroup("help", true);
73 engine.showWidgetGroup("mainMenu", false);
75 engine.showWidget("back", true);
77 engine.highlightWidget("back");
82 * Displays the title widgets and hide the others.
83 * Also disables Continue and Load Game if games are not
84 * available to be loaded.
86 void showTitleWidgets()
88 engine.showWidgetGroup("skill", false);
89 engine.showWidgetGroup("saveGames", false);
90 engine.showWidgetGroup("gameSlots", false);
91 engine.showWidgetGroup("help", false);
92 engine.showWidget("back", false);
94 engine.showWidgetGroup("mainMenu", true);
96 engine.highlightWidget("newGame");
98 if (!engine.continueSaveSlot)
100 engine.enableWidget("loadGame", false);
101 engine.enableWidget("continue", false);
105 engine.highlightWidget("continue");
110 * Creates the data labels for the save game slots
111 * according to the save game data available
113 void setupSaveWidgets()
118 for (int i = 0 ; i < 5 ; i++)
120 snprintf(widgetName, sizeof widgetName, "save%d", i + 1);
121 strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
123 if ((strstr(engine.saveSlot[i], _("Empty"))) || (strstr(engine.saveSlot[i], _("Corrupt"))))
125 engine.enableWidget(widgetName, false);
128 snprintf(widgetName, sizeof widgetName, "slot%d", i + 1);
129 strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
134 * Loads the title widgets
136 void loadTitleWidgets()
138 if (!engine.loadWidgets(_("data/titleWidgets")))
140 graphics.showErrorAndExit(ERR_FILE, _("data/titleWidgets"));
147 Widget *widget = engine.getWidgetByName("labelManual");
148 strncpy(widget->label, GAMEPLAYMANUAL, sizeof widget->label);
154 * Does the main game title sequence
155 * @return The section to proceed to (see main.cpp)
162 SDL_FillRect(graphics.screen, NULL, graphics.black);
163 graphics.delay(1000);
170 float titleAlpha = 0;
171 bool allFadedOn = false;
173 graphics.quickSprite("cheatHeader", graphics.loadImage("gfx/main/cheats.png"));
174 graphics.quickSprite("optionsHeader", graphics.loadImage("gfx/main/options.png"));
175 graphics.quickSprite("keyHeader", graphics.loadImage("gfx/main/keyConfig.png"));
176 graphics.quickSprite("joystickHeader", graphics.loadImage("gfx/main/joystickConfig.png"));
177 graphics.quickSprite("optionsBackground", graphics.loadImage("gfx/main/optionsBackground.png"));
179 SDL_Surface *prlogo = graphics.quickSprite("PRLogo", graphics.loadImage("gfx/main/prlogo.gif"));
180 SDL_Surface *title = graphics.quickSprite("Title", graphics.loadImage("gfx/main/title.png"));
182 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
184 graphics.setFontSize(3);
185 SDL_Surface *presents = graphics.quickSprite("Presents", graphics.getString(_("Presents"), true));
186 SDL_Surface *sdl = graphics.quickSprite("SDL", graphics.getString(_("An SDL Game"), true));
188 graphics.setFontSize(2);
189 SDL_Surface *subTitle = graphics.quickSprite("SubTitle", graphics.getString(_("Blob Wars : Episode I"), true));
191 graphics.setFontSize(0);
192 SDL_Surface *copyright = graphics.quickSprite("Copyright", graphics.getString(_("Copyright (C) 2004, 2005 Parallel Realities"), true));
195 #define STRINGIFY_VALUE(x) STRINGIFY(x)
196 #define STRINGIFY(x) #x
197 snprintf(v, sizeof v, _("Version %s"), STRINGIFY_VALUE(VERSION));
198 SDL_Surface *version = graphics.quickSprite("Version", graphics.getString(v, true));
200 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, 0);
202 audio.loadMusic("music/title");
204 graphics.loadBackground("gfx/main/CircuitBoard.jpg");
205 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, 0);
207 int startNewGame, options, quit, help, easy, normal, hard, extreme, back, practice;
208 int load, cont, save[5], slot[6];
211 startNewGame = options = quit = easy = normal = hard = extreme = back = help = practice = 0;
212 load = cont = save[0] = save[1] = save[2] = save[3] = save[4] = 0;
213 slot[0] = slot[1] = slot[2] = slot[3] = slot[4] = slot[5] = 0;
216 engine.setWidgetVariable("newGame", &startNewGame);
217 engine.setWidgetVariable("loadGame", &load);
218 engine.setWidgetVariable("continue", &cont);
219 engine.setWidgetVariable("options", &options);
220 engine.setWidgetVariable("help", &help);
221 engine.setWidgetVariable("quit", &quit);
230 Uint32 now = SDL_GetTicks();
232 unsigned int frameLimit = SDL_GetTicks() + 16;
236 graphics.updateScreen();
241 for (int x = (int)offX ; x < 640 ; x += graphics.background->w)
243 for (int y = 0 ; y < 480 ; y += graphics.background->h)
245 graphics.blit(graphics.background, x, y, graphics.screen, false);
251 if ((SDL_GetTicks() >= now + 2000) && (SDL_GetTicks() <= now + 10000))
253 graphics.blit(prlogo, 320, 240, graphics.screen, true);
255 else if ((SDL_GetTicks() >= now + 13000) && (SDL_GetTicks() <= now + 19000))
257 graphics.blit(presents, 320, 240, graphics.screen, true);
259 else if ((SDL_GetTicks() >= now + 22000) && (SDL_GetTicks() <= now + 27000))
261 graphics.blit(sdl, 320, 240, graphics.screen, true);
264 if (engine.userAccepts())
271 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha);
272 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha);
276 if ((SDL_GetTicks() >= now + 4000) || (allFadedOn))
281 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha);
285 if ((SDL_GetTicks() >= now + 29000) || (allFadedOn))
287 if (titleAlpha < 255)
290 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha);
294 graphics.blit(subTitle, 320, 180, graphics.screen, true);
295 graphics.blit(copyright, 10, 460, graphics.screen, false);
296 graphics.blit(version, (630 - version->w), 460, graphics.screen, false);
300 doMusicInfo(SDL_GetTicks() - (now + 39000));
303 Math::wrapFloat(&(offX -= 0.25), -graphics.background->w, 0);
307 graphics.blit(title, 320, 100, graphics.screen, true);
313 audio.playMenuSound(engine.processWidgets());
320 engine.setWidgetVariable("newGame", &startNewGame);
321 engine.setWidgetVariable("loadGame", &load);
322 engine.setWidgetVariable("continue", &cont);
323 engine.setWidgetVariable("options", &options);
324 engine.setWidgetVariable("help", &help);
325 engine.setWidgetVariable("quit", &quit);
333 engine.setWidgetVariable("back", &back);
340 engine.setWidgetVariable("slot1", &slot[0]);
341 engine.setWidgetVariable("slot2", &slot[1]);
342 engine.setWidgetVariable("slot3", &slot[2]);
343 engine.setWidgetVariable("slot4", &slot[3]);
344 engine.setWidgetVariable("slot5", &slot[4]);
345 engine.setWidgetVariable("slot6", &slot[5]);
346 engine.setWidgetVariable("back", &back);
350 for (int i = 0 ; i < 6 ; i++)
355 engine.setWidgetVariable("practice", &practice);
356 engine.setWidgetVariable("easy", &easy);
357 engine.setWidgetVariable("normal", &normal);
358 engine.setWidgetVariable("hard", &hard);
359 engine.setWidgetVariable("extreme", &extreme);
360 engine.setWidgetVariable("back", &back);
369 engine.setWidgetVariable("save1", &save[0]);
370 engine.setWidgetVariable("save2", &save[1]);
371 engine.setWidgetVariable("save3", &save[2]);
372 engine.setWidgetVariable("save4", &save[3]);
373 engine.setWidgetVariable("save5", &save[4]);
374 engine.setWidgetVariable("back", &back);
378 if (easy) {engine.skill = 0; break;}
379 if (normal) {engine.skill = 1; break;}
380 if (hard) {engine.skill = 2; break;}
381 if (extreme) {engine.skill = 3; break;}
382 if (practice) {engine.skill = -1; break;}
384 if (cont) {load = engine.continueSaveSlot; break;}
386 if (save[0]) {load = 1; break;}
387 if (save[1]) {load = 2; break;}
388 if (save[2]) {load = 3; break;}
389 if (save[3]) {load = 4; break;}
390 if (save[4]) {load = 5; break;}
392 if (engine.keyState[SDLK_ESCAPE])
394 audio.playMenuSound(2);
411 engine.delay(frameLimit);
412 frameLimit = SDL_GetTicks() + 16;
415 engine.deleteWidgets();
417 SDL_FillRect(graphics.screen, NULL, graphics.black);
418 graphics.updateScreen();
432 (autoSaveSlot < 5) ? game.autoSaveSlot = autoSaveSlot : game.autoSave = false;
438 debug(("Map Name = %s", game.mapName))
440 else if (engine.skill == -1)
442 game.setMapName("data/practice");
443 game.setStageName("Training Mission");
444 engine.practice = true;
448 else if (engine.skill == 3)
451 game.hasAquaLung = game.hasJetPack = true;
454 if (strcmp(game.mapName, "data/spaceStation") == 0)
456 game.setMapName("data/finalBattle");
457 game.setStageName("Final Battle");
465 * Loads and shows the credits at the end of the game.
474 int numberOfCredits = 0;
475 int pos1 = 0, pos2 = 0, size = 0;
478 SDL_Surface *backdrop = graphics.quickSprite("CreditsBackGround", graphics.loadImage("gfx/main/creditsBack.png"));
480 engine.loadData(_("data/credits"));
482 line = strtok((char*)engine.dataBuffer, "\n");
484 sscanf(line, "%d", &numberOfCredits);
486 y = new float[numberOfCredits];
487 SDL_Surface **credit = new SDL_Surface*[numberOfCredits];
489 line = strtok(NULL, "\n");
493 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
497 sscanf(line, "%d %d %[^\n\r]", &pos2, &size, string);
503 graphics.setFontSize(size);
504 credit[i] = graphics.quickSprite("credit", graphics.getString(string, true));
508 if (i == numberOfCredits)
513 line = strtok(NULL, "\n");
516 SDL_Surface *device = graphics.quickSprite("credit", graphics.loadImage("gfx/main/creditsDevice.png"));
517 float deviceY = y[numberOfCredits - 7] - 50;
519 audio.loadMusic("music/credits");
522 engine.resetTimeDifference();
523 Uint32 now = SDL_GetTicks();
525 while (y[numberOfCredits - 1] > 350)
527 graphics.updateScreen();
531 engine.doTimeDifference();
533 SDL_FillRect(graphics.screen, NULL, graphics.black);
534 graphics.blit(backdrop, 0, 365, graphics.screen, false);
536 deviceY -= (0.25 * engine.getTimeDifference());
538 if ((deviceY > 10) && (deviceY < 470))
540 graphics.blit(device, 320, (int)deviceY, graphics.screen, true);
543 for (i = 0 ; i < numberOfCredits ; i++)
545 y[i] -= (0.25 * engine.getTimeDifference());
547 if ((y[i] > 10) && (y[i] < 470))
549 graphics.blit(credit[i], 320, (int)y[i], graphics.screen, true);
552 graphics.drawRect(0, 450, 640, 30, graphics.black, graphics.screen);
553 graphics.drawRect(0, 0, 640, 30, graphics.black, graphics.screen);
556 doMusicInfo(SDL_GetTicks() - (now + 10000));
561 graphics.delay(12000);
563 graphics.fadeToBlack();