4 Super Tux - Title Screen
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - December 29, 2003
19 #include <SDL_image.h>
23 #include <sys/types.h>
31 #include "high_scores.h"
38 #include "leveleditor.h"
40 texture_type bkg_title, img_choose_subset, anim1, anim2;
43 int quit, frame, pict, i;
45 void display_credits();
47 void draw_background()
49 /* Draw the title background: */
51 texture_draw_bg(&bkg_title, NO_UPDATE);
53 /* Animate title screen: */
55 pict = (frame / 5) % 3;
58 texture_draw_part(&bkg_title, 560, 270, 560, 270, 80, 75, NO_UPDATE);
60 texture_draw(&anim1, 560, 270, NO_UPDATE);
62 texture_draw(&anim2, 560, 270, NO_UPDATE);
65 /* --- TITLE SCREEN --- */
71 string_list_type level_subsets;
72 level_subsets = dsubdirs("/levels", "info");
76 /* Reset menu variables */
78 menu_set_current(&main_menu);
85 texture_load(&bkg_title,DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA);
86 texture_load(&anim1,DATA_PREFIX "/images/title/title-anim2.png", IGNORE_ALPHA);
87 texture_load(&anim2,DATA_PREFIX "/images/title/title-anim1.png", IGNORE_ALPHA);
88 texture_load(&img_choose_subset,DATA_PREFIX "/images/status/choose-level-subset.png", USE_ALPHA);
90 /* --- Main title loop: --- */
97 /* Draw the title background: */
98 texture_draw_bg(&bkg_title, NO_UPDATE);
102 while (!done && !quit)
106 while (SDL_PollEvent(&event))
108 if (event.type == SDL_QUIT)
110 /* Quit event - quit: */
113 else if (event.type == SDL_KEYDOWN)
117 key = event.key.keysym.sym;
119 /* Check for menu events */
120 menu_event(&event.key.keysym);
122 if (key == SDLK_ESCAPE)
130 else if (event.type == SDL_JOYAXISMOTION && event.jaxis.axis == JOY_Y)
132 if (event.jaxis.value > 1024)
133 menuaction = MN_DOWN;
134 else if (event.jaxis.value < -1024)
137 else if (event.type == SDL_JOYBUTTONDOWN)
139 /* Joystick button: Continue: */
147 /* Draw the background: */
150 /* Draw the high score: */
151 sprintf(str, "High score: %d", hs_score);
152 text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
153 sprintf(str, "by %s", hs_name);
154 text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
156 /* Don't draw menu, if quit is true */
157 if(show_menu && !quit)
158 menu_process_current();
160 if(current_menu == &main_menu)
162 switch (menu_check(&main_menu))
167 if(level_subsets.num_items != 0)
169 subset_load(&subset,level_subsets.item[0]);
172 texture_draw(&img_choose_subset,(screen->w - img_choose_subset.w) / 2, 0, NO_UPDATE);
173 if(level_subsets.num_items != 0)
175 texture_draw(&subset.image,(screen->w - subset.image.w) / 2 + 25,78,NO_UPDATE);
176 if(level_subsets.num_items > 1)
179 texture_draw(&arrow_left,(screen->w / 2) - ((strlen(subset.title)+2)*16)/2,20,NO_UPDATE);
180 if(i < level_subsets.num_items-1)
181 texture_draw(&arrow_right,(screen->w / 2) + ((strlen(subset.title))*16)/2,20,NO_UPDATE);
183 text_drawf(&gold_text, subset.title, 0, 20, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
184 text_drawf(&gold_text, subset.description, 20, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
188 while(SDL_PollEvent(&event) && !done)
196 case SDL_KEYDOWN: // key pressed
199 key = event.key.keysym.sym;
206 subset_free(&subset);
207 subset_load(&subset,level_subsets.item[i]);
210 else if(key == SDLK_RIGHT)
212 if(i < level_subsets.num_items -1)
215 subset_free(&subset);
216 subset_load(&subset,level_subsets.item[i]);
219 else if(key == SDLK_SPACE || key == SDLK_RETURN)
222 quit = gameloop(subset.name,1,ST_GL_PLAY);
223 subset_free(&subset);
225 else if(key == SDLK_ESCAPE)
238 update_load_save_game_menu(&load_game_menu, YES);
242 quit = leveleditor(1);
252 else if(current_menu == &options_menu)
254 process_options_menu();
256 else if(current_menu == &load_game_menu)
258 process_save_load_game_menu(NO);
270 texture_free(&bkg_title);
271 texture_free(&anim1);
272 texture_free(&anim2);
273 string_list_free(&level_subsets);
275 /* Return to main! */
280 void display_credits()
289 string_list_type names;
290 string_list_init(&names);
292 sprintf(filename,"%s/CREDITS",DATA_PREFIX);
293 if((fi = fopen(filename,"r")) != NULL)
295 while(fgets(temp, sizeof(temp), fi) != NULL)
297 temp[strlen(temp)-1]='\0';
298 string_list_add_item(&names,temp);
304 string_list_add_item(&names,"Credits were not found!");
305 string_list_add_item(&names,"Shame on the guy, who");
306 string_list_add_item(&names,"forgot to include them");
307 string_list_add_item(&names,"in your SuperTux distribution.");
311 timer_init(&timer, SDL_GetTicks());
312 timer_start(&timer, 50);
321 length = names.num_items;
323 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
327 /* in case of input, exit */
328 while(SDL_PollEvent(&event))
332 switch(event.key.keysym.sym)
359 /* draw the credits */
363 text_drawf(&white_big_text, "- Credits -", 0, screen->h-scroll, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
365 for(i = 0, n = 0, d = 0; i < length; i++,n++,d++)
367 if(names.item[i] == "")
371 if(names.item[i][0] == ' ')
372 text_drawf(&white_small_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll-10, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
373 else if(names.item[i][0] == ' ')
374 text_drawf(&white_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
375 else if(names.item[i+1][0] == '-' || names.item[i][0] == '-')
376 text_drawf(&white_big_text, names.item[i], 0, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 3+e%7, NO_UPDATE);
378 text_drawf(&blue_text, names.item[i], 0 + e % 20, 60+screen->h+(n*18)+(d*18)-scroll, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
388 texture_draw_part(&bkg_title, 0, 0, 0, 0, 640, 130, NO_UPDATE);
392 if(60+screen->h+(n*18)+(d*18)-scroll < 0 && 20+60+screen->h+(n*18)+(d*18)-scroll < 0)
401 if(timer_get_left(&timer) < 0)
404 timer_start(&timer, 50);
407 string_list_free(&names);
409 SDL_EnableKeyRepeat(0, 0); // disables key repeating
411 menu_set_current(&main_menu);