4 Super Tux - Intro Screen
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - February 1st, 2004
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: */
58 texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA);
59 texture_load(&gown_sit, DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA);
60 texture_load(&gown_lookup, DATA_PREFIX "/images/intro/gown-lookup.png", USE_ALPHA);
61 texture_load(&gown_upset, DATA_PREFIX "/images/intro/gown-upset.png", USE_ALPHA);
62 texture_load(&tux_sit, DATA_PREFIX "/images/intro/tux-sit.png", USE_ALPHA);
63 texture_load(&tux_upset, DATA_PREFIX "/images/intro/tux-upset.png", USE_ALPHA);
64 texture_load(&tux_mad, DATA_PREFIX "/images/intro/tux-mad.png", USE_ALPHA);
65 texture_load(&copter[0], DATA_PREFIX "/images/intro/copter1.png", USE_ALPHA);
66 texture_load(&copter[1], DATA_PREFIX "/images/intro/copter2.png", USE_ALPHA);
67 texture_load(&copter_squish, DATA_PREFIX "/images/intro/copter-squish.png", USE_ALPHA);
68 texture_load(&copter_stretch, DATA_PREFIX "/images/intro/copter-stretch.png", USE_ALPHA);
69 texture_load(&beam, DATA_PREFIX "/images/intro/beam.png", USE_ALPHA);
71 /* Allocate buffer for height array: */
73 height = malloc(sizeof(int) * (gown_upset.w));
74 height_speed = malloc(sizeof(int) * (gown_upset.w));
77 /* Initialize height arrays: */
79 for (j = 0; j < (gown_upset.w); j++)
82 height_speed[j] = (rand() % 10) + 1;
85 /* Display background: */
87 texture_draw_bg(&bkgd, UPDATE);
96 timer_start(&timer,10000);
98 while (timer_check(&timer) && !done && !quit)
103 while (SDL_PollEvent(&event))
105 if (event.type == SDL_QUIT)
107 /* Quit event - quit: */
111 else if (event.type == SDL_KEYDOWN)
113 /* Keypress - skip intro: */
118 else if (event.type == SDL_JOYBUTTONDOWN)
120 /* Fire button - skip intro: */
128 /* Display background: */
132 if (timer_get_gone(&timer) < 2000 && scene == 0)
135 /* Gown and tux sitting: */
137 texture_draw(&tux_sit, 270, 400, UPDATE);
138 texture_draw(&gown_sit, 320, 400, UPDATE);
140 text_drawf(&blue_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
144 if (timer_get_gone(&timer) >= 2000 && scene == 1)
147 /* Helicopter begins to fly in: */
149 erasecenteredtext(intro_text[0], 456, &bkgd, NO_UPDATE, 1);
150 text_drawf(&blue_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
154 if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000)
156 /* Helicopter flying in: */
157 texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
159 texture_draw(&copter[i % 2],
160 (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32,
163 update_rect(screen, 0, 32, screen->w, (copter[0].h));
167 if (timer_get_gone(&timer) >= 2500 && scene == 2)
170 /* Gown notices something... */
172 texture_draw(&gown_lookup, 320, 400, UPDATE);
176 if (timer_get_gone(&timer) >= 3500 && scene == 3)
179 /* Gown realizes it's bad! */
181 texture_draw(&gown_upset, 320, 400, UPDATE);
185 if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000)
187 /* Helicopter sits: */
188 texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
190 texture_draw(&copter[i % 2], 400 - (copter[0].w), 32, NO_UPDATE);
191 update_rect(screen, 0, 32, screen->w, (copter[0].h));
195 if (timer_get_gone(&timer) >= 5000 && scene == 4)
198 /* Tux realizes something's happening: */
200 texture_draw(&tux_upset, 270, 400, UPDATE);
203 erasecenteredtext(intro_text[1], 456, &bkgd, UPDATE, 1);
204 text_drawf(&blue_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
208 if (timer_get_gone(&timer) >= 5000)
212 texture_draw_part(&bkgd,
213 320, 32 + (copter[0].h), 320,
216 368 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
219 for (j = 0; j < (gown_upset.sdl_surface -> w); j++)
221 texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j],
227 src.h = (gown_upset.h);
234 SDL_BlitSurface(gown_upset.sdl_surface, &src, screen, &dest);
236 height[j] = height[j] - height_speed[j];
246 400 + (gown_upset.h) - (copter[0].h));
250 if (timer_get_gone(&timer) >= 8000 && scene == 5)
255 texture_draw(&tux_mad, 270, 400, UPDATE);
257 erasecenteredtext(intro_text[2], 456, &bkgd, UPDATE, 1);
258 text_drawf(&blue_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
262 if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250)
264 /* Helicopter starting to speed off: */
266 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
268 texture_draw(&copter_squish,
269 400 - (copter[0].w), 32,
272 update_rect(screen, 0, 32, screen->w, (copter_squish.h));
276 if (timer_get_gone(&timer) >= 8250)
278 /* Helicopter speeding off: */
280 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
282 texture_draw(&copter_stretch,
283 (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w),
287 update_rect(screen, 0, 32, screen->w, (copter_stretch.h));
301 texture_free(&gown_sit);
302 texture_free(&gown_lookup);
303 texture_free(&gown_upset);
304 texture_free(&tux_sit);
305 texture_free(&tux_upset);
306 texture_free(&tux_mad);
307 texture_free(&copter[0]);
308 texture_free(&copter[1]);
309 texture_free(&copter_squish);
310 texture_free(&copter_stretch);
314 /* Free array buffers: */
320 /* Return to main! */