~ubuntu-branches/ubuntu/lucid/meritous/lucid

« back to all changes in this revision

Viewing changes to src/ending.c

  • Committer: Bazaar Package Importer
  • Author(s): Dylan R. E. Moonfire
  • Date: 2008-02-11 13:45:02 UTC
  • Revision ID: james.westby@ubuntu.com-20080211134502-8o235kfyej0lrag8
Tags: upstream-1.2+dfsg
ImportĀ upstreamĀ versionĀ 1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//   ending.c
 
3
//
 
4
//   Copyright 2007, 2008 Lancer-X/ASCEAI
 
5
//
 
6
//   This file is part of Meritous.
 
7
//
 
8
//   Meritous is free software: you can redistribute it and/or modify
 
9
//   it under the terms of the GNU General Public License as published by
 
10
//   the Free Software Foundation, either version 3 of the License, or
 
11
//   (at your option) any later version.
 
12
//
 
13
//   Meritous is distributed in the hope that it will be useful,
 
14
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
//   GNU General Public License for more details.
 
17
//
 
18
//   You should have received a copy of the GNU General Public License
 
19
//   along with Meritous.  If not, see <http://www.gnu.org/licenses/>.
 
20
//
 
21
 
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <math.h>
 
25
#include <SDL.h>
 
26
#include <SDL_image.h>
 
27
#include <assert.h>
 
28
 
 
29
#include "levelblit.h"
 
30
#include "audio.h"
 
31
#include "boss.h"
 
32
#include "mapgen.h"
 
33
 
 
34
void DrawScrolly(int t);
 
35
void DrawPText(int t);
 
36
void DrawSText(int t);
 
37
void DrawSTextV(int t);
 
38
void DrawCircuitFlash(int t, int method);
 
39
void DrawStream(int t);
 
40
 
 
41
void InitParticleStorm();
 
42
void RunParticleStorm(int offset);
 
43
 
 
44
SDL_Surface *streamspr = NULL, *glitter = NULL;
 
45
 
 
46
SDL_Color ending_pal[256];
 
47
 
 
48
void UpdatePalette()
 
49
{
 
50
        SDL_SetPalette(screen, SDL_PHYSPAL, ending_pal, 0, 256);
 
51
}
 
52
 
 
53
void DrawCredits();
 
54
 
 
55
int credits_scroll = 0;
 
56
 
 
57
int EndingEvents()
 
58
{
 
59
        static SDL_Event event;
 
60
        
 
61
        player_room = 0;
 
62
        current_boss = 3;
 
63
        boss_fight_mode = 4;
 
64
        
 
65
        MusicUpdate();
 
66
        
 
67
        while (SDL_PollEvent(&event)) {
 
68
                if (event.type == SDL_KEYDOWN) {
 
69
                        switch (event.key.keysym.sym) {
 
70
                                case SDLK_ESCAPE:
 
71
                                        return 1;
 
72
                                        break;
 
73
                                default:
 
74
                                        break;
 
75
                        }
 
76
                }
 
77
                if (event.type == SDL_QUIT) {
 
78
                        return 1;
 
79
                }
 
80
        }
 
81
        
 
82
        return 0;
 
83
}
 
84
 
 
85
void ShowEnding()
 
