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.
24 * Displays the skill level widgets and hide the others
26 void showSkillLevels()
28 engine.showWidgetGroup("skill", true);
29 engine.showWidgetGroup("mainMenu", false);
30 engine.showWidgetGroup("gameSlots", false);
32 engine.showWidget("back", true);
34 engine.highlightWidget("normal");
36 engine.enableWidget("extreme", engine.extremeAvailable);
40 * Displays the save game widgets and hide the others
44 engine.showWidgetGroup("gameSlots", true);
45 engine.showWidgetGroup("mainMenu", false);
47 engine.showWidget("back", true);
49 engine.highlightWidget("slot1");
54 engine.showWidgetGroup("saveGames", true);
55 engine.showWidgetGroup("mainMenu", false);
57 engine.showWidget("back", true);
59 engine.highlightWidget("save1");
63 * Displays the manual widgets and hide the others
70 engine.showWidgetGroup("help", true);
71 engine.showWidgetGroup("mainMenu", false);
73 engine.showWidget("back", true);
75 engine.highlightWidget("back");
80 * Displays the title widgets and hide the others.
81 * Also disables Continue and Load Game if games are not
82 * available to be loaded.
84 void showTitleWidgets()
86 engine.showWidgetGroup("skill", false);
87 engine.showWidgetGroup("saveGames", false);
88 engine.showWidgetGroup("gameSlots", false);
89 engine.showWidgetGroup("help", false);
90 engine.showWidget("back", false);
92 engine.showWidgetGroup("mainMenu", true);
94 engine.highlightWidget("newGame");
96 if (!engine.continueSaveSlot)
98 engine.enableWidget("loadGame", false);
99 engine.enableWidget("continue", false);
103 engine.highlightWidget("continue");
108 * Creates the data labels for the save game slots
109 * according to the save game data available
111 void setupSaveWidgets()
116 for (int i = 0 ; i < 5 ; i++)
118 snprintf(widgetName, sizeof widgetName, "save%d", i + 1);
119 strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
121 if ((strstr(engine.saveSlot[i], _("Empty"))) || (strstr(engine.saveSlot[i], _("Corrupt"))))
123 engine.enableWidget(widgetName, false);
126 snprintf(widgetName, sizeof widgetName, "slot%d", i + 1);
127 strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
132 * Loads the title widgets
134 void loadTitleWidgets()
136 if (!engine.loadWidgets(_("data/titleWidgets")))
138 graphics.showErrorAndExit(ERR_FILE, _("data/titleWidgets"));
145 Widget *widget = engine.getWidgetByName("labelManual");
146 strncpy(widget->label, GAMEPLAYMANUAL, sizeof widget->label);
152 * Does the main game title sequence
153 * @return The section to proceed to (see main.cpp)
160 SDL_FillRect(graphics.screen, NULL, graphics.black);
161 graphics.delay(1000);
168 float titleAlpha = 0;
169 bool allFadedOn = false;
171 graphics.quickSprite("cheatHeader", graphics.loadImage("gfx/main/cheats.png"));
172 graphics.quickSprite("optionsHeader", graphics.loadImage("gfx/main/options.png"));
173 graphics.quickSprite("keyHeader", graphics.loadImage("gfx/main/keyConfig.png"));
174 graphics.quickSprite("joystickHeader", graphics.loadImage("gfx/main/joystickConfig.png"));
175 graphics.quickSprite("optionsBackground", graphics.loadImage("gfx/main/optionsBackground.png"));
177 SDL_Surface *prlogo = graphics.quickSprite("PRLogo", graphics.loadImage("gfx/main/prlogo.gif"));
178 SDL_Surface *title = graphics.quickSprite("Title", graphics.loadImage("gfx/main/title.png"));
180 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
182 graphics.setFontSize(3);
183 SDL_Surface *presents = graphics.quickSprite("Presents", graphics.getString(_("Presents"), true));
184 SDL_Surface *sdl = graphics.quickSprite("SDL", graphics.getString(_("An SDL Game"), true));
186 graphics.setFontSize(2);
187 SDL_Surface *subTitle = graphics.quickSprite("SubTitle", graphics.getString(_("Blob Wars : Episode I"), true));
189 graphics.setFontSize(0);
190 SDL_Surface *copyright = graphics.quickSprite("Copyright", graphics.getString(_("Copyright (C) 2004, 2005 Parallel Realities"), true));
193 #define STRINGIFY_VALUE(x) STRINGIFY(x)
194 #define STRINGIFY(x) #x
195 snprintf(v, sizeof v, _("Version %s"), STRINGIFY_VALUE(VERSION));
196 SDL_Surface *version = graphics.quickSprite("Version", graphics.getString(v, true));
198 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, 0);
200 audio.loadMusic("music/title");
202 graphics.loadBackground("gfx/main/CircuitBoard.jpg");
203 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, 0);
205 int startNewGame, options, quit, help, easy, normal, hard, extreme, back, practice;
206 int load, cont, save[5], slot[6];
209 startNewGame = options = quit = easy = normal = hard = extreme = back = help = practice = 0;
210 load = cont = save[0] = save[1] = save[2] = save[3] = save[4] = 0;
211 slot[0] = slot[1] = slot[2] = slot[3] = slot[4] = slot[5] = 0;
214 engine.setWidgetVariable("newGame", &startNewGame);
215 engine.setWidgetVariable("loadGame", &load);
216 engine.setWidgetVariable("continue", &cont);
217 engine.setWidgetVariable("options", &options);
218 engine.setWidgetVariable("help", &help);
219 engine.setWidgetVariable("quit", &quit);
228 Uint32 now = SDL_GetTicks();
230 unsigned int frameLimit = SDL_GetTicks() + 16;
234 graphics.updateScreen();
239 for (int x = (int)offX ; x < 640 ; x += graphics.background->w)
241 for (int y = 0 ; y < 480 ; y += graphics.background->h)
243 graphics.blit(graphics.background, x, y, graphics.screen, false);
249 if ((SDL_GetTicks() >= now + 2000) && (SDL_GetTicks() <= now + 10000))
251 graphics.blit(prlogo, 320, 240, graphics.screen, true);
253 else if ((SDL_GetTicks() >= now + 13000) && (SDL_GetTicks() <= now + 19000))
255 graphics.blit(presents, 320, 240, graphics.screen, true);
257 else if ((SDL_GetTicks() >= now + 22000) && (SDL_GetTicks() <= now + 27000))
259 graphics.blit(sdl, 320, 240, graphics.screen, true);
262 if (engine.userAccepts())
269 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha);
270 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha);
274 if ((SDL_GetTicks() >= now + 4000) || (allFadedOn))
279 SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha);
283 if ((SDL_GetTicks() >= now + 29000) || (allFadedOn))
285 if (titleAlpha < 255)
288 SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha);
292 graphics.blit(subTitle, 320, 180, graphics.screen, true);
293 graphics.blit(copyright, 10, 460, graphics.screen, false);
294 graphics.blit(version, (630 - version->w), 460, graphics.screen, false);
299 Math::wrapFloat(&(offX -= 0.25), -graphics.background->w, 0);
303 graphics.blit(title, 320, 100, graphics.screen, true);
309 audio.playMenuSound(engine.processWidgets());
316 engine.setWidgetVariable("newGame", &startNewGame);
317 engine.setWidgetVariable("loadGame", &load);
318 engine.setWidgetVariable("continue", &cont);
319 engine.setWidgetVariable("options", &options);
320 engine.setWidgetVariable("help", &help);
321 engine.setWidgetVariable("quit", &quit);
329 engine.setWidgetVariable("back", &back);
336 engine.setWidgetVariable("slot1", &slot[0]);
337 engine.setWidgetVariable("slot2", &slot[1]);
338 engine.setWidgetVariable("slot3", &slot[2]);
339 engine.setWidgetVariable("slot4", &slot[3]);
340 engine.setWidgetVariable("slot5", &slot[4]);
341 engine.setWidgetVariable("slot6", &slot[5]);
342 engine.setWidgetVariable("back", &back);
346 for (int i = 0 ; i < 6 ; i++)
351 engine.setWidgetVariable("practice", &practice);
352 engine.setWidgetVariable("easy", &easy);
353 engine.setWidgetVariable("normal", &normal);
354 engine.setWidgetVariable("hard", &hard);
355 engine.setWidgetVariable("extreme", &extreme);
356 engine.setWidgetVariable("back", &back);
365 engine.setWidgetVariable("save1", &save[0]);
366 engine.setWidgetVariable("save2", &save[1]);
367 engine.setWidgetVariable("save3", &save[2]);
368 engine.setWidgetVariable("save4", &save[3]);
369 engine.setWidgetVariable("save5", &save[4]);
370 engine.setWidgetVariable("back", &back);
374 if (easy) {engine.skill = 0; break;}
375 if (normal) {engine.skill = 1; break;}
376 if (hard) {engine.skill = 2; break;}
377 if (extreme) {engine.skill = 3; break;}
378 if (practice) {engine.skill = -1; break;}
380 if (cont) {load = engine.continueSaveSlot; break;}
382 if (save[0]) {load = 1; break;}
383 if (save[1]) {load = 2; break;}
384 if (save[2]) {load = 3; break;}
385 if (save[3]) {load = 4; break;}
386 if (save[4]) {load = 5; break;}
388 if (engine.keyState[SDLK_ESCAPE])
390 audio.playMenuSound(2);
407 engine.delay(frameLimit);
408 frameLimit = SDL_GetTicks() + 16;
411 engine.deleteWidgets();
413 SDL_FillRect(graphics.screen, NULL, graphics.black);
414 graphics.updateScreen();
428 (autoSaveSlot < 5) ? game.autoSaveSlot = autoSaveSlot : game.autoSave = false;
434 debug(("Map Name = %s", game.mapName))
436 else if (engine.skill == -1)
438 game.setMapName("data/practice");
439 game.setStageName("Training Mission");
440 engine.practice = true;
444 else if (engine.skill == 3)
447 game.hasAquaLung = game.hasJetPack = true;
450 if (strcmp(game.mapName, "data/spaceStation") == 0)
452 game.setMapName("data/finalBattle");
453 game.setStageName("Final Battle");
461 * Loads and shows the credits at the end of the game.
470 int numberOfCredits = 0;
471 int pos1 = 0, pos2 = 0, size = 0;
474 SDL_Surface *backdrop = graphics.quickSprite("CreditsBackGround", graphics.loadImage("gfx/main/creditsBack.png"));
476 engine.loadData(_("data/credits"));
478 line = strtok((char*)engine.dataBuffer, "\n");
480 sscanf(line, "%d", &numberOfCredits);
482 y = new float[numberOfCredits];
483 SDL_Surface **credit = new SDL_Surface*[numberOfCredits];
485 line = strtok(NULL, "\n");
489 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
493 sscanf(line, "%d %d %[^\n\r]", &pos2, &size, string);
499 graphics.setFontSize(size);
500 credit[i] = graphics.quickSprite("credit", graphics.getString(string, true));
504 if (i == numberOfCredits)
509 line = strtok(NULL, "\n");
512 SDL_Surface *device = graphics.quickSprite("credit", graphics.loadImage("gfx/main/creditsDevice.png"));
513 float deviceY = y[numberOfCredits - 7] - 50;
515 audio.loadMusic("music/credits");
518 engine.resetTimeDifference();
520 while (y[numberOfCredits - 1] > 350)
522 graphics.updateScreen();
526 engine.doTimeDifference();
528 SDL_FillRect(graphics.screen, NULL, graphics.black);
529 graphics.blit(backdrop, 0, 365, graphics.screen, false);
531 deviceY -= (0.25 * engine.getTimeDifference());
533 if ((deviceY > 10) && (deviceY < 470))
535 graphics.blit(device, 320, (int)deviceY, graphics.screen, true);
538 for (i = 0 ; i < numberOfCredits ; i++)
540 y[i] -= (0.25 * engine.getTimeDifference());
542 if ((y[i] > 10) && (y[i] < 470))
544 graphics.blit(credit[i], 320, (int)y[i], graphics.screen, true);
547 graphics.drawRect(0, 450, 640, 30, graphics.black, graphics.screen);
548 graphics.drawRect(0, 0, 640, 30, graphics.black, graphics.screen);
554 graphics.delay(12000);
556 graphics.fadeToBlack();