831a2d95fed4adbd40bd3f94b7bdbe3ca8e36803
[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 - April 12, 2000
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 #ifndef NOSOUND
22 #include <SDL_mixer.h>
23 #endif
24
25 #ifdef LINUX
26 #include <pwd.h>
27 #include <sys/types.h>
28 #include <ctype.h>
29 #endif
30
31 #include "defines.h"
32 #include "globals.h"
33 #include "title.h"
34 #include "screen.h"
35
36
37 /* --- TITLE SCREEN --- */
38
39 int title(void)
40 {
41   SDL_Surface * title, * anim1, * anim2;
42   SDL_Event event;
43   SDLKey key;
44   int done, quit, frame, pict;
45   
46   
47   /* Clear screen: */
48   
49   clearscreen(0, 0, 0);
50   updatescreen();
51   
52   
53   /* Load images: */
54   
55   title = load_image(DATA_PREFIX "/images/title/title.png", IGNORE_ALPHA);
56   anim1 = load_image(DATA_PREFIX "/images/title/title-anim2.png",
57                      IGNORE_ALPHA);
58   anim2 = load_image(DATA_PREFIX "/images/title/title-anim1.png",
59                      IGNORE_ALPHA);
60   
61   
62   /* Draw the title background: */
63   
64   drawimage(title, 0, 0, UPDATE);
65   
66   
67   /* --- Main title loop: --- */
68   
69   done = 0;
70   quit = 0;
71   
72   frame = 0;
73   
74   do
75     {
76       frame++;
77       
78       
79       /* Handle events: */
80       
81       while (SDL_PollEvent(&event))
82         {
83           if (event.type == SDL_QUIT)
84             {
85               /* Quit event - quit: */
86               
87               quit = 1;
88             }
89           else if (event.type == SDL_KEYDOWN)
90             {
91               /* Keypress... */
92               
93               key = event.key.keysym.sym;
94               
95               if (key == SDLK_ESCAPE)
96                 {
97                   /* Escape: Quit: */
98                   
99                   quit = 1;
100                 }
101               else if (key == SDLK_SPACE || key == SDLK_RETURN)
102                 {
103                   /* Space / Return: Continue: */
104                   
105                   done = 1;
106                 }
107             }
108 #ifdef JOY_YES
109           else if (event.type == SDL_JOYBUTTONDOWN)
110             {
111               /* Joystick button: Continue: */
112               
113               done = 1;
114             }
115 #endif
116         }
117       
118       
119       /* Animate title screen: */
120       
121       pict = (frame / 5) % 3;
122       
123       if (pict == 0)
124         drawpart(title, 560, 270, 80, 75, UPDATE);
125       else if (pict == 1)
126         drawimage(anim1, 560, 270, UPDATE);
127       else if (pict == 2)
128         drawimage(anim2, 560, 270, UPDATE);
129       
130       
131       /* Pause: */
132       
133       SDL_Delay(50);
134     }
135   while (!done && !quit);
136   
137   
138   /* Free surfaces: */
139   
140   SDL_FreeSurface(title);
141   SDL_FreeSurface(anim1);
142   SDL_FreeSurface(anim2);
143   
144   
145   /* Return to main! */
146   
147   return(quit);
148 }