4 Super Tux - Intro Screen
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - April 23, 2000
19 #include <SDL_image.h>
23 #include <sys/types.h>
34 char * intro_text[] = {
35 "Tux and Gown were having a nice picnic..",
37 "Gown is beamed away!!!",
38 "This looks like a job for ---"
47 texture_type bkgd, copter_squish, copter_stretch, beam,
48 gown_sit, gown_lookup, gown_upset,
49 tux_sit, tux_upset, tux_mad;
50 texture_type copter[2];
52 int done, i, quit, j, scene;
53 int * height, * height_speed;
57 /* Load sprite images: */
59 texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA);
60 texture_load(&gown_sit, DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA);
61 texture_load(&gown_lookup, DATA_PREFIX "/images/intro/gown-lookup.png", USE_ALPHA);
62 texture_load(&gown_upset, DATA_PREFIX "/images/intro/gown-upset.png", USE_ALPHA);
63 texture_load(&tux_sit, DATA_PREFIX "/images/intro/tux-sit.png", USE_ALPHA);
64 texture_load(&tux_upset, DATA_PREFIX "/images/intro/tux-upset.png", USE_ALPHA);
65 texture_load(&tux_mad, DATA_PREFIX "/images/intro/tux-mad.png", USE_ALPHA);
66 texture_load(&copter[0], DATA_PREFIX "/images/intro/copter1.png", USE_ALPHA);
67 texture_load(&copter[1], DATA_PREFIX "/images/intro/copter2.png", USE_ALPHA);
68 texture_load(&copter_squish, DATA_PREFIX "/images/intro/copter-squish.png", USE_ALPHA);
69 texture_load(&copter_stretch, DATA_PREFIX "/images/intro/copter-stretch.png", USE_ALPHA);
70 texture_load(&beam, DATA_PREFIX "/images/intro/beam.png", USE_ALPHA);
72 /* Allocate buffer for height array: */
74 height = malloc(sizeof(int) * (gown_upset.w));
75 height_speed = malloc(sizeof(int) * (gown_upset.w));
78 /* Initialize height arrays: */
80 for (j = 0; j < (gown_upset.w); j++)
83 height_speed[j] = (rand() % 10) + 1;
86 /* Display background: */
88 texture_draw_bg(&bkgd, UPDATE);
97 timer_start(&timer,10000);
99 while (timer_check(&timer) && !done && !quit)
104 while (SDL_PollEvent(&event))
106 if (event.type == SDL_QUIT)
108 /* Quit event - quit: */
112 else if (event.type == SDL_KEYDOWN)
114 /* Keypress - skip intro: */
119 else if (event.type == SDL_JOYBUTTONDOWN)
121 /* Fire button - skip intro: */
129 /* Display background: */
133 if (timer_get_gone(&timer) < 2000 && scene == 0)
136 /* Gown and tux sitting: */
138 texture_draw(&tux_sit, 270, 400, UPDATE);
139 texture_draw(&gown_sit, 320, 400, UPDATE);
141 drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE, 1);
145 if (timer_get_gone(&timer) >= 2000 && scene == 1)
148 /* Helicopter begins to fly in: */
150 erasecenteredtext(intro_text[0], 456, bkgd.sdl_surface, NO_UPDATE, 1);
151 drawcenteredtext(intro_text[1], 456, letters_red, NO_UPDATE, 1);
155 if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000)
157 /* Helicopter flying in: */
158 texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
160 texture_draw(&copter[i % 2],
161 (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32,
164 update_rect(screen, 0, 32, screen->w, (copter[0].h));
168 if (timer_get_gone(&timer) >= 2500 && scene == 2)
171 /* Gown notices something... */
173 texture_draw(&gown_lookup, 320, 400, UPDATE);
177 if (timer_get_gone(&timer) >= 3500 && scene == 3)
180 /* Gown realizes it's bad! */
182 texture_draw(&gown_upset, 320, 400, UPDATE);
186 if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000)
188 /* Helicopter sits: */
189 texture_draw_part(&bkgd, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
191 texture_draw(&copter[i % 2], 400 - (copter[0].w), 32, NO_UPDATE);
192 update_rect(screen, 0, 32, screen->w, (copter[0].h));
196 if (timer_get_gone(&timer) >= 5000 && scene == 4)
199 /* Tux realizes something's happening: */
201 texture_draw(&tux_upset, 270, 400, UPDATE);
204 erasecenteredtext(intro_text[1], 456, bkgd.sdl_surface, UPDATE, 1);
205 drawcenteredtext(intro_text[2], 456, letters_red, UPDATE, 1);
209 if (timer_get_gone(&timer) >= 5000)
213 texture_draw_part(&bkgd,
217 368 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
220 for (j = 0; j < (gown_upset.sdl_surface -> w); j++)
222 texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j],
228 src.h = (gown_upset.h);
235 SDL_BlitSurface(gown_upset.sdl_surface, &src, screen, &dest);
237 height[j] = height[j] - height_speed[j];
247 400 + (gown_upset.h) - (copter[0].h));
251 if (timer_get_gone(&timer) >= 8000 && scene == 5)
256 texture_draw(&tux_mad, 270, 400, UPDATE);
258 erasecenteredtext(intro_text[2], 456, bkgd.sdl_surface, UPDATE, 1);
259 drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE, 1);
263 if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250)
265 /* Helicopter starting to speed off: */
267 texture_draw_part(&bkgd, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
269 texture_draw(&copter_squish,
270 400 - (copter[0].w), 32,
273 update_rect(screen, 0, 32, screen->w, (copter_squish.h));
277 if (timer_get_gone(&timer) >= 8250)
279 /* Helicopter speeding off: */
281 texture_draw_part(&bkgd, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
283 texture_draw(&copter_stretch,
284 (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w),
288 update_rect(screen, 0, 32, screen->w, (copter_stretch.h));
302 texture_free(&gown_sit);
303 texture_free(&gown_lookup);
304 texture_free(&gown_upset);
305 texture_free(&tux_sit);
306 texture_free(&tux_upset);
307 texture_free(&tux_mad);
308 texture_free(&copter[0]);
309 texture_free(&copter[1]);
310 texture_free(&copter_squish);
311 texture_free(&copter_stretch);
315 /* Free array buffers: */
321 /* Return to main! */