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>
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 SDL_Surface * bkgd, * copter_squish, * copter_stretch, * beam,
47 * gown_sit, * gown_lookup, * gown_upset,
48 * tux_sit, * tux_upset, * tux_mad;
49 SDL_Surface * copter[2];
52 int * height, * height_speed;
55 /* Load sprite images: */
57 bkgd = load_image(DATA_PREFIX "/images/intro/intro.png", IGNORE_ALPHA);
59 gown_sit = load_image(DATA_PREFIX "/images/intro/gown-sit.png", USE_ALPHA);
60 gown_lookup = load_image(DATA_PREFIX "/images/intro/gown-lookup.png",
62 gown_upset = load_image(DATA_PREFIX "/images/intro/gown-upset.png",
65 tux_sit = load_image(DATA_PREFIX "/images/intro/tux-sit.png", USE_ALPHA);
66 tux_upset = load_image(DATA_PREFIX "/images/intro/tux-upset.png",
68 tux_mad = load_image(DATA_PREFIX "/images/intro/tux-mad.png", USE_ALPHA);
70 copter[0] = load_image(DATA_PREFIX "/images/intro/copter1.png", USE_ALPHA);
71 copter[1] = load_image(DATA_PREFIX "/images/intro/copter2.png", USE_ALPHA);
73 copter_squish = load_image(DATA_PREFIX "/images/intro/copter-squish.png",
75 copter_stretch = load_image(DATA_PREFIX "/images/intro/copter-stretch.png",
78 beam = load_image(DATA_PREFIX "/images/intro/beam.png", USE_ALPHA);
81 /* Allocate buffer for height array: */
83 height = malloc(sizeof(int) * (gown_upset -> w));
84 height_speed = malloc(sizeof(int) * (gown_upset -> w));
87 /* Initialize height arrays: */
89 for (j = 0; j < (gown_upset -> w); j++)
92 height_speed[j] = (rand() % 10) + 1;
96 /* Display background: */
98 drawimage(bkgd, 0, 0, UPDATE);
106 for (i = 0; i < (10000 / FPS) && !done && !quit; i++)
110 while (SDL_PollEvent(&event))
112 if (event.type == SDL_QUIT)
114 /* Quit event - quit: */
118 else if (event.type == SDL_KEYDOWN)
120 /* Keypress - skip intro: */
125 else if (event.type == SDL_JOYBUTTONDOWN)
127 /* Fire button - skip intro: */
139 /* Gown and tux sitting: */
141 drawimage(tux_sit, 270, 400, UPDATE);
142 drawimage(gown_sit, 320, 400, UPDATE);
144 drawcenteredtext(intro_text[0], 456, letters_blue, UPDATE, 1);
148 if (i == (2000 / FPS))
150 /* Helicopter begins to fly in: */
152 erasecenteredtext(intro_text[0], 456, bkgd, UPDATE, 1);
153 drawcenteredtext(intro_text[1], 456, letters_red, UPDATE, 1);
157 if (i > (2000 / FPS) && i < (4000 / FPS))
159 /* Helicopter flying in: */
161 drawpart(bkgd, 0, 32, 640, (copter[0] -> h), NO_UPDATE);
163 drawimage(copter[i % 2],
164 (i - (2000 / FPS)) * (FPS / 5) - (copter[0] -> w), 32,
167 SDL_UpdateRect(screen, 0, 32, 640, (copter[0] -> h));
171 if (i == (2500 / FPS))
173 /* Gown notices something... */
175 drawimage(gown_lookup, 320, 400, UPDATE);
179 if (i == (3500 / FPS))
181 /* Gown realizes it's bad! */
183 drawimage(gown_upset, 320, 400, UPDATE);
187 if (i > (4000 / FPS) && i < (8000 / FPS))
189 /* Helicopter sits: */
191 drawpart(bkgd, 0, 32, 640, (copter[0] -> h), NO_UPDATE);
193 drawimage(copter[i % 2], 400 - (copter[0] -> w), 32, NO_UPDATE);
195 SDL_UpdateRect(screen, 0, 32, 640, (copter[0] -> h));
199 if (i == (5000 / FPS))
201 /* Tux realizes something's happening: */
203 drawimage(tux_upset, 270, 400, UPDATE);
206 erasecenteredtext(intro_text[1], 456, bkgd, UPDATE, 1);
207 drawcenteredtext(intro_text[2], 456, letters_red, UPDATE, 1);
211 if (i > (5000 / FPS))
217 32 + (copter[0] -> h),
219 368 + (gown_upset -> h) - (copter[0] -> h), NO_UPDATE);
222 for (j = 0; j < (gown_upset -> w); j++)
224 drawimage(beam, 320 + j - ((beam -> w) / 2), height[j],
230 src.h = (gown_upset -> h);
237 SDL_BlitSurface(gown_upset, &src, screen, &dest);
239 height[j] = height[j] - height_speed[j];
245 SDL_UpdateRect(screen,
247 32 + (copter[0] -> h),
249 400 + (gown_upset -> h) - (copter[0] -> h));
253 if (i == (8000 / FPS))
257 drawimage(tux_mad, 270, 400, UPDATE);
259 erasecenteredtext(intro_text[2], 456, bkgd, UPDATE, 1);
260 drawcenteredtext(intro_text[3], 456, letters_gold, UPDATE, 1);
264 if (i > (8000 / FPS) && i < (8250 / FPS))
266 /* Helicopter starting to speed off: */
268 drawpart(bkgd, 0, 32, 640, (copter_squish -> h), NO_UPDATE);
270 drawimage(copter_squish,
271 400 - (copter[0] -> w), 32,
274 SDL_UpdateRect(screen, 0, 32, 640, (copter_squish -> h));
278 if (i > (8250 / FPS))
280 /* Helicopter speeding off: */
282 drawpart(bkgd, 0, 32, 640, (copter_stretch -> h), NO_UPDATE);
284 drawimage(copter_stretch,
285 (i - (8250 / FPS)) * 30 + 400 - (copter[0] -> w),
289 SDL_UpdateRect(screen, 0, 32, 640, (copter_stretch -> h));
300 SDL_FreeSurface(bkgd);
302 SDL_FreeSurface(gown_sit);
303 SDL_FreeSurface(gown_lookup);
304 SDL_FreeSurface(gown_upset);
306 SDL_FreeSurface(tux_sit);
307 SDL_FreeSurface(tux_upset);
308 SDL_FreeSurface(tux_mad);
310 SDL_FreeSurface(copter[0]);
311 SDL_FreeSurface(copter[1]);
313 SDL_FreeSurface(copter_squish);
314 SDL_FreeSurface(copter_stretch);
316 SDL_FreeSurface(beam);
319 /* Free array buffers: */
325 /* Return to main! */