86
{
 
87
        int i;
 
88
        
 
89
        if (streamspr == NULL) {
 
90
                streamspr = IMG_Load("dat/i/stream.png");
 
91
                SDL_SetColorKey(streamspr, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0);
 
92
                glitter = IMG_Load("dat/i/glitter.png");
 
93
                SDL_SetColorKey(glitter, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0);
 
94
        }
 
95
        
 
96
        for (i = 0; i < 500; i += 1) {
 
97
                if (((i % 60) >= 24)&&((i % 60) < 34)) {
 
98
                        DrawCircuitFlash((i % 60) - 24, 0);
 
99
                } else {
 
100
                        DrawScrolly(i);
 
101
                }
 
102
                EndCycle(0);
 
103
                if (EndingEvents()) return;
 
104
        }
 
105
        for (i = 0; i < 30; i++) {
 
106
                DrawCircuitFlash(i, 1);
 
107
                
 
108
                EndCycle(0);
 
109
                if (EndingEvents()) return;
 
110
        }
 
111
        SDL_FillRect(screen, NULL, 255);
 
112
        for (i = 0; i < 350; i++) {
 
113
                DrawPText(i);
 
114
                EndCycle(0);
 
115
                if (EndingEvents()) return;
 
116
        }
 
117
        
 
118
        Paint(0, 0, 22, 27, "dat/d/cstream.loc");
 
119
        
 
120
        if (player_shield < 30) {
 
121
                for (i = 0; i < 400; i++) {
 
122
                        DrawStream(i);
 
123
                        EndCycle(0);
 
124
                        if (EndingEvents()) return;
 
125
                }
 
126
                InitParticleStorm();
 
127
                for (i = 0; i < 240; i++) {
 
128
                        RunParticleStorm(240-i);
 
129
                        EndCycle(0);
 
130
                        if (EndingEvents()) return;
 
131
                }
 
132
                for (i = 0; i < 60; i++) {
 
133
                        RunParticleStorm(0);
 
134
                        EndCycle(0);
 
135
                        if (EndingEvents()) return;
 
136
                }
 
137
                for (i = 0; i < 180; i++) {
 
138
                        RunParticleStorm(i*3);
 
139
                        EndCycle(0);
 
140
                        if (EndingEvents()) return;
 
141
                }
 
142
                for (i = 0; i < 500; i++) {
 
143
                        DrawSText(i);
 
144
                        EndCycle(0);
 
145
                        if (EndingEvents()) return;
 
146
                }
 
147
        } else {
 
148
                for (i = 0; i < 250; i++) {
 
149
                        DrawStream(i);
 
150
                        EndCycle(0);
 
151
                        if (EndingEvents()) return;
 
152
                }
 
153
                for (i = 0; i < 500; i++) {
 
154
                        DrawSTextV(i);
 
155
                        EndCycle(0);
 
156
                        if (EndingEvents()) return;
 
157
                }
 
158
        }
 
159
        
 
160
        credits_scroll = 0;
 
161
        for (;;) {
 
162
                DrawCredits();
 
163
                EndCycle(0);
 
164
                if (EndingEvents()) return;
 
165
        }
 
166
}
 
167
 
 
168
char *SText[15] = {     "Merit released the locks on the PSI flowing through the Dome,",
 
169
                                        "releasing the flow of PSI into the atmosphere.",
 
170
                                        "",
 
171
                                        "The Orcus Dome was originally built to centralise the limited",
 
172
                                        "PSI available to everyone. However, this made the existing",
 
173
                                        "reserves more vulnerable to malicious PSI users",
 
174
                                        "",
 
175
                                        "While other PSI users initially resented Merit for his rash",
 
176
                                        "behaviour, they eventually adjusted to the decentralisation.",
 
177
                                        "",
 
178
                                        "Eventually, PSI users grew so adept at manipulating the",
 
179
                                        "diluted flows of PSI that they were capable of the same things",
 
180
                                        "as before. Each PSI user would keep their own individual",
 
181
                                        "reserves of PSI for when they needed to weild greater power,",
 
182
                                        "and the balance of power was restored." };
 
183
                                        
 
184
char *STextV[15] = {"Merit decided to assume the role of custodian over the Orcus",
 
185
                                        "Dome, in Wervyn Anixil's place. He resumed the experiments on",
 
186
                                        "PSI and found ways of making the Dome's remaining supply go as",
 
187
                                        "far as it could.",
 
188
                                        "",
 
189
                                        "Other PSI users were suspicious of MERIT, just as they were",
 
190
                                        "wary of Wervyn Anixil before him, but they soon adjusted.",
 
191
                                        "",
 
192
                                        "The balance of power was quickly restored, and stabilised for",
 
193
                                        "eternity due to the work of Wervyn Anixil and now MERIT.",
 
194
                                        "",
 
195
                                        "",
 
196
                                        "                      [[ BEST ENDING ]]",
 
197
                                        "",
 
198
                                        ""};
 
199
 
 
200
void DrawSText(int t)
 
