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);
45 /* Set SuperTux configuration and save directories
47 /* Get home directory (from $HOME variable)... if we can't determine it,
48 use the current directory ("."): */
50 if (getenv("HOME") != NULL)
51 home = getenv("HOME");
55 st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
56 strlen("/.supertux") + 1));
58 strcat(st_dir, "/.supertux");
60 st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
62 strcpy(st_save_dir,st_dir);
63 strcpy(st_save_dir,"/save");
65 /* Create them. In the case they exist it won't destroy anything. */
67 mkdir(st_save_dir, 0755);
69 /* Seed random number generator: */
71 srand(SDL_GetTicks());
76 if (SDL_Init(SDL_INIT_VIDEO) < 0)
79 "\nError: I could not initialize video!\n"
80 "The Simple DirectMedia error that occured was:\n"
81 "%s\n\n", SDL_GetError());
91 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
93 fprintf(stderr, "Warning: I could not initialize joystick!\n"
94 "The Simple DirectMedia error that occured was:\n"
95 "%s\n\n", SDL_GetError());
103 if (SDL_NumJoysticks() <= 0)
105 fprintf(stderr, "Warning: No joysticks are available.\n");
111 js = SDL_JoystickOpen(0);
115 fprintf(stderr, "Warning: Could not open joystick 1.\n"
116 "The Simple DirectMedia error that occured was:\n"
117 "%s\n\n", SDL_GetError());
123 /* Check for proper joystick configuration: */
125 if (SDL_JoystickNumAxes(js) < 2)
128 "Warning: Joystick does not have enough axes!\n");
134 if (SDL_JoystickNumButtons(js) < 2)
138 "Joystick does not have enough buttons!\n");
151 /* Init SDL Audio silently even if --disable-sound : */
153 if (audio_device == YES)
155 if (SDL_Init(SDL_INIT_AUDIO) < 0)
157 /* only print out message if sound was not disabled at command-line */
158 if (use_sound == YES)
161 "\nWarning: I could not initialize audio!\n"
162 "The Simple DirectMedia error that occured was:\n"
163 "%s\n\n", SDL_GetError());
171 /* Open sound silently regarless the value of "use_sound": */
173 if (audio_device == YES)
175 if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
177 /* only print out message if sound was not disabled at command-line */
178 if (use_sound == YES)
181 "\nWarning: I could not set up audio for 44100 Hz "
183 "The Simple DirectMedia error that occured was:\n"
184 "%s\n\n", SDL_GetError());
194 if (use_fullscreen == YES)
196 screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
200 "\nWarning: I could not set up fullscreen video for "
202 "The Simple DirectMedia error that occured was:\n"
203 "%s\n\n", SDL_GetError());
208 if (use_fullscreen == NO)
210 screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
215 "\nError: I could not set up video for 640x480 mode.\n"
216 "The Simple DirectMedia error that occured was:\n"
217 "%s\n\n", SDL_GetError());
223 /* Load global images: */
225 letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
228 letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
231 letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
234 letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
238 /* Set icon image: */
243 /* Set window manager stuff: */
245 SDL_WM_SetCaption("Super Tux", "Super Tux");
249 /* --- SHUTDOWN --- */
251 void st_shutdown(void)
259 void st_abort(char * reason, char * details)
261 fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
267 /* Set Icon (private) */
276 /* Load icon into a surface: */
278 icon = IMG_Load(DATA_PREFIX "/images/icon.png");
282 "\nError: I could not load the icon image: %s\n"
283 "The Simple DirectMedia error that occured was:\n"
284 "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
291 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
292 mask = malloc(masklen * sizeof(Uint8));
293 memset(mask, 0xFF, masklen);
298 SDL_WM_SetIcon(icon, mask);
301 /* Free icon surface & mask: */
304 SDL_FreeSurface(icon);
308 /* Parse command-line arguments: */
310 void parseargs(int argc, char * argv[])
328 /* Parse arguments: */
330 for (i = 1; i < argc; i++)
332 if (strcmp(argv[i], "--fullscreen") == 0 ||
333 strcmp(argv[i], "-f") == 0)
335 /* Use full screen: */
337 use_fullscreen = YES;
339 else if (strcmp(argv[i], "--usage") == 0)
345 else if (strcmp(argv[i], "--version") == 0)
349 printf("Super Tux - version " VERSION "\n");
352 else if (strcmp(argv[i], "--disable-sound") == 0)
354 /* Disable the compiled in sound & music feature */
356 printf("Sounds and music disabled \n");
360 printf("Sounds and music feature is not compiled in \n");
364 else if (strcmp(argv[i], "--help") == 0)
367 printf("Super Tux " VERSION "\n\n");
369 printf("---------- Command-line options ----------\n\n");
371 printf(" --disable-sound - If sound support was compiled in, this will\n disable it for this session of the game.\n\n");
373 printf(" --fullscreen - Run in fullscreen mode.\n\n");
375 printf(" --help - Display a help message summarizing command-line\n options, license and game controls.\n\n");
377 printf(" --usage - Display a brief message summarizing command-line options.\n\n");
379 printf(" --version - Display the version of SuperTux you're running.\n\n\n");
382 printf("---------- License ----------\n\n");
383 printf(" This program comes with ABSOLUTELY NO WARRANTY.\n");
384 printf(" This is free software, and you are welcome to redistribute\n");
385 printf(" or modify it under certain conditions. See the file \n");
386 printf(" \"COPYING.txt\" for more details.\n\n\n");
388 printf("---------- Game controls ----------\n\n");
389 printf(" Please see the file \"README.txt\"\n\n");
395 /* Unknown - complain! */
405 void usage(char * prog, int ret)
410 /* Determine which stream to write to: */
418 /* Display the usage message: */
420 fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] | [--usage | --help | --version]\n",