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>
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;
56 /* Load sprite images: */
57 texture_load(&bkgd, DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA);
58 texture_load(&gown_sit, DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA);
59 texture_load(&gown_lookup, DATA_PREFIX "/images/intro/gown-lookup.png", USE_ALPHA);
60 texture_load(&gown_upset, DATA_PREFIX "/images/intro/gown-upset.png", USE_ALPHA);
61 texture_load(&tux_sit, DATA_PREFIX "/images/intro/tux-sit.png", USE_ALPHA);
62 texture_load(&tux_upset, DATA_PREFIX "/images/intro/tux-upset.png", USE_ALPHA);
63 texture_load(&tux_mad, DATA_PREFIX "/images/intro/tux-mad.png", USE_ALPHA);
64 texture_load(&copter[0], DATA_PREFIX "/images/intro/copter1.png", USE_ALPHA);
65 texture_load(&copter[1], DATA_PREFIX "/images/intro/copter2.png", USE_ALPHA);
66 texture_load(&copter_squish, DATA_PREFIX "/images/intro/copter-squish.png", USE_ALPHA);
67 texture_load(&copter_stretch, DATA_PREFIX "/images/intro/copter-stretch.png", USE_ALPHA);
68 texture_load(&beam, DATA_PREFIX "/images/intro/beam.png", USE_ALPHA);
70 /* Allocate buffer for height array: */
72 height = (int*) malloc(sizeof(int) * (gown_upset.w));
73 height_speed = (int*) malloc(sizeof(int) * (gown_upset.w));
76 /* Initialize height arrays: */
78 for (j = 0; j < (gown_upset.w); j++)
81 height_speed[j] = (rand() % 10) + 1;
84 /* Display background: */
86 texture_draw_bg(&bkgd, UPDATE);
95 timer_init(&timer,NO);
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(&white_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(&white_text, intro_text[0], 454, &bkgd, NO_UPDATE, 1);
150 text_drawf(&white_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(&white_text, intro_text[1], 454, &bkgd, UPDATE, 1);
204 text_drawf(&white_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
208 if (timer_get_gone(&timer) >= 5000 && timer_get_gone(&timer) <= 8000)
212 texture_draw_part(&bkgd,
213 310, 32 + (copter[0].h), 310,
216 376 + (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 texture_draw_part(&gown_upset,src.x,src.y,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
236 height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer_get_gone(&timer) - 5000)/(float)3000.));
245 400 + (gown_upset.h) - (copter[0].h));
249 if (timer_get_gone(&timer) >= 8000 && scene == 5)
251 texture_draw_part(&bkgd,
252 310, 32 + (copter[0].h), 310,
255 368 + (gown_upset.h) - (copter[0].h), NO_UPDATE);
260 texture_draw(&tux_mad, 270, 400, UPDATE);
262 erasecenteredtext(&white_text, intro_text[2], 454, &bkgd, UPDATE, 1);
263 text_drawf(&white_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE);
267 if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250)
269 /* Helicopter starting to speed off: */
271 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_squish.h), NO_UPDATE);
273 texture_draw(&copter_squish,
274 400 - (copter[0].w), 32,
277 update_rect(screen, 0, 32, screen->w, (copter_squish.h));
281 if (timer_get_gone(&timer) >= 8250)
283 /* Helicopter speeding off: */
285 texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h), NO_UPDATE);
287 texture_draw(&copter_stretch,
288 (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w),
292 update_rect(screen, 0, 32, screen->w, (copter_stretch.h));
306 texture_free(&gown_sit);
307 texture_free(&gown_lookup);
308 texture_free(&gown_upset);
309 texture_free(&tux_sit);
310 texture_free(&tux_upset);
311 texture_free(&tux_mad);
312 texture_free(&copter[0]);
313 texture_free(&copter[1]);
314 texture_free(&copter_squish);
315 texture_free(&copter_stretch);
319 /* Free array buffers: */
325 /* Return to main! */