7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - November 7, 2001
19 #include <SDL_image.h>
22 #include <SDL_mixer.h>
27 #include <sys/types.h>
37 /* Local function prototypes: */
40 void usage(char * prog, int ret);
47 /* Seed random number generator: */
49 srand(SDL_GetTicks());
54 if (SDL_Init(SDL_INIT_VIDEO) < 0)
57 "\nError: I could not initialize video!\n"
58 "The Simple DirectMedia error that occured was:\n"
59 "%s\n\n", SDL_GetError());
69 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
71 fprintf(stderr, "Warning: I could not initialize joystick!\n"
72 "The Simple DirectMedia error that occured was:\n"
73 "%s\n\n", SDL_GetError());
81 if (SDL_NumJoysticks() <= 0)
83 fprintf(stderr, "Warning: No joysticks are available.\n");
89 js = SDL_JoystickOpen(0);
93 fprintf(stderr, "Warning: Could not open joystick 1.\n"
94 "The Simple DirectMedia error that occured was:\n"
95 "%s\n\n", SDL_GetError());
101 /* Check for proper joystick configuration: */
103 if (SDL_JoystickNumAxes(js) < 2)
106 "Warning: Joystick does not have enough axes!\n");
112 if (SDL_JoystickNumButtons(js) < 2)
116 "Joystick does not have enough buttons!\n");
127 /* Init SDL Audio: */
129 if (use_sound == YES)
131 if (SDL_Init(SDL_INIT_AUDIO) < 0)
134 "\nWarning: I could not initialize audio!\n"
135 "The Simple DirectMedia error that occured was:\n"
136 "%s\n\n", SDL_GetError());
145 if (use_sound == YES)
147 if (Mix_OpenAudio(11025, AUDIO_S16, 2, 512) < 0)
150 "\nWarning: I could not set up audio for 11025 Hz "
152 "The Simple DirectMedia error that occured was:\n"
153 "%s\n\n", SDL_GetError());
162 if (use_fullscreen == YES)
164 screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
168 "\nWarning: I could not set up fullscreen video for "
170 "The Simple DirectMedia error that occured was:\n"
171 "%s\n\n", SDL_GetError());
176 if (use_fullscreen == NO)
178 screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
183 "\nError: I could not set up video for 640x480 mode.\n"
184 "The Simple DirectMedia error that occured was:\n"
185 "%s\n\n", SDL_GetError());
191 /* Load global images: */
193 letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
196 letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
199 letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
202 letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
206 /* Set icon image: */
211 /* Set window manager stuff: */
213 SDL_WM_SetCaption("Super Tux", "Super Tux");
217 /* --- SHUTDOWN --- */
219 void st_shutdown(void)
227 void st_abort(char * reason, char * details)
229 fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
235 /* Set Icon (private) */
244 /* Load icon into a surface: */
246 icon = IMG_Load(DATA_PREFIX "/images/icon.png");
250 "\nError: I could not load the icon image: %s\n"
251 "The Simple DirectMedia error that occured was:\n"
252 "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
259 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
260 mask = malloc(masklen * sizeof(Uint8));
261 memset(mask, 0xFF, masklen);
266 SDL_WM_SetIcon(icon, mask);
269 /* Free icon surface & mask: */
272 SDL_FreeSurface(icon);
276 /* Parse command-line arguments: */
278 void parseargs(int argc, char * argv[])
289 /* Parse arguments: */
291 for (i = 1; i < argc; i++)
293 if (strcmp(argv[i], "--fullscreen") == 0 ||
294 strcmp(argv[i], "-f") == 0)
296 /* Use full screen: */
298 use_fullscreen = YES;
300 else if (strcmp(argv[i], "--usage") == 0)
306 else if (strcmp(argv[i], "--version") == 0)
310 printf("Super Tux - version " VERSION "\n");
313 else if (strcmp(argv[i], "--help") == 0)
317 printf("Super Tux - Help summary\n");
318 printf("[ under construction ]\n");
323 /* Unknown - complain! */
333 void usage(char * prog, int ret)
338 /* Determine which stream to write to: */
346 /* Display the usage message: */
348 fprintf(fi, "Usage: %s [--fullscreen] | [--usage | --help | --version]\n",