OSDN Git Service

README-jp.txtのBOMを削除した
[starfighter-jp/starfighter-jp.git] / src / title.cpp
1 /*
2 Copyright (C) 2003 Parallel Realities
3 Copyright (C) 2011, 2012, 2013 Guus Sliepen
4 Copyright (C) 2012, 2015, 2016 onpon4 <onpon4@riseup.net>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 3
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "Starfighter.h"
21
22 static int showGameMenu(int continueSaveSlot)
23 {
24         screen_blitText(TS_START_NEW_GAME);
25         screen_blitText(TS_LOAD_GAME);
26         if (continueSaveSlot != -1)
27         {
28                 screen_blitText(TS_CONTINUE_CURRENT_GAME);
29         }
30         screen_blitText(TS_OPTIONS);
31         if (engine.cheat)
32         {
33                 gfx_textSprites[TS_QUIT].y = screen->h / 3 + 150;
34                 screen_blitText(TS_CHEAT_OPTIONS);
35         }
36         else
37         {
38                 gfx_textSprites[TS_QUIT].y = screen->h / 3 + 130;
39         }
40         screen_blitText(TS_QUIT);
41
42         if (engine.cheat)
43                 return 6;
44
45         return 5;
46 }
47
48 static int showLoadMenu()
49 {
50         int rtn = 1;
51
52         for (int i = TS_SAVESLOT_0 ; i <= TS_SAVESLOT_5 ; i++)
53         {
54                 rtn++;
55                 if (gfx_textSprites[i].image != NULL)
56                 {
57                         screen_blitText(i);
58                         gfx_textSprites[TS_BACK_TO_MAIN_MENU].y = gfx_textSprites[i].y + 40;
59                 }
60         }
61         screen_blitText(TS_BACK_TO_MAIN_MENU);
62
63         return rtn;
64 }
65
66 static void createDifficultyMenu()
67 {
68         gfx_createTextObject(TS_START_GAME, "»Ï¤á¤ë",
69                 -1, screen->h / 3 + 50, FONT_WHITE);
70
71         if (game.difficulty == DIFFICULTY_EASY)
72                 gfx_createTextObject(TS_DIFFICULTY, "Æñ°×ÅÙ - ´Êñ",
73                         -1, screen->h / 3 + 70, FONT_WHITE);
74         else if (game.difficulty == DIFFICULTY_HARD)
75                 gfx_createTextObject(TS_DIFFICULTY, "Æñ°×ÅÙ - Æñ¤·¤¤",
76                         -1, screen->h / 3 + 70, FONT_WHITE);
77         else if (game.difficulty == DIFFICULTY_NIGHTMARE)
78                 gfx_createTextObject(TS_DIFFICULTY, "Æñ°×ÅÙ - °­Ì´!",
79                         -1, screen->h / 3 + 70, FONT_WHITE);
80         else if (game.difficulty == DIFFICULTY_ORIGINAL)
81                 gfx_createTextObject(TS_DIFFICULTY, "Æñ°×ÅÙ - µìÈÇ",
82                         -1, screen->h / 3 + 70, FONT_WHITE);
83         else
84                 gfx_createTextObject(TS_DIFFICULTY, "Æñ°×ÅÙ - ÉáÄÌ",
85                         -1, screen->h / 3 + 70, FONT_WHITE);
86 }
87
88 static int showDifficultyMenu()
89 {
90         gfx_textSprites[TS_BACK_TO_MAIN_MENU].y = screen->h / 3 + 110;
91
92         screen_blitText(TS_START_GAME);
93         screen_blitText(TS_DIFFICULTY);
94         screen_blitText(TS_BACK_TO_MAIN_MENU);
95
96         return 3;
97 }
98
99 static void createOptionsMenu()
100 {
101         if (engine.useSound)
102                 gfx_createTextObject(TS_SOUND, "¸ú²Ì²» - ON",
103                         -1, screen->h / 3 + 50, FONT_WHITE);
104         else
105                 gfx_createTextObject(TS_SOUND, "¸ú²Ì²» - OFF",
106                         -1, screen->h / 3 + 50, FONT_WHITE);
107
108         if (engine.useMusic)
109                 gfx_createTextObject(TS_MUSIC, "²»³Ú - ON",
110                         -1, screen->h / 3 + 70, FONT_WHITE);
111         else
112                 gfx_createTextObject(TS_MUSIC, "²»³Ú - OFF",
113                         -1, screen->h / 3 + 70, FONT_WHITE);
114
115         if (engine.fullScreen)
116                 gfx_createTextObject(TS_FULLSCREEN, "¥Õ¥ë¥¹¥¯¥ê¡¼¥ó - ON",
117                         -1, screen->h / 3 + 90, FONT_WHITE);
118         else
119                 gfx_createTextObject(TS_FULLSCREEN, "¥Õ¥ë¥¹¥¯¥ê¡¼¥ó - OFF",
120                         -1, screen->h / 3 + 90, FONT_WHITE);
121
122         if (engine.autoPause)
123                 gfx_createTextObject(TS_AUTOPAUSE, "¥ª¡¼¥È¥Ý¡¼¥º - ON",
124                         -1, screen->h / 3 + 110, FONT_WHITE);
125         else
126                 gfx_createTextObject(TS_AUTOPAUSE, "¥ª¡¼¥È¥Ý¡¼¥º - OFF",
127                         -1, screen->h / 3 + 110, FONT_WHITE);
128 }
129
130 static int showOptionsMenu()
131 {
132         gfx_textSprites[TS_BACK_TO_MAIN_MENU].y = screen->h / 3 + 150;
133
134         screen_blitText(TS_SOUND);
135         screen_blitText(TS_MUSIC);
136         screen_blitText(TS_FULLSCREEN);
137         screen_blitText(TS_AUTOPAUSE);
138         screen_blitText(TS_BACK_TO_MAIN_MENU);
139
140         return 5;
141 }
142
143 static void createCheatMenu()
144 {
145         if (engine.cheatShield)
146                 gfx_createTextObject(TS_UNLIMITED_SHIELD, "̵À©¸Â¤Î¥·¡¼¥ë¥É - ON",
147                         -1, screen->h / 3 + 50, FONT_WHITE);
148         else
149                 gfx_createTextObject(TS_UNLIMITED_SHIELD, "̵À©¸Â¤Î¥·¡¼¥ë¥É - OFF",
150                         -1, screen->h / 3 + 50, FONT_WHITE);
151
152         if (engine.cheatAmmo)
153                 gfx_createTextObject(TS_UNLIMITED_AMMO, "̵À©¸Â¤Î¥×¥é¥º¥Þ - ON",
154                         -1, screen->h / 3 + 70, FONT_WHITE);
155         else
156                 gfx_createTextObject(TS_UNLIMITED_AMMO, "̵À©¸Â¤Î¥×¥é¥º¥Þ - OFF",
157                         -1, screen->h / 3 + 70, FONT_WHITE);
158
159         if (engine.cheatCash)
160                 gfx_createTextObject(TS_UNLIMITED_CASH, "̵À©¸Â¤Î¥­¥ã¥Ã¥·¥å - ON",
161                         -1, screen->h / 3 + 90, FONT_WHITE);
162         else
163                 gfx_createTextObject(TS_UNLIMITED_CASH, "̵À©¸Â¤Î¥­¥ã¥Ã¥·¥å - OFF",
164                         -1, screen->h / 3 + 90, FONT_WHITE);
165
166         if (engine.cheatTime)
167                 gfx_createTextObject(TS_UNLIMITED_TIME, "̵À©¸Â¤Î»þ´Ö - ON",
168                         -1, screen->h / 3 + 110, FONT_WHITE);
169         else
170                 gfx_createTextObject(TS_UNLIMITED_TIME, "̵À©¸Â¤Î»þ´Ö - OFF",
171                         -1, screen->h / 3 + 110, FONT_WHITE);
172 }
173
174 static int showCheatMenu()
175 {
176         gfx_textSprites[TS_BACK_TO_MAIN_MENU].y = screen->h / 3 + 150;
177
178         screen_blitText(TS_UNLIMITED_SHIELD);
179         screen_blitText(TS_UNLIMITED_AMMO);
180         screen_blitText(TS_UNLIMITED_CASH);
181         screen_blitText(TS_UNLIMITED_TIME);
182         screen_blitText(TS_BACK_TO_MAIN_MENU);
183
184         return 5;
185 }
186
187 /*
188 This is the main title screen, with the stars whirling past and the
189 "Parallel Realities, Present..." text. Nothing too special.
190 */
191 int doTitle()
192 {
193         int continueSaveSlot;
194
195         int prx;
196         int pry;
197         int sfx;
198         int sfy;
199
200         int then;
201         int now;
202
203         int redGlow = 255;
204         int redDir = -2;
205         char buildVersion[25];
206
207         int selectedOption = 1;
208         bool skip = false;
209         int listLength = 5; // menu list length
210         int menuType = MENU_MAIN;
211
212         game_init();
213
214         engine.gameSection = SECTION_TITLE;
215
216         screen_flushBuffer();
217         gfx_free();
218         resetLists();
219         
220         // required to stop the title screen crashing
221         game.system = 0;
222         game.area = MISN_START;
223
224         loadGameGraphics();
225
226         screen_clear(black);
227         renderer_update();
228         screen_clear(black);
229
230         continueSaveSlot = initSaveSlots();
231
232         loadBackground("gfx/spirit.jpg");
233
234         SDL_Surface *prlogo, *sflogo;
235         prlogo = gfx_loadImage("gfx/prlogo.png");
236         sflogo = gfx_loadImage("gfx/sflogo.png");
237
238         prx = ((screen->w - prlogo->w) / 2);
239         pry = ((screen->h - prlogo->h) / 2);
240
241         sfx = ((screen->w - sflogo->w) / 2);
242         sfy = ((screen->h - sflogo->h) / 3);
243
244         gfx_createTextObject(TS_PRESENTS, "PRESENTS",
245                 -1, screen->h / 2, FONT_WHITE);
246         gfx_createTextObject(TS_AN_SDL_GAME, "AN SDL GAME",
247                 -1, screen->h / 2, FONT_WHITE);
248         gfx_createTextObject(TS_START_NEW_GAME, "ºÇ½é¤«¤é",
249                 -1, screen->h / 3 + 50, FONT_WHITE);
250         gfx_createTextObject(TS_LOAD_GAME, "¥í¡¼¥É",
251                 -1, screen->h / 3 + 70, FONT_WHITE);
252         gfx_createTextObject(TS_CONTINUE_CURRENT_GAME, "³¤­",
253                 -1, screen->h / 3 + 90, FONT_WHITE);
254         gfx_createTextObject(TS_OPTIONS, "¥ª¥×¥·¥ç¥ó",
255                 -1, screen->h / 3 + 110, FONT_WHITE);
256         gfx_createTextObject(TS_CHEAT_OPTIONS, "¥Á¡¼¥È¥ª¥×¥·¥ç¥ó",
257                 -1, screen->h / 3 + 130, FONT_WHITE);
258         gfx_createTextObject(TS_QUIT, "½ªÎ»",
259                 -1, screen->h / 3 + 130, FONT_WHITE);
260
261         createOptionsMenu();
262         createDifficultyMenu();
263         gfx_createTextObject(TS_BACK_TO_MAIN_MENU, "¥á¥¤¥ó¥á¥Ë¥å¡¼¤ËÌá¤ë", -1, 0, FONT_WHITE);
264
265         createCheatMenu();
266
267         // Set the star motion
268         engine.ssx = -0.5;
269         engine.ssy = 0;
270         engine.smx = 0;
271         engine.smy = 0;
272
273         then = SDL_GetTicks();
274
275         for (int i = 0 ; i < 15 ; i++)
276         {
277                 aliens[i] = alien_defs[rand() % 3];
278                 if ((rand() % 5) == 0)
279                         aliens[i] = alien_defs[CD_TRANSPORTSHIP];
280                 if ((rand() % 5) == 0)
281                         aliens[i] = alien_defs[CD_MINER];
282                 aliens[i].x = rand() % screen->w;
283                 aliens[i].y = rand() % (screen->h - 40);
284                 aliens[i].dx = 1 + rand() % 3;
285                 aliens[i].face = 0;
286         }
287
288     sprintf(buildVersion, "Version %s", VERSION );
289
290         SDL_Rect optionRec;
291
292         optionRec.x = screen->w / 2 - 110;
293         optionRec.y = screen->h / 3 + 45;
294         optionRec.h = 22;
295         optionRec.w = 215;
296
297         if (continueSaveSlot != -1)
298         {
299                 selectedOption = 3;
300                 optionRec.y += 40;
301         }
302
303         screen_drawBackground();
304
305         engine.done = 0;
306         flushInput();
307         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
308
309         audio_playMusic("music/walking_among_androids.ogg", 1);
310
311         while (!engine.done)
312         {
313                 renderer_update();
314                 screen_unBuffer();
315
316                 now = SDL_GetTicks();
317
318                 game_doStars();
319                 game_doExplosions();
320
321                 for (int i = 0 ; i < 15 ; i++)
322                 {
323                         explosion_addEngine(&aliens[i]);
324                         aliens[i].x += aliens[i].dx;
325                         screen_blit(aliens[i].image[0], (int)aliens[i].x, (int)aliens[i].y);
326                         if (aliens[i].x > screen->w + 30)
327                         {
328                                 aliens[i].x = -40;
329                                 aliens[i].y = rand() % (screen->h - 20);
330                                 aliens[i].dx = 1 + rand() % 3;
331                         }
332                 }
333
334                 if ((now - then > 2000) && (now - then < 8000) && (!skip))
335                 {
336                         screen_blit(prlogo, prx, pry);
337                 }
338                 else if ((now - then > 9000) && (now - then < 15000) && (!skip))
339                 {
340                         screen_blitText(TS_PRESENTS);
341                 }
342                 else if ((now - then > 16000) && (now - then < 21000) && (!skip))
343                 {
344                         screen_blitText(TS_AN_SDL_GAME);
345                 }
346                 else if ((now - then > 25500) || (skip))
347                 {
348                         screen_blit(sflogo, sfx, sfy);
349
350                         if ((now - then >= 27500) || (skip))
351                         {
352                                 screen_addBuffer(0, 0, screen->w, screen->h);
353
354                                 screen_drawRect(optionRec.x, optionRec.y, optionRec.w, optionRec.h, redGlow, 0x00, 0x00);
355
356                                 switch(menuType)
357                                 {
358                                         case MENU_MAIN:
359                                                 listLength = showGameMenu(continueSaveSlot);
360                                                 break;
361                                         case MENU_DIFFICULTY:
362                                                 listLength = showDifficultyMenu();
363                                                 break;
364                                         case MENU_LOAD:
365                                                 listLength = showLoadMenu();
366                                                 break;
367                                         case MENU_OPTIONS:
368                                                 listLength = showOptionsMenu();
369                                                 break;
370                                         case MENU_CHEAT:
371                                                 listLength = showCheatMenu();
372                                                 break;
373                                 }
374
375                                 redGlow += redDir;
376                                 if (redGlow <= 0) {redDir = 2; redGlow = 0;}
377                                 if (redGlow >= 255) {redDir = -2; redGlow = 255;}
378
379                                 if (engine.keyState[KEY_UP])
380                                 {
381                                         engine.keyState[KEY_UP] = 0;
382                                         WRAP_ADD(selectedOption, -1, 1, listLength + 1);
383                                         if (menuType == MENU_MAIN)
384                                                 if (selectedOption == 3)
385                                                         if (continueSaveSlot == -1)
386                                                                 selectedOption = 2;
387                                 }
388                                 if (engine.keyState[KEY_DOWN])
389                                 {
390                                         engine.keyState[KEY_DOWN] = 0;
391                                         WRAP_ADD(selectedOption, 1, 0, listLength);
392                                         if (menuType == MENU_MAIN)
393                                                 if (selectedOption == 3)
394                                                         if (continueSaveSlot == -1)
395                                                                 selectedOption = 4;
396                                 }
397
398                                 optionRec.y = screen->h / 3 + 26 + (20 * selectedOption);
399                                 if (menuType > MENU_MAIN)
400                                         if (selectedOption == listLength)
401                                                 optionRec.y += 20;
402
403                                 if (!skip)
404                                 {
405                                         gfx_renderString("Copyright Parallel Realities 2003",
406                                                 5, screen->h - 60, FONT_WHITE, 0, gfx_background);
407                                         gfx_renderString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012",
408                                                 5, screen->h - 40, FONT_WHITE, 0, gfx_background);
409                                         gfx_renderString("Copyright 2015, 2016 onpon4",
410                                                 5, screen->h - 20, FONT_WHITE, 0, gfx_background);
411                                         gfx_renderString(buildVersion, screen->w - 6 - strlen(buildVersion) * 9,
412                                                 screen->h - 20, FONT_WHITE, 0, gfx_background);
413                                         screen_addBuffer(0, 0, screen->w, screen->h);
414                                         skip = true;
415                                 }
416                         }
417                 }
418
419                 getPlayerInput();
420
421                 // if someone has invoked the credits cheat
422                 if (engine.cheatCredits)
423                 {
424                         doCredits();
425                         engine.cheatCredits = false;
426                 }
427
428                 if ((engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE]))
429                 {
430                         if ((now - then <= 27500) && (!skip))
431                         {
432                                 gfx_renderString("Copyright Parallel Realities 2003",
433                                         5, screen->h - 60, FONT_WHITE, 0, gfx_background);
434                                 gfx_renderString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012",
435                                         5, screen->h - 40, FONT_WHITE, 0, gfx_background);
436                                 gfx_renderString("Copyright 2015, 2016 onpon4",
437                                         5, screen->h - 20, FONT_WHITE, 0, gfx_background);
438                                 gfx_renderString(buildVersion, screen->w - 6 - strlen(buildVersion) * 9,
439                                         screen->h - 20, FONT_WHITE, 0, gfx_background);
440                                 screen_addBuffer(0, 560, 800, 40);
441                                 skip = true;
442                         }
443                         else
444                         {
445                                 switch (menuType)
446                                 {
447                                         case MENU_MAIN:
448                                                 if (selectedOption == 1)
449                                                 {
450                                                         menuType = MENU_DIFFICULTY;
451                                                         selectedOption = 1;
452                                                 }
453                                                 else if (selectedOption == 2)
454                                                 {
455                                                         menuType = MENU_LOAD;
456                                                         selectedOption = 1;
457                                                 }
458                                                 else if (selectedOption == 3)
459                                                         engine.done = 1;
460                                                 else if (selectedOption == 4)
461                                                 {
462                                                         menuType = MENU_OPTIONS;
463                                                         selectedOption = 1;
464                                                 }
465                                                 else if (selectedOption == 5)
466                                                 {
467                                                         if (engine.cheat)
468                                                         {
469                                                                 menuType = MENU_CHEAT;
470                                                                 selectedOption = 1;
471                                                         }
472                                                         else
473                                                                 engine.done = 1;
474                                                 }
475                                                 else if (selectedOption == 6)
476                                                         engine.done = 1;
477                                                 break;
478
479                                         case MENU_DIFFICULTY:
480                                                 if (selectedOption == 1)
481                                                         engine.done = 1;
482                                                 else if (selectedOption == 2)
483                                                 {
484                                                         game.difficulty++;
485                                                         game.difficulty %= DIFFICULTY_MAX;
486                                                 }
487                                                 else if (selectedOption == listLength)
488                                                 {
489                                                         menuType = MENU_MAIN;
490                                                         selectedOption = 1;
491                                                 }
492                                                 createDifficultyMenu();
493                                                 break;
494
495                                         case MENU_LOAD:
496                                                 if (selectedOption != listLength)
497                                                 {
498                                                         engine.done = 1;
499                                                         continueSaveSlot = selectedOption - 1;
500                                                         selectedOption = 3;
501                                                 }
502                                                 else
503                                                 {
504                                                         menuType = MENU_MAIN;
505                                                         selectedOption = 1;
506                                                 }
507                                                 break;
508
509                                         case MENU_OPTIONS:
510                                                 if ((selectedOption == 1) && (engine.useAudio))
511                                                         engine.useSound = !engine.useSound;
512                                                 else if ((selectedOption == 2) && (engine.useAudio))
513                                                 {
514                                                         engine.useMusic = !engine.useMusic;
515
516                                                         if (engine.useMusic)
517                                                         {
518                                                                 audio_playMusic(
519                                                                         "music/walking_among_androids.ogg", 1);
520                                                         }
521                                                         else
522                                                         {
523                                                                 audio_haltMusic();
524                                                         }
525                                                 }
526                                                 else if (selectedOption == 3)
527                                                 {
528                                                         engine.fullScreen = !engine.fullScreen;
529                                                         SDL_SetWindowFullscreen(window,
530                                                                 (engine.fullScreen ?
531                                                                         SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
532                                                 }
533                                                 else if (selectedOption == 4)
534                                                 {
535                                                         engine.autoPause = !engine.autoPause;
536                                                 }
537                                                 else if (selectedOption == listLength)
538                                                 {
539                                                         menuType = MENU_MAIN;
540                                                         selectedOption = 1;
541                                                 }
542                                                 createOptionsMenu();
543                                                 break;
544
545                                         case MENU_CHEAT:
546                                                 if (selectedOption == 1)
547                                                         engine.cheatShield = !engine.cheatShield;
548                                                 else if (selectedOption == 2)
549                                                         engine.cheatAmmo = !engine.cheatAmmo;
550                                                 else if (selectedOption == 3)
551                                                         engine.cheatCash = !engine.cheatCash;
552                                                 else if (selectedOption == 4)
553                                                         engine.cheatTime = !engine.cheatTime;
554                                                 else if (selectedOption == listLength)
555                                                 {
556                                                         menuType = MENU_MAIN;
557                                                         selectedOption = 1;
558                                                 }
559                                                 createCheatMenu();
560                                                 break;
561
562                                         default:
563                                                 menuType = MENU_MAIN;
564                                                 selectedOption = 1;
565                                                 break;
566                                 }
567                         }
568                         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
569                 }
570
571                 game_delayFrame();
572         }
573
574         audio_haltMusic();
575
576         SDL_FreeSurface(prlogo);
577         SDL_FreeSurface(sflogo);
578
579         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
580
581         resetLists();
582
583         if (selectedOption == 1)
584         {
585                 game_init();
586                 selectedOption = 2; // go straight to mission 0
587         }
588
589         if (selectedOption == 3)
590         {
591                 game_init();
592                 selectedOption = loadGame(continueSaveSlot);
593         }
594
595         // Send back a negative number...
596         if (selectedOption > 4)
597         {
598                 selectedOption = -1;
599                 exit(0);
600         }
601
602         return selectedOption;
603 }
604
605 /*
606 Scrolls the intro text up the screen and nothing else.
607 */
608 void showStory()
609 {
610         gfx_free();
611
612         int y = screen->h + 20;
613
614         FILE *fp;
615
616         fp = fopen("data/intro.txt", "rb");
617
618         int index = 0;
619         int nextPos = -1;
620         char string[255];
621
622         while (fscanf(fp, "%d %[^\n]%*c", &nextPos, string) == 2)
623         {
624                 y += nextPos;
625                 gfx_createTextObject(index, string, -1, y, FONT_WHITE);
626
627                 index++;
628         }
629
630         fclose(fp);
631
632         loadBackground("gfx/startUp.jpg");
633         screen_drawBackground();
634         screen_flushBuffer();
635
636         flushInput();
637         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
638
639         while (true)
640         {
641                 renderer_update();
642                 screen_unBuffer();
643
644                 getPlayerInput();
645
646                 if ((engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE]))
647                         break;
648
649                 // XXX: The fact that it's line 8 that's watched is completely
650                 // arbitrary. It might be prudent to replace this with something else.
651                 if (gfx_textSprites[8].y > (screen->h / 2) + 150)
652                 {
653                         for (int i = 0 ; i < 9 ; i++)
654                         {
655                                 gfx_textSprites[i].y -= 0.33333;
656                                 screen_blitText(i);
657                         }
658                 }
659                 else
660                 {
661                         SDL_Delay(3000);
662                         break;
663                 }
664
665                 game_delayFrame();
666         }
667 }
668
669 /*
670 The game over screen :(
671 */
672 void gameover()
673 {
674         screen_flushBuffer();
675         gfx_free();
676         SDL_FillRect(gfx_background, NULL, black);
677
678         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
679         engine.gameSection = SECTION_INTERMISSION;
680
681         SDL_Surface *gameover = gfx_loadImage("gfx/gameover.png");
682
683         screen_clear(black);
684         renderer_update();
685         screen_clear(black);
686         SDL_Delay(1000);
687
688         audio_playMusic("music/death.ogg", -1);
689
690         int x = (screen->w - gameover->w) / 2;
691         int y = (screen->h - gameover->h) / 2;
692
693         renderer_update();
694
695         flushInput();
696         engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
697
698         while (true)
699         {
700                 getPlayerInput();
701
702                 if (engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE])
703                         break;
704
705                 renderer_update();
706
707                 screen_unBuffer();
708                 x = ((screen->w - gameover->w) / 2) - RANDRANGE(-2, 2);
709                 y = ((screen->h - gameover->h) / 2)  - RANDRANGE(-2, 2);
710                 screen_blit(gameover, x,  y);
711
712                 game_delayFrame();
713         }
714
715         SDL_FreeSurface(gameover);
716         audio_haltMusic();
717         screen_flushBuffer();
718 }
719
720 void doCredits()
721 {
722         loadBackground("gfx/credits.jpg");
723         screen_flushBuffer();
724         gfx_free();
725
726         FILE *fp;
727         int lastCredit = -1;
728
729         int yPos = 0;
730         int yPos2 = screen->h;
731         char text[255];
732         int i;
733
734         textObject *credit;
735
736         screen_clear(black);
737         renderer_update();
738         screen_clear(black);
739
740         screen_drawBackground();
741
742         audio_playMusic("music/rise_of_spirit.ogg", 1);
743
744         fp = fopen("data/credits.txt", "rb");
745         // FIXME: It would be nice for the size of this array to be determined
746         // by the number of lines in the text file. I'm not sure how to do
747         // that at the moment, so just giving it a very large number for now.
748         credit = (textObject*) malloc(sizeof(textObject) * 300);
749
750         while (fscanf(fp, "%d %[^\n]%*c", &yPos, text) == 2)
751         {
752                 lastCredit++;
753                 credit[lastCredit].image = gfx_createTextSurface(text, FONT_WHITE);
754                 credit[lastCredit].x = (screen->w - credit[lastCredit].image->w) / 2;
755                 yPos2 += yPos;
756                 credit[lastCredit].y = yPos2;
757         }
758
759         fclose(fp);
760
761         engine.done = 0;
762
763         engine.keyState[KEY_ESCAPE] = 0;
764         engine.keyState[KEY_FIRE] = 0;
765         engine.keyState[KEY_ALTFIRE] = 0;
766         flushInput();
767
768         while (true)
769         {
770                 renderer_update();
771                 screen_unBuffer();
772
773                 getPlayerInput();
774                 if (engine.keyState[KEY_ESCAPE] || engine.keyState[KEY_FIRE] ||
775                                 engine.keyState[KEY_ALTFIRE])
776                         break;
777
778                 float speed = 0.5;
779                 if(engine.keyState[KEY_DOWN])
780                         speed = 2;
781                 else if(engine.keyState[KEY_UP])
782                         speed = -2;
783
784                 for (i = 0 ; i <= lastCredit ; i++)
785                 {
786                         if ((credit[i].y > -10) && (credit[i].y < (screen->h + 10)))
787                                 screen_blit(credit[i].image, (int)credit[i].x, (int)credit[i].y);
788                         if (speed > 0 && credit[lastCredit].y > ((screen->h / 2) + 100))
789                                 credit[i].y -= speed;
790                         else if(speed < 0 && credit[0].y < screen->h)
791                                 credit[i].y -= speed;
792                 }
793
794                 game_delayFrame();
795         }
796
797         for (i = 0 ; i <= lastCredit ; i++)
798         {
799                 SDL_FreeSurface(credit[i].image);
800         }
801
802         free(credit);
803 }
804