1 /*
2 Copyright (C) 2004 Parallel Realities
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #include "title.h"
22
showTitle()23 void showTitle()
24 {
25 SDL_Surface *prlogo = graphics.getSprite("PRLogo", true)->getCurrentFrame();
26 SDL_Surface *presents = graphics.getSprite("Presents", true)->getCurrentFrame();
27 SDL_Surface *sdl = graphics.getSprite("SDL", true)->getCurrentFrame();
28 SDL_Surface *virusLogo = graphics.getSprite("TitleLogo", true)->getCurrentFrame();
29
30 unsigned int then = SDL_GetTicks() + 2000;
31 unsigned int now = then;
32 int section = 0;
33 float logoY = 300;
34
35 engine.resetTimeDifference();
36
37 while (true)
38 {
39 now = SDL_GetTicks();
40
41 engine.doTimeDifference();
42 graphics.updateScreen();
43 graphics.clearScreen(graphics.black);
44 engine.getInput();
45
46 if (now > then)
47 {
48 section++;
49 then = now + 5000;
50 if ((section % 2) == 0)
51 {
52 then = now + 1500;
53 }
54
55 if (section == 6)
56 {
57 then = now + 2000;
58 }
59 }
60
61 switch (section)
62 {
63 case 1:
64 graphics.blit(prlogo, 400, 300, graphics.screen, true);
65 break;
66 case 3:
67 graphics.blit(presents, 400, 300, graphics.screen, true);
68 break;
69 case 5:
70 graphics.blit(sdl, 400, 300, graphics.screen, true);
71 break;
72 }
73
74 if (section >= 7)
75 {
76 graphics.blit(virusLogo, 400, (int)logoY, graphics.screen, true);
77
78 if (section > 7)
79 {
80 logoY -= (2 * engine.getTimeDifference());
81 }
82 }
83
84 if ((engine.userAccepts()) || (logoY <= 100))
85 {
86 return;
87 }
88 }
89 }
90
doTitleViruses()91 void doTitleViruses()
92 {
93 Virus *virus = (Virus*)gameData.virusList.getHead();
94
95 while (virus->next != NULL)
96 {
97 virus = (Virus*)virus->next;
98
99 virus->dy += (0.1 * engine.getTimeDifference());
100 Math::limitFloat(&virus->dy, -8, 10);
101
102 virus->y += virus->dy * engine.getTimeDifference();
103 virus->x += virus->dx * engine.getTimeDifference();
104
105 if (virus->y > 600)
106 {
107 virus->y = 600;
108 virus->dy = Math::rrand(-8, -2);
109 }
110
111 if (virus->x < 0)
112 {
113 virus->x = 0;
114 virus->dx = -virus->dx;
115 }
116
117 if (virus->x > 800)
118 {
119 virus->x = 800;
120 virus->dx = -virus->dx;
121 }
122
123 graphics.blit(virus->sprite->getCurrentFrame(), (int)virus->x, (int)virus->y, graphics.screen, true);
124 }
125 }
126
addTitleViruses()127 void addTitleViruses()
128 {
129 Sprite *virusSprite1 = graphics.getSprite("Virus1", true);
130 Sprite *virusSprite2 = graphics.getSprite("Virus2", true);
131 Sprite *virusSprite3 = graphics.getSprite("Virus3", true);
132
133 Virus *virus;
134
135 for (int i = 0 ; i < 25 ; i++)
136 {
137 virus = new Virus();
138
139 switch (rand() % 3)
140 {
141 case VIRUS_THIEF:
142 virus->type = VIRUS_THIEF;
143 virus->sprite = virusSprite1;
144 break;
145
146 case VIRUS_EAT:
147 virus->type = VIRUS_EAT;
148 virus->sprite = virusSprite2;
149 break;
150
151 case VIRUS_DESTROY:
152 virus->type = VIRUS_DESTROY;
153 virus->sprite = virusSprite3;
154 break;
155 }
156
157 virus->x = Math::rrand(0, 800);
158 virus->y = Math::rrand(-50, 0);
159
160 virus->dx = Math::rrand(-2, 2);
161 if (virus->dx == 0)
162 virus->dx = Math::rrand(1, 2);
163
164 gameData.addVirus(virus);
165 }
166 }
167
doTitle()168 int doTitle()
169 {
170 graphics.clearScreen(graphics.black);
171 graphics.delay(500);
172
173 gameData.clear();
174
175 SDL_Surface *title = graphics.getSprite("TitleLogo", true)->getCurrentFrame();
176
177 if (!engine.loadWidgets("data/titleWidgets"))
178 graphics.showErrorAndExit(ERR_FILE, "data/titleWidgets");
179
180 Widget *widget = engine.getWidgetByName("labelManual");
181 strcpy(widget->label, GAMEPLAYMANUAL);
182
183 if (!engine.useAudio)
184 {
185 engine.enableWidget("soundvol", false);
186 engine.enableWidget("musicvol", false);
187 }
188
189 float brightness;
190
191 int start, options, credits, highscores, help, quit, back, easy, normal, hard, nightmare, ultimate;
192 start = options = credits = highscores = help = quit = back = easy = normal = hard = nightmare = ultimate = 0;
193
194 engine.setWidgetVariable("newGame", &start);
195 engine.setWidgetVariable("highscores", &highscores);
196 engine.setWidgetVariable("credits", &credits);
197 engine.setWidgetVariable("options", &options);
198 engine.setWidgetVariable("help", &help);
199 engine.setWidgetVariable("quit", &quit);
200
201 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
202 engine.setWidgetVariable("sound", &gameData.soundVolume);
203 engine.setWidgetVariable("music", &gameData.musicVolume);
204 engine.setWidgetVariable("gamma", &gameData.gamma);
205
206 engine.setWidgetVariable("easy", &easy);
207 engine.setWidgetVariable("normal", &normal);
208 engine.setWidgetVariable("hard", &hard);
209 engine.setWidgetVariable("nightmare", &nightmare);
210 engine.setWidgetVariable("ultimate", &ultimate);
211
212 engine.setWidgetVariable("back", &back);
213
214 engine.showWidgetGroup("mainMenu", true);
215 engine.showWidgetGroup("help", false);
216 engine.showWidgetGroup("options", false);
217 engine.showWidgetGroup("skill", false);
218 engine.showWidgetGroup("back", false);
219
220 engine.highlightWidget("newGame");
221
222 bool showMenu = false;
223
224 audio.loadMusic("music/Infection.mod");
225
226 addTitleViruses();
227
228 int then = SDL_GetTicks() + 2000;
229 int now = SDL_GetTicks();
230 int section = 0;
231
232 #if USEPAK
233 int sectionLimit = 13;
234
235 if ((gameData.nightmareCount > 0) && (gameData.nightmareCount < 50))
236 sectionLimit = 15;
237
238 if (gameData.nightmareCount == 0)
239 sectionLimit = 17;
240 #else
241 int sectionLimit = 17;
242 #endif
243
244 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
245 graphics.setFontSize(1);
246
247 audio.playMusic();
248
249 if (!gameData.shownTitles)
250 {
251 showTitle();
252 gameData.shownTitles = true;
253 }
254
255 engine.resetTimeDifference();
256
257 engine.clearInput();
258 engine.flushInput();
259
260 while (true)
261 {
262 engine.doTimeDifference();
263
264 now = SDL_GetTicks();
265
266 graphics.updateScreen();
267
268 engine.getInput();
269
270 graphics.clearScreen(graphics.black);
271
272 graphics.blit(title, 400, 100, graphics.screen, true);
273
274 graphics.setFontSize(0);
275 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
276 graphics.drawString(10, 580, TXT_LEFT, graphics.screen, "Copyright (c) Parallel Realities 2005, 2010");
277 graphics.drawString(790, 580, TXT_RIGHT, graphics.screen, "Version %.1f", VERSION);
278 graphics.setFontSize(1);
279
280 doTitleViruses();
281
282 if (!showMenu)
283 {
284 if (now > then)
285 {
286 Math::wrapInt(&(++section), 0, sectionLimit);
287 then = now + 4000;
288 if ((section % 2) == 0)
289 then = now + 1000;
290 }
291
292 switch (section)
293 {
294 case 1:
295 graphics.drawString(400, 325, TXT_CENTERED, graphics.screen, "++ Main Design and Programming ++");
296 graphics.drawString(400, 350, TXT_CENTERED, graphics.screen, "Stephen Sweeney");
297 graphics.drawString(400, 375, TXT_CENTERED, graphics.screen, "Rik Sweeney");
298 break;
299
300 case 3:
301 graphics.drawString(400, 325, TXT_CENTERED, graphics.screen, "++ File, Directory and Icon Graphics ++");
302 graphics.drawString(400, 350, TXT_CENTERED, graphics.screen, "Everaldo (Crystal Icon Theme)");
303 graphics.drawString(400, 400, TXT_CENTERED, graphics.screen, "++ Virus Graphics ++");
304 graphics.drawString(400, 425, TXT_CENTERED, graphics.screen, "Stephen Sweeney");
305 break;
306
307 case 5:
308 graphics.drawString(400, 325, TXT_CENTERED, graphics.screen, "++ Music By ++");
309 graphics.drawString(400, 350, TXT_CENTERED, graphics.screen, "Rene Siekmann");
310 graphics.drawString(400, 375, TXT_CENTERED, graphics.screen, "xtd / mystic & trsi");
311 break;
312
313 case 7:
314 graphics.drawString(400, 325, TXT_CENTERED, graphics.screen, "++ %s Version By ++", PLATFORMNAME);
315 graphics.drawString(400, 350, TXT_CENTERED, graphics.screen, PORTERSNAME);
316 graphics.drawString(400, 375, TXT_CENTERED, graphics.screen, PORTERSEMAIL);
317 break;
318
319 case 9:
320 showHighScores(MODE_EASY, 200);
321 break;
322
323 case 11:
324 showHighScores(MODE_NORMAL, 200);
325 break;
326
327 case 13:
328 showHighScores(MODE_HARD, 200);
329 break;
330
331 case 15:
332 showHighScores(MODE_NIGHTMARE, 200);
333 break;
334
335 case 17:
336 showHighScores(MODE_ULTIMATE, 200);
337 break;
338 }
339
340 if (engine.userAccepts())
341 {
342 showMenu = true;
343 engine.clearInput();
344 engine.flushInput();
345 }
346 }
347 else
348 {
349 if (engine.processWidgets())
350 {
351 if (engine.widgetChanged("fullscreen"))
352 SDL_WM_ToggleFullScreen(graphics.screen);
353
354 if (engine.widgetChanged("sound"))
355 audio.setSoundVolume(gameData.soundVolume);
356
357 if (engine.widgetChanged("music"))
358 audio.setMusicVolume(gameData.musicVolume);
359
360 if (engine.widgetChanged("gamma"))
361 {
362 brightness = gameData.gamma;
363 brightness /= 10;
364 SDL_SetGamma(brightness, brightness, brightness);
365 }
366 }
367
368 drawWidgets();
369
370 if (start)
371 {
372 start = 0;
373 engine.showWidgetGroup("mainMenu", false);
374 engine.showWidgetGroup("skill", true);
375 engine.showWidgetGroup("back", true);
376 engine.highlightWidget("normal");
377
378 #if USEPAK
379 if (gameData.nightmareCount > 50)
380 engine.showWidget("nightmare", false);
381
382 if (gameData.nightmareCount > 0)
383 engine.showWidget("ultimate", false);
384 #endif
385 }
386
387 if (options)
388 {
389 options = 0;
390 engine.showWidgetGroup("mainMenu", false);
391 engine.showWidgetGroup("options", true);
392 engine.showWidgetGroup("back", true);
393 engine.highlightWidget("fullscreen");
394 }
395
396 if (help)
397 {
398 help = 0;
399 engine.showWidgetGroup("mainMenu", false);
400 engine.showWidgetGroup("help", true);
401 engine.showWidgetGroup("back", true);
402 engine.highlightWidget("back");
403 }
404
405 if (back)
406 {
407 back = 0;
408 engine.showWidgetGroup("mainMenu", true);
409 engine.showWidgetGroup("options", false);
410 engine.showWidgetGroup("skill", false);
411 engine.showWidgetGroup("help", false);
412 engine.showWidgetGroup("back", false);
413 engine.highlightWidget("newGame");
414 }
415
416 if (highscores)
417 {
418 section = 9;
419 then = now + 4000;
420 showMenu = false;
421 highscores = 0;
422 }
423
424 if (credits)
425 {
426 section = 1;
427 then = now + 4000;
428 showMenu = false;
429 credits = 0;
430 }
431
432 if (quit)
433 exit(0);
434
435 if ((easy) || (normal) || (hard) || (nightmare) || (ultimate))
436 break;
437
438 if (engine.keyState[SDLK_ESCAPE])
439 {
440 showMenu = false;
441 start = back = 0;
442 engine.showWidgetGroup("mainMenu", true);
443 engine.showWidgetGroup("skill", false);
444 engine.showWidgetGroup("back", false);
445 engine.highlightWidget("newGame");
446 engine.keyState[SDLK_ESCAPE] = 0;
447 }
448
449 if (showMenu == false)
450 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
451 }
452 }
453
454 audio.stopMusic();
455 gameData.clear();
456
457 if (easy) gameData.skill = 0;
458 if (normal) gameData.skill = 1;
459 if (hard) gameData.skill = 2;
460 if (nightmare) gameData.skill = 3;
461 if (ultimate) gameData.skill = 4;
462
463 return SECTION_GAME;
464 }
465