201
{
 
202
        int offset = 540 + (t / 2);
 
203
        int i, c;
 
204
        t = t * 350 / 500;
 
205
        int cl = 350 - t;
 
206
        
 
207
        for (i = 0; i < 64; i++) {
 
208
                DrawRect(0, i * 15 - offset, 640, 15, (64 - i) * cl / 350);
 
209
        }
 
210
        for (i = 64; i < 128; i++) {
 
211
                DrawRect(0, i * 15 - offset, 640, 15, (i - 64) * cl / 350);
 
212
        }
 
213
        
 
214
        if (t < 300) {
 
215
                for (i = 0; i < 15; i++) {
 
216
                        c = (255 + (i * 100) - t*10);
 
217
                        if (c < 0) c = 0;
 
218
                        if (c > 255) c = 255;
 
219
                        
 
220
                        draw_text(68, 150+i*12, SText[i], 255-c);
 
221
                }
 
222
        } else {
 
223
                for (i = 0; i < 15; i++) {
 
224
                        c = 5 + (t-300) * 5;
 
225
                        
 
226
                        draw_text(68, 150+i*12, SText[i], 255-c);
 
227
                }
 
228
        }
 
229
        
 
230
        UpdatePalette();
 
231
        VideoUpdate();
 
232
}
 
233
void DrawSTextV(int t)
 
234
{
 
235
        int offset = 540 + (t / 2);
 
236
        int i, c;
 
237
        t = t * 350 / 500;
 
238
        int cl = 350 - t;
 
239
        
 
240
        for (i = 0; i < 64; i++) {
 
241
                DrawRect(0, i * 15 - offset, 640, 15, (64 - i) * cl / 350);
 
242
        }
 
243
        for (i = 64; i < 128; i++) {
 
244
                DrawRect(0, i * 15 - offset, 640, 15, (i - 64) * cl / 350);
 
245
        }
 
246
        
 
247
        if (t < 300) {
 
248
                for (i = 0; i < 15; i++) {
 
249
                        c = (255 + (i * 100) - t*10);
 
250
                        if (c < 0) c = 0;
 
251
                        if (c > 255) c = 255;
 
252
                        
 
253
                        draw_text(68, 150+i*12, STextV[i], 255-c);
 
254
                }
 
255
        } else {
 
256
                for (i = 0; i < 15; i++) {
 
257
                        c = 5 + (t-300) * 5;
 
258
                        
 
259
                        draw_text(68, 150+i*12, STextV[i], 255-c);
 
260
                }
 
261
        }
 
262
        
 
263
        UpdatePalette();
 
264
        VideoUpdate();
 
265
}
 
266
 
 
267
 
 
268
float pt_x[500];
 
269
float pt_y[500];
 
270
float pt_vx[500];
 
271
float pt_vy[500];
 
272
int pt_t[500];
 
273
 
 
274
void InitParticleStorm()
 
275
{
 
276
        int i;
 
277
        
 
278
        for (i = 0; i < 500; i++) {
 
279
                pt_x[i] = 320;
 
280
                pt_y[i] = 960;
 
281
                pt_vx[i] = (float)(rand()%101) / 33.333 - 1.5;
 
282
                pt_vy[i] = (float)(rand()%101) / 10.0 - 16.1;
 
283
                pt_t[i] = rand()%100;
 
284
        }
 
285
}
 
286
 
 
287
char *credits[] = {
 
288
        "Concept:                    Lancer-X/Asceai",
 
289
        "Game design:                Lancer-X/Asceai",
 
290
        "Graphics:                   Lancer-X/Asceai",
 
291
        "Programming:                Lancer-X/Asceai",
 
292
        "Sound Effects:              Various (public domain) sources",
 
293
        "Music:                      Various artists",
 
294
        "Beta testing:               Quasar",
 
295
        "Beta testing:               Terryn",
 
296
        "Beta testing:               Wervyn"
 
297
         "\"Ambient Light\"       Vogue of Triton"
 
298
         "\"Battle of Ragnarok\"  Frostbite"
 
299
         "\"Dragon Cave\"         TICAZ"
 
300
         " cavern.xm             Unknown"
 
301
         "\"Caverns Boss\"        Alexis Janson"
 
302
         "\"Forest Boss\"         Alexis Janson"
 
303
         "\"Catacombs Boss\"      Alexis Janson"
 
304
         "\"Fear 2\"              Mick Rippon"
 
305
         "\"The Final Battle\"    Goose/Cļæ½DA & iNVASiON"
 
306
         "\"Ice Frontier\"        Skaven/FC"
 
307
         "\"KnarkLoader 1.0\"     Rapacious"
 
308
         "\"RPG-Battle\"          Cyn"
 
309
         "\"Metallic Forest\"     Joseph Fox"
 
310
};
 
