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 /* --- TITLE SCREEN --- */
44 texture_type title, img_choose_subset, anim1, anim2;
47 int done, quit, frame, pict, i;
52 level_subsets = dsubdirs("/levels", "info", &subsets_num);
56 /* Rest menu variables */
58 menu_set_current(&main_menu);
65 texture_load(&title,DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA);
66 texture_load(&anim1,DATA_PREFIX "/images/title/title-anim2.png", IGNORE_ALPHA);
67 texture_load(&anim2,DATA_PREFIX "/images/title/title-anim1.png", IGNORE_ALPHA);
68 texture_load(&img_choose_subset,DATA_PREFIX "/images/status/choose-level-subset.png", IGNORE_ALPHA);
70 /* --- Main title loop: --- */
77 /* Draw the title background: */
78 texture_draw_bg(&title, NO_UPDATE);
80 /* Draw the high score: */
82 sprintf(str, "High score: %d", hs_score);
83 text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
84 sprintf(str, "by %s", hs_name);
85 text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
87 while (!done && !quit)
92 while (SDL_PollEvent(&event))
94 if (event.type == SDL_QUIT)
96 /* Quit event - quit: */
99 else if (event.type == SDL_KEYDOWN)
103 key = event.key.keysym.sym;
105 /* Check for menu events */
106 menu_event(&event.key.keysym);
108 if (key == SDLK_ESCAPE)
116 else if (event.type == SDL_JOYAXISMOTION && event.jaxis.axis == JOY_Y)
118 if (event.jaxis.value > 1024)
119 menuaction = MN_DOWN;
120 else if (event.jaxis.value < -1024)
123 else if (event.type == SDL_JOYBUTTONDOWN)
125 /* Joystick button: Continue: */
133 /* Draw the title background: */
135 texture_draw_bg(&title, NO_UPDATE);
137 /* Draw the high score: */
138 sprintf(str, "High score: %d", hs_score);
139 text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
140 sprintf(str, "by %s", hs_name);
141 text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1, NO_UPDATE);
143 /* Don't draw menu, if quit is true */
144 if(show_menu && !quit)
145 menu_process_current();
147 if(current_menu == &main_menu)
149 switch (menu_check(&main_menu))
154 subset_load(&subset,level_subsets[0]);
157 texture_draw(&img_choose_subset, 50, 0, NO_UPDATE);
160 texture_draw(&subset.image,135,78,NO_UPDATE);
161 text_drawf(&gold_text, subset.title, 0, 20, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
165 while(SDL_PollEvent(&event) && !done)
172 case SDL_KEYDOWN: // key pressed
175 key = event.key.keysym.sym;
182 subset_free(&subset);
183 subset_load(&subset,level_subsets[i]);
186 else if(key == SDLK_RIGHT)
188 if(i < subsets_num -1)
191 subset_free(&subset);
192 subset_load(&subset,level_subsets[i]);
195 else if(key == SDLK_SPACE || key == SDLK_RETURN)
198 quit = gameloop(subset.name,1,ST_GL_PLAY);
199 subset_free(&subset);
201 else if(key == SDLK_ESCAPE)
214 quit = leveleditor(1);
221 else if(current_menu == &options_menu)
223 process_options_menu();
225 /* Animate title screen: */
227 pict = (frame / 5) % 3;
230 texture_draw_part(&title, 560, 270, 560, 270, 80, 75, NO_UPDATE);
232 texture_draw(&anim1, 560, 270, NO_UPDATE);
234 texture_draw(&anim2, 560, 270, NO_UPDATE);
245 texture_free(&title);
246 texture_free(&anim1);
247 texture_free(&anim2);
248 free_strings(level_subsets,subsets_num);
250 /* Return to main! */