7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - November 7, 2001
19 #include <SDL_image.h>
23 #include <sys/types.h>
34 /* Local function prototypes: */
37 void usage(char * prog, int ret);
44 /* Seed random number generator: */
46 srand(SDL_GetTicks());
51 if (SDL_Init(SDL_INIT_VIDEO) < 0)
54 "\nError: I could not initialize video!\n"
55 "The Simple DirectMedia error that occured was:\n"
56 "%s\n\n", SDL_GetError());
66 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
68 fprintf(stderr, "Warning: I could not initialize joystick!\n"
69 "The Simple DirectMedia error that occured was:\n"
70 "%s\n\n", SDL_GetError());
78 if (SDL_NumJoysticks() <= 0)
80 fprintf(stderr, "Warning: No joysticks are available.\n");
86 js = SDL_JoystickOpen(0);
90 fprintf(stderr, "Warning: Could not open joystick 1.\n"
91 "The Simple DirectMedia error that occured was:\n"
92 "%s\n\n", SDL_GetError());
98 /* Check for proper joystick configuration: */
100 if (SDL_JoystickNumAxes(js) < 2)
103 "Warning: Joystick does not have enough axes!\n");
109 if (SDL_JoystickNumButtons(js) < 2)
113 "Joystick does not have enough buttons!\n");
124 /* Init SDL Audio: */
126 if (use_sound == YES)
128 if (SDL_Init(SDL_INIT_AUDIO) < 0)
131 "\nWarning: I could not initialize audio!\n"
132 "The Simple DirectMedia error that occured was:\n"
133 "%s\n\n", SDL_GetError());
141 if (use_sound == YES)
143 if (Mix_OpenAudio(44100, AUDIO_S16, 2, 512) < 0)
146 "\nWarning: I could not set up audio for 44100 Hz "
148 "The Simple DirectMedia error that occured was:\n"
149 "%s\n\n", SDL_GetError());
157 if (use_fullscreen == YES)
159 screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
163 "\nWarning: I could not set up fullscreen video for "
165 "The Simple DirectMedia error that occured was:\n"
166 "%s\n\n", SDL_GetError());
171 if (use_fullscreen == NO)
173 screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
178 "\nError: I could not set up video for 640x480 mode.\n"
179 "The Simple DirectMedia error that occured was:\n"
180 "%s\n\n", SDL_GetError());
186 /* Load global images: */
188 letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
191 letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
194 letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
197 letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
201 /* Set icon image: */
206 /* Set window manager stuff: */
208 SDL_WM_SetCaption("Super Tux", "Super Tux");
212 /* --- SHUTDOWN --- */
214 void st_shutdown(void)
222 void st_abort(char * reason, char * details)
224 fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
230 /* Set Icon (private) */
239 /* Load icon into a surface: */
241 icon = IMG_Load(DATA_PREFIX "/images/icon.png");
245 "\nError: I could not load the icon image: %s\n"
246 "The Simple DirectMedia error that occured was:\n"
247 "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
254 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
255 mask = malloc(masklen * sizeof(Uint8));
256 memset(mask, 0xFF, masklen);
261 SDL_WM_SetIcon(icon, mask);
264 /* Free icon surface & mask: */
267 SDL_FreeSurface(icon);
271 /* Parse command-line arguments: */
273 void parseargs(int argc, char * argv[])
287 /* Parse arguments: */
289 for (i = 1; i < argc; i++)
291 if (strcmp(argv[i], "--fullscreen") == 0 ||
292 strcmp(argv[i], "-f") == 0)
294 /* Use full screen: */
296 use_fullscreen = YES;
298 else if (strcmp(argv[i], "--usage") == 0)
304 else if (strcmp(argv[i], "--version") == 0)
308 printf("Super Tux - version " VERSION "\n");
311 else if (strcmp(argv[i], "--disable-sound") == 0)
313 /* Disable the compiled in sound & music feature */
315 printf("Sounds and music disabled \n");
318 printf("Sounds and music feature is not compiled in \n");
321 else if (strcmp(argv[i], "--help") == 0)
324 printf("Super Tux " VERSION "\n\n");
326 printf("---------- Command-line options ----------\n\n");
328 printf(" --disable-sound - If sound support was compiled in, this will\n disable it for this session of the game.\n\n");
330 printf(" --fullscreen - Run in fullscreen mode.\n\n");
332 printf(" --help - Display a help message summarizing command-line\n options, license and game controls.\n\n");
334 printf(" --usage - Display a brief message summarizing command-line options.\n\n");
336 printf(" --version - Display the version of SuperTux you're running.\n\n\n");
339 printf("---------- License ----------\n\n");
340 printf(" This program comes with ABSOLUTELY NO WARRANTY.\n");
341 printf(" This is free software, and you are welcome to redistribute\n");
342 printf(" or modify it under certain conditions. See the file \n");
343 printf(" \"COPYING.txt\" for more details.\n\n\n");
345 printf("---------- Game controls ----------\n\n");
346 printf(" Please see the file \"README.txt\"\n\n");
352 /* Unknown - complain! */
362 void usage(char * prog, int ret)
367 /* Determine which stream to write to: */
375 /* Display the usage message: */
377 fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] | [--usage | --help | --version]\n",