Implemented --help and --disable-sound (patch by Duong-Khang NGUYEN <neoneurone@users...
[supertux.git] / src / title.c
1 /*
2   title.c
3   
4   Super Tux - Title Screen
5   
6   by Bill Kendrick
7   bill@newbreedsoftware.com
8   http://www.newbreedsoftware.com/supertux/
9   
10   April 11, 2000 - December 9, 2003
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <unistd.h>
18 #include <SDL.h>
19 #include <SDL_image.h>
20
21 #ifdef LINUX
22 #include <pwd.h>
23 #include <sys/types.h>
24 #include <ctype.h>
25 #endif
26
27 #include "defines.h"
28 #include "globals.h"
29 #include "title.h"
30 #include "screen.h"
31 #include "high_scores.h"
32
33
34 /* --- TITLE SCREEN --- */
35
36 int title(void)
37 {
38   SDL_Surface * title, * anim1, * anim2;
39   SDL_Event event;
40   SDLKey key;
41   int done, quit, frame, pict;
42   char str[80];
43   
44   
45   /* Clear screen: */
46   
47   clearscreen(0, 0, 0);
48   updatescreen();
49   
50   
51   /* Load images: */
52   
53   title = load_image(DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA);
54   anim1 = load_image(DATA_PREFIX "/images/title/title-anim2.png",
55                      IGNORE_ALPHA);
56   anim2 = load_image(DATA_PREFIX "/images/title/title-anim1.png",
57                      IGNORE_ALPHA);
58   
59   
60   /* Draw the title background: */
61   
62   drawimage(title, 0, 0, UPDATE);
63
64
65   /* Draw the high score: */
66
67   sprintf(str, "High score: %d", load_hs());
68   drawcenteredtext(str, 460, letters_red, UPDATE);
69   
70   
71   /* --- Main title loop: --- */
72   
73   done = 0;
74   quit = 0;
75   
76   frame = 0;
77   
78   do
79     {
80       frame++;
81       
82       
83       /* Handle events: */
84       
85       while (SDL_PollEvent(&event))
86         {
87           if (event.type == SDL_QUIT)
88             {
89               /* Quit event - quit: */
90               
91               quit = 1;
92             }
93           else if (event.type == SDL_KEYDOWN)
94             {
95               /* Keypress... */
96               
97               key = event.key.keysym.sym;
98               
99               if (key == SDLK_ESCAPE)
100                 {
101                   /* Escape: Quit: */
102                   
103                   quit = 1;
104                 }
105               else if (key == SDLK_SPACE || key == SDLK_RETURN)
106                 {
107                   /* Space / Return: Continue: */
108                   
109                   done = 1;
110                 }
111             }
112 #ifdef JOY_YES
113           else if (event.type == SDL_JOYBUTTONDOWN)
114             {
115               /* Joystick button: Continue: */
116               
117               done = 1;
118             }
119 #endif
120         }
121       
122       
123       /* Animate title screen: */
124       
125       pict = (frame / 5) % 3;
126       
127       if (pict == 0)
128         drawpart(title, 560, 270, 80, 75, UPDATE);
129       else if (pict == 1)
130         drawimage(anim1, 560, 270, UPDATE);
131       else if (pict == 2)
132         drawimage(anim2, 560, 270, UPDATE);
133       
134       
135       /* Pause: */
136       
137       SDL_Delay(50);
138     }
139   while (!done && !quit);
140   
141   
142   /* Free surfaces: */
143   
144   SDL_FreeSurface(title);
145   SDL_FreeSurface(anim1);
146   SDL_FreeSurface(anim2);
147   
148   
149   /* Return to main! */
150   
151   return(quit);
152 }