1 #include "sparkles.h"
2 #include "display_subsystem.h"
3 #include "globals.h"
4 #include "engine_exhaust.h"
5 #include "mood_item.h"
6 #include "sound.h"
7 #include <math.h>
8
9 #define END_LEVEL_MARGIN 0.98
10
11 /*! \brief Draw the black infinity of space
12 *
13 * The space, the final frontier....
14 */
draw_infinite_black()15 void draw_infinite_black() {
16 float t;
17 float l = level - floorf(level);
18 Uint32 c = 0;
19
20 if((l > END_LEVEL_MARGIN) && (state == GAME_PLAY)) {
21 t = 4 * (1 - (1 - l) / (1 - END_LEVEL_MARGIN));
22 if(last_levelup_snd < level) {
23 last_levelup_snd = ceilf(level);
24 play_sound(4);
25 }
26 switch ((int) t) {
27 case 0:
28 // ramp up red
29 c = SDL_MapRGB(surf_screen->format, (int) (255 * t), 0, 0);
30 break;
31 case 1:
32 // ramp down red, ramp up green
33 c = SDL_MapRGB(surf_screen->format, (int) (255 * (1 - t)), (int) (255 * (t - 1)), 0);
34 break;
35 case 2:
36 // ramp down green, ramp up blue
37 c = SDL_MapRGB(surf_screen->format, 0, (int) (255 * (3 - t)), (int) (255 * (t - 3)));
38 break;
39 case 3:
40 // ramp down blue
41 c = SDL_MapRGB(surf_screen->format, 0, 0, (int) (255 * (4 - t)));
42 break;
43 }
44 }
45 SDL_FillRect(surf_screen, NULL, c);
46 }
47
48
draw_ghostly_rock_dodger(SDL_Surface * surf_t_rock,SDL_Surface * surf_t_dodger)49 void draw_ghostly_rock_dodger(SDL_Surface *surf_t_rock, SDL_Surface *surf_t_dodger) {
50 SDL_Rect src, dest;
51
52 src.w = surf_t_rock->w;
53 src.h = surf_t_rock->h;
54 src.x = 0;
55 src.y = 0;
56 dest.w = src.w;
57 dest.h = src.h;
58 dest.x = (xsize - src.w) / 2 + cosf(fadetimer / 6.5) * 10;
59 dest.y = (ysize / 2 - src.h) / 2 + sinf(fadetimer / 5) * 10;
60 SDL_SetAlpha(surf_t_rock, SDL_SRCALPHA, (int) (170 + 85 * sinf(fadetimer)));
61 SDL_BlitSurface(surf_t_rock, &src, surf_screen, &dest);
62 src.w = surf_t_dodger->w;
63 src.h = surf_t_dodger->h;
64 dest.w = src.w;
65 dest.h = src.h;
66 dest.x = (xsize - src.w) / 2 + sinf(fadetimer / 6.5) * 10;
67 dest.y =
68 (ysize / 2 - src.h) / 2 + surf_t_rock->h + 20 +
69 sinf((fadetimer + 1) / 5) * 10;
70 SDL_SetAlpha(surf_t_dodger, SDL_SRCALPHA,
71 (int) (170 + 85 * sinf(fadetimer - 1.0)));
72 SDL_BlitSurface(surf_t_dodger, &src, surf_screen, &dest);
73 }
74
75
drawdots(SDL_Surface * s)76 void drawdots(SDL_Surface * s) {
77 // Draw the background stars (aka space dots - they can't possibly be stars
78 // because then we'd be moving past them at something like 10,000 times the
79 // speed of light)
80 draw_space_dots(current_spacedot_engine, s);
81 // Draw the mood item...
82 draw_mood_item(s);
83 // Draw all the engine dots
84 SDL_LockSurface(s);
85 draw_engine_dots(s);
86 // Draw all outstanding bang dots and plumes
87 draw_sparkles(s);
88 SDL_UnlockSurface(s);
89 }
90
91
draw_background_objects()92 void draw_background_objects() {
93 // Draw a fully black background
94 draw_infinite_black();
95 // Draw the background dots
96 drawdots(surf_screen);
97 }
98
99