311
 
 
312
void DrawCredits()
 
313
{
 
314
        static SDL_Surface *fin = NULL;
 
315
        static SDL_Surface *theend[2] = {NULL};
 
316
        SDL_Rect draw_to;
 
317
        int i;
 
318
        int ypos;
 
319
        int c;
 
320
        int n_credits = sizeof(credits)/sizeof(*credits);
 
321
        int finish_point;
 
322
        
 
323
        finish_point = 400 + (n_credits * 50);
 
324
        
 
325
        draw_to.x = 384;
 
326
        draw_to.y = 352;
 
327
        
 
328
        SDL_FillRect(screen, NULL, 0);
 
329
        
 
330
        if (fin == NULL) {
 
331
                fin = IMG_Load("dat/i/fin.png");
 
332
                
 
333
                theend[0] = IMG_Load("dat/i/theend.png");
 
334
                theend[1] = IMG_Load("dat/i/true_end.png");
 
335
        }
 
336
        
 
337
        if (credits_scroll >= (finish_point + 80)) {
 
338
                SDL_BlitSurface(theend[(player_shield == 30)], NULL, screen, NULL);
 
339
        } else {
 
340
                SDL_BlitSurface(fin, NULL, screen, &draw_to);
 
341
                
 
342
                // Show each line of credits
 
343
                
 
344
                for (i = 0; i < n_credits; i++) {
 
345
                        ypos = 800 + (i * 100) - credits_scroll * 2;
 
346
                        
 
347
                        if ((ypos >= 0)&&(ypos < 480)) {
 
348
                                c = 255 - abs(ypos - 240);
 
349
                                draw_text(120, ypos, credits[i], c);
 
350
                        }
 
351
                }
 
352
                
 
353
        }
 
354
        
 
355
        for (i = 0; i < 128; i++) {
 
356
                ending_pal[i].r = 0;
 
357
                ending_pal[i].g = i;
 
358
                ending_pal[i].b = i*2;
 
359
        }
 
360
        for (i = 128; i < 256; i++) {
 
361
                ending_pal[i].r = (i - 128)*2+1;
 
362
                ending_pal[i].g = i;
 
363
                ending_pal[i].b = 255;
 
364
        }
 
365
        
 
366
        // Dim palette if we're just starting
 
367
        
 
368
        if (credits_scroll < 80) {
 
369
                for (i = 0; i < 256; i++) {
 
370
                        ending_pal[i].r = ending_pal[i].r * credits_scroll / 80;
 
371
                        ending_pal[i].g = ending_pal[i].g * credits_scroll / 80;
 
372
                        ending_pal[i].b = ending_pal[i].b * credits_scroll / 80;
 
373
                }
 
374
        }
 
375
        
 
376
        // Also palette if we're finishing
 
377
        
 
378
        if ((credits_scroll >= (finish_point))&&(credits_scroll < (finish_point + 80))) {
 
379
                for (i = 0; i < 256; i++) {
 
380
                        ending_pal[i].r = ending_pal[i].r * (finish_point+80-credits_scroll) / 80;
 
381
                        ending_pal[i].g = ending_pal[i].g * (finish_point+80-credits_scroll) / 80;
 
382
                        ending_pal[i].b = ending_pal[i].b * (finish_point+80-credits_scroll) / 80;
 
383
                }
 
384
        }
 
385
        
 
386
        if ((credits_scroll >= (finish_point + 80))&&(credits_scroll < (finish_point + 160))) {
 
387
                for (i = 0; i < 256; i++) {
 
388
                        ending_pal[i].r = ending_pal[i].r * (credits_scroll - (finish_point + 80)) / 80;
 
389
                        ending_pal[i].g = ending_pal[i].g * (credits_scroll - (finish_point + 80)) / 80;
 
390
                        ending_pal[i].b = ending_pal[i].b * (credits_scroll - (finish_point + 80)) / 80;
 
391
                }
 
392
        }
 
393
        
 
394
        credits_scroll++;
 
395
        
 
396
        UpdatePalette();
 
397
        VideoUpdate();
 
398
}
 
399
 
 
400
void RunParticleStorm(int offset)
 
401
{
 
402
        SDL_Rect draw_from, draw_to;
 
403
        int i;
 
404
        
 
405
        for (i = 0; i < 64; i++) {
 
406
                DrawRect(0, i * 15 - offset, 640, 15, 64 - i);
 
407
        }
 
408
        
 
409
        for (i = 0; i < 500; i++) {
 
410
                if (pt_t[i] > 0) {
 
411
                        pt_t[i]--;
 
412
                } else {
 
413
                        pt_vy[i] += 0.1;
 
414
                        pt_x[i] += pt_vx[i];
 
415
                        pt_y[i] += pt_vy[i];
 
416
                }
 
417
                
 
418
                draw_from.x = (rand()%3)*32;
 
419
                draw_from.y = 0;
 
420
                draw_from.w = 32;
 
421
                draw_from.h = 32;
 
422
        
 
423
                draw_to.x = (int)pt_x[i] - 16;
 
424
                draw_to.y = (int)pt_y[i] - 16 - offset;
 
425
                SDL_BlitSurface(glitter, &draw_from, screen, &draw_to);
 
426
        }
 
427
 
 
428
        for (i = 0; i < 128; i++) {
 
429
                ending_pal[i].r = i*2;
 
430
                ending_pal[i].g = i*2;
 
431
                ending_pal[i].b = 0;
 
432
        }
 
433
        for (i = 128; i < 256; i++) {
 
434
                ending_pal[i].r = 255;
 
435
                ending_pal[i].g = 255;
 
436
                ending_pal[i].b = (i - 128)*2+1;
 
437
        }
 
438
        
 
439
        UpdatePalette();
 
440
        VideoUpdate();
 
441
}
 
442
 
 
443
void DrawStream(int t)
 
444
{
 
445
        int i;
 
446
        int scr_x = 32;
 
447
        int scr_y = 0;
 
448
        int strm_scrl;
 
449
        SDL_Rect draw_from, draw_to;
 
450
        
 
451
        for (i = 0; i < 256; i++) {
 
452
                ending_pal[i].r = i;
 
453
                ending_pal[i].g = (i * 7 / 8) + 16 + sin( (float)t / 8 )*16;
 
454
                ending_pal[i].b = (i * 3 / 4) + 32 + sin( (float)t / 8 )*32;
 
455
        }
 
456
        
 
457
 
 
458
        if (t >= 300) {
 
459
                scr_x = 32 + rand()%32 - rand()%32;
 
460
                scr_y = rand()%8;
 
461
        }
 
462
        
 
463
        if (t < 10) {
 
464
                scr_y = (20 - t * 2);
 
465
        }
 
466
        
 
467
        DrawLevel(scr_x, scr_y, 0, 0);
 
468
        DrawPlayer(344 - scr_x, 228 - scr_y, 0, 0);
 
469
        
 
470
        for (i = 0; i < 7; i++) {
 
471
                strm_scrl = (t * 20) % 128;
 
472
                draw_to.x = 0 - strm_scrl - scr_x + (128*i);
 
473
                draw_to.y = 19 - scr_y;
 
474
                
 
475
                if (i >= 300) {
 
476
                        draw_to.y += rand()%4;
 
477
                        draw_to.y -= rand()%4;
 
478
                }
 
479
                SDL_BlitSurface(streamspr, NULL, screen, &draw_to);
 
480
        }
 
481
        
 
482
        // glitter
 
483
        for (i = 0; i < 20; i++) {
 
484
                draw_from.x = (rand()%3)*32;
 
485
                draw_from.y = 0;
 
486
                draw_from.w = 32;
 
487
                draw_from.h = 32;
 
488
        
 
489
                draw_to.x = rand()%(640+32)-32;
 
490
                draw_to.y = (rand()%(124)) + 3;
 
491
                
 
492
                SDL_BlitSurface(glitter, &draw_from, screen, &draw_to);
 
493
        }
 
494
        
 
495
        if (t > 250) {
 
496
                if (t < 300) {
 
497
                        if (t == 251) {
 
498
                                SND_CircuitRelease(1000);
 
499
                        }
 
500
                        DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 254) * 10, 255);
 
501
                        DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 252) * 10, 225);
 
502
                        DrawCircle(320+32 - scr_x, 240 - scr_y, (t - 250) * 10, 195);
 
503
                }
 
504
        }
 
505
        
 
506
        UpdatePalette();
 
507
        VideoUpdate();
 
508
}
 
509
 
 
510
char *PText[10] = {     "Activating the seal quickly unblocked the ley lines and allowed",
 
511
                                        "PSI to flow through the Dome again. The remaining shadows were",
 
512
                                        "quickly flushed out.",
 
513
                                        "",
 
514
                                        "Wervyn Anixil's unconventional use of the PSI resulted in him",
 
515
                                        "being burned out and rendered powerless. Merit will see to it",
 
516
                                        "that he faces judgement for his crimes.",
 
517
                                        "",
 
518
                                        "Neither of the two PSI weapons housed within the Dome had been",
 
519
                                        "touched. However . . ." };
 
520
char *PTextV[10] ={     "Activating the seal quickly unblocked the ley lines and allowed",
 
521
                                        "PSI to flow through the Dome again. The remaining shadows were",
 
522
                                        "quickly flushed out.",
 
523
                                        "",
 
524
                                        "The traitor, who was never identified, perished in the Sealing.",
 
525
                                        "It soon became clear that the traitor had managed to betray and",
 
526
                                        "kill the real Wervyn Anixil during his experiments on the PSI.",
 
527
                                        "If the Agate Knife was never found, nobody would have been any",
 
528
                                        "the wiser, and things could have turned out very differently.",
 
529
                                        "However, there was one last thing for MERIT to do."};
 
530
 
 
531
void DrawPText(int t)
 
532
{
 
533
        int i;
 
534
        int c;
 
535
        
 
536
        int x, y;
 
537
        
 
538
        for (i = 0; i < 256; i++) {
 
539
                ending_pal[i].r = i;
 
540
                ending_pal[i].g = i;
 
541
                ending_pal[i].b = (i * 3 / 4) + 64;
 
542
        }
 
543
        
 
544
        if (t < 300) {
 
545
        
 
546
                for (i = 0; i < 10; i++) {
 
547
                        c = (255 + (i * 100) - t*10);
 
548
                        if (c < 0) c = 0;
 
549
                        if (c > 255) c = 255;
 
550
                        
 
551
                        if (player_shield != 30) {
 
552
                                draw_text(68, 180+i*12, PText[i], c);
 
553
                        } else {
 
554
                                draw_text(68, 180+i*12, PTextV[i], c);
 
555
                        }
 
556
                }
 
557
        } else {
 
558
                for (i = 0; i < 10; i++) {
 
559
                        c = 5 + (t-300) * 5;
 
560
                        
 
561
                        if (player_shield != 30) {
 
562
                                draw_text(68, 180+i*12, PText[i], c);
 
563
                        } else {
 
564
                                draw_text(68, 180+i*12, PTextV[i], c);
 
565
                        }
 
566
                }
 
567
        }
 
568
        
 
569
        for (i = 0; i < (32 * 8); i++) {
 
570
                x = (i % 32)*20;
 
571
                y = (i / 32)*20;
 
572
                
 
573
                c = 237 + (i/32*2) + (rand()% (19 - (i/32) *2));
 
574
                DrawRect(x, y, 20, 20, c);
 
575
                c = 237 + (i/32*2) + (rand()% (19 - (i/32) *2));
 
576
                DrawRect(x, 460 - y, 20, 20, c);
 
577
        }
 
578
        
 
579
        
 
580
        UpdatePalette();
 
581
        VideoUpdate();
 
582
}
 
583
 
 
584
void DrawScrolly(int t)
 
585
{
 
586
        int xp;
 
587
        int yp;
 
588
        int i, j;
 
589
        float a_dir;
 
590
        float v_radius;
 
591
        int all_blue = 0;
 
592
        SDL_Rect draw_from, draw_to;
 
593
        
 
594
        int x, y, r;
 
595
        
 
596
        float bright;
 
597
        
 
598
        if (t < 795) {
 
599
                xp = 8192 - 320 - 3180 + (t * 4);
 
600
                yp = t * 20;
 
601
        } else {
 
602
                xp = 8192 - 320 + ( (t-795) * 10);
 
603
                yp = 795 * 20 - (t-795)*10;
 
604
        }
 
605
        
 
606
        // Palette
 
607
        
 
608
        
 
609
        if ((rand() % 10)==9) {
 
610
                all_blue = 1;
 
611
        }
 
612
        for (i = 0; i < 256; i++) {
 
613
                bright = sin((float)t / 10.0) * 0.2 + 0.4;
 
614
                ending_pal[i].r = (i * bright + (256*(1.0-bright))) * ((float)(all_blue == 0) * 0.5 + 0.5);
 
615
                ending_pal[i].g = (i * bright + (256*(1.0-bright))) * ((float)(all_blue == 0) * 0.5 + 0.5);
 
616
                ending_pal[i].b = i * bright + (256*(1.0-bright));
 
617
        }
 
618
        DrawLevel(xp, yp, 0, 0);
 
619
        
 
620
        v_radius = sin((float)t / 10.0)*20 + 100;
 
621
        
 
622
        for (i = 0; i < 5; i++) {
 
623
                x = rand()%640;
 
624
                y = rand()%480;
 
625
                r = rand()%500+100;
 
626
                
 
627
                DrawCircleEx(x, y, r+2, r-4, 128);
 
628
                DrawCircleEx(x, y, r, r-2, 255);
 
629
        }
 
630
        
 
631
        for (i = 0; i < 4; i++) {
 
632
                draw_from.x = (8 + i) * 32;
 
633
                draw_from.y = 0;
 
634
                draw_from.w = 32;
 
635
                draw_from.h = 32;
 
636
                
 
637
                a_dir = ((float)t / 10.0) + (M_PI*(float)i/2);
 
638
                
 
639
                for (j = 10; j >= 0; j--) {
 
640
                        DrawCircleEx(320+cos(a_dir)*v_radius, 240+sin(a_dir)*v_radius, 22 + j * 2, 0, abs(j-3) * 15);
 
641
                }
 
642
                DrawCircleEx(320+cos(a_dir)*v_radius, 240+sin(a_dir)*v_radius, 20, 0, 0);
 
643
                
 
644
                draw_to.x = 320 + cos(a_dir) * v_radius - 16;
 
645
                draw_to.y = 240 + sin(a_dir) * v_radius - 16;
 
646
                SDL_BlitSurface(artifact_spr, &draw_from, screen, &draw_to);
 
647
        }
 
648
        
 
649
        UpdatePalette();
 
650
        VideoUpdate();
 
651
}
 
652
 
 
653
void DrawCircuitFlash(int t, int method)
 
654
{
 
655
        static SDL_Surface *circ = NULL;
 
656
        static int xpos, ypos;
 
657
        int i, j;
 
658
        SDL_Rect from;
 
659
        
 
660
        if (circ == NULL) {
 
661
                circ = IMG_Load("dat/i/circuits_1.png");
 
662
        }
 
663
        
 
664
        if (t == 0) {
 
665
                if (method == 0) {
 
666
                        xpos = rand()%641;
 
667
                        ypos = rand()%481;
 
668
                } else {
 
669
                        xpos = 320;
 
670
                        ypos = 240;
 
671
                }
 
672
        }
 
673
        
 
674
        from.x = xpos;
 
675
        from.y = ypos;
 
676
        from.w = 640;
 
677
        from.h = 480;
 
678
        
 
679
        SDL_BlitSurface(circ, &from, screen, NULL);
 
680
        
 
681
        for (i = 0; i < 256; i++) {
 
682
                if (method == 0) {
 
683
                        j = i * t / 4;
 
684
                } else {
 
685
                        j = i * t / 8;
 
686
                        if (t >= 20) {
 
687
                                j += t * 25;
 
688
                        }
 
689
                }
 
690
                
 
691
                if (j > 255) j = 255;
 
692
                ending_pal[i].r = j;
 
693
                ending_pal[i].g = j;
 
694
                ending_pal[i].b = j;
 
695
        }
 
696
        
 
697
        UpdatePalette();
 
698
        VideoUpdate();
 
699
}