4 Super Tux - Intro Screen
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - March 15, 2004
19 #include <SDL_image.h>
22 #include <sys/types.h>
33 char * intro_text[] = {
34 "Tux and Gown were having a nice picnic..",
36 "Gown is beamed away!!!",
37 "This looks like a job for ---"
46 texture_type bkgd, copter_squish, copter_stretch, beam,
47 gown_sit, gown_lookup, gown_upset,
48 tux_sit, tux_upset, tux_mad;
49 texture_type copter[2];
51 int done, i, quit, j, scene;
52 int * height, * height_speed;
55 /* Load sprite images: */
56 texture_load(&bkgd, datadir + "/images/intro/intro.png", IGNORE_ALPHA);
57 texture_load(&gown_sit, datadir + "/images/intro/gown-sit.png", USE_ALPHA);
58 texture_load(&gown_lookup, datadir + "/images/intro/gown-lookup.png", USE_ALPHA);
59 texture_load(&gown_upset, datadir + "/images/intro/gown-upset.png", USE_ALPHA);
60 texture_load(&tux_sit, datadir + "/images/intro/tux-sit.png", USE_ALPHA);
61 texture_load(&tux_upset, datadir + "/images/intro/tux-upset.png", USE_ALPHA);
62 texture_load(&tux_mad, datadir + "/images/intro/tux-mad.png", USE_ALPHA);
63 texture_load(&copter[0], datadir + "/images/intro/copter1.png", USE_ALPHA);
64 texture_load(&copter[1], datadir + "/images/intro/copter2.png", USE_ALPHA);
65 texture_load(&copter_squish, datadir + "/images/intro/copter-squish.png", USE_ALPHA);
66 texture_load(&copter_stretch, datadir + "/images/intro/copter-stretch.png", USE_ALPHA);
67 texture_load(&beam, datadir + "/images/intro/beam.png", USE_ALPHA);
69 /* Allocate buffer for height array: */
71 height = (int*) malloc(sizeof(int) * (gown_upset.w));
72 height_speed = (int*) malloc(sizeof(int) * (gown_upset.w));
75 /* Initialize height arrays: */
77 for (j = 0; j < (gown_upset.w); j++)
80 height_speed[j] = (rand() % 10) + 1;
83 /* Display background: */
85 texture_draw_bg(&bkgd, UPDATE);
94 timer_init(&timer,NO);
95 timer_start(&timer,10000);
97 while (timer_check(&timer) && !done && !quit)
102 while (SDL_PollEvent(&event))
104 if (event.type == SDL_QUIT)
106 /* Quit event - quit: */
110 else if (event.type == SDL_KEYDOWN)
112 /* Keypress - skip intro: */
116 else if (event.type == SDL_JOYBUTTONDOWN)
118 /* Fire button - skip intro: */
125 /* Display background: */
129 if (timer_get_gone(&timer) < 2000 && scene == 0)
132 /* Gown and tux sitting: */
134 texture_draw(&tux_sit, 270, 400, UPDATE);
135 texture_draw(&gown_sit, 320, 400, UPDATE);
137 text_drawf(&white_text, intro_text[0], 0, -8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
141 if (timer_get_gone(&timer) >= 2000 && scene == 1)
144 /* Helicopter begins to fly in: */
146 erasecenteredtext(&white_text, intro_text[0], 454, &bkgd, NO_UPDATE, 1);
147 text_drawf(&white_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
151 if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000)
153 /* Helicopter flying in: */
154 texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
156 texture_draw(&copter[i % 2],
157 (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32,
160 update_rect(screen, 0, 32, screen->w, (copter[0].h));
164 if (timer_get_gone(&timer) >= 2500 && scene == 2)
167 /* Gown notices something... */
169 texture_draw(&gown_lookup, 320, 400, UPDATE);
173 if (timer_get_gone(&timer) >= 3500 && scene == 3)
176 /* Gown realizes it's bad! */
178 texture_draw(&gown_upset, 320, 400, UPDATE);
182 if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000)
184 /* Helicopter sits: */
185 texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h), NO_UPDATE);
187 texture_draw(&copter[i % 2], 400 - (copter[0].w), 32, NO_UPDATE);
188 update_rect(screen, 0, 32, screen->w, (copter[0].h));
192 if (timer_get_gone(&timer) >= 5000 && scene == 4)
195 /* Tux realizes something's happening: */
197 texture_draw(&tux_upset, 270, 400, UPDATE);
200 erasecenteredtext(&white_text, intro_text[1], 454, &bkgd, UPDATE, 1);
201 text_drawf(&white_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
205 if (timer_get_gone(&timer) >= 5000 && timer_get_gone(&timer) <= 8000)
209 texture_draw_part(&bkgd,
210 310, 32 + (copter[0].h), 310,
213 376 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
216 for (j = 0; j < (gown_upset.sdl_surface -> w); j++)
218 texture_draw(&beam, 320 + j - ((beam.w) / 2), height[j],
224 src.h = (gown_upset.h);
231 texture_draw_part(&gown_upset,src.x,src.y,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
233 height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer_get_gone(&timer) - 5000)/(float)3000.));
242 400 + (gown_upset.h) - (copter[0].h));
246 if (timer_get_gone(&timer) >= 8000 && scene == 5)
248 texture_draw_part(&bkgd,
249 310, 32 + (copter[0].h), 310,
252 368 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
257 texture_draw(&tux_mad, 270, 400, UPDATE);
259 erasecenteredtext(&white_text, intro_text[2], 454, &bkgd, UPDATE, 1);
260 text_drawf(&white_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
264 if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250)
266 /* Helicopter starting to speed off: */
268 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
270 texture_draw(&copter_squish,
271 400 - (copter[0].w), 32,
274 update_rect(screen, 0, 32, screen->w, (copter_squish.h));
278 if (timer_get_gone(&timer) >= 8250)
280 /* Helicopter speeding off: */
282 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
284 texture_draw(&copter_stretch,
285 (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w),
289 update_rect(screen, 0, 32, screen->w, (copter_stretch.h));
303 texture_free(&gown_sit);
304 texture_free(&gown_lookup);
305 texture_free(&gown_upset);
306 texture_free(&tux_sit);
307 texture_free(&tux_upset);
308 texture_free(&tux_mad);
309 texture_free(&copter[0]);
310 texture_free(&copter[1]);
311 texture_free(&copter_squish);
312 texture_free(&copter_stretch);
316 /* Free array buffers: */
322 /* Return to main! */