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 strcat(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 or music
158 was not disabled at command-line
160 if (use_sound == YES || use_music == YES)
163 "\nWarning: I could not initialize audio!\n"
164 "The Simple DirectMedia error that occured was:\n"
165 "%s\n\n", SDL_GetError());
167 /* keep the programming logic the same :-)
168 because in this case, use_sound & use_music' values are ignored
169 when there's no available audio device
178 /* Open sound silently regarless the value of "use_sound": */
180 if (audio_device == YES)
182 if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
184 /* only print out message if sound or music
185 was not disabled at command-line
187 if ((use_sound == YES) || (use_music == YES))
190 "\nWarning: I could not set up audio for 44100 Hz "
192 "The Simple DirectMedia error that occured was:\n"
193 "%s\n\n", SDL_GetError());
204 if (use_fullscreen == YES)
206 screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
210 "\nWarning: I could not set up fullscreen video for "
212 "The Simple DirectMedia error that occured was:\n"
213 "%s\n\n", SDL_GetError());
218 if (use_fullscreen == NO)
220 screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
225 "\nError: I could not set up video for 640x480 mode.\n"
226 "The Simple DirectMedia error that occured was:\n"
227 "%s\n\n", SDL_GetError());
233 /* Load global images: */
235 letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
238 letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
241 letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
244 letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
248 /* Set icon image: */
253 /* Set window manager stuff: */
255 SDL_WM_SetCaption("Super Tux", "Super Tux");
259 /* --- SHUTDOWN --- */
261 void st_shutdown(void)
269 void st_abort(char * reason, char * details)
271 fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
277 /* Set Icon (private) */
286 /* Load icon into a surface: */
288 icon = IMG_Load(DATA_PREFIX "/images/icon.png");
292 "\nError: I could not load the icon image: %s\n"
293 "The Simple DirectMedia error that occured was:\n"
294 "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
301 masklen = (((icon -> w) + 7) / 8) * (icon -> h);
302 mask = malloc(masklen * sizeof(Uint8));
303 memset(mask, 0xFF, masklen);
308 SDL_WM_SetIcon(icon, mask);
311 /* Free icon surface & mask: */
314 SDL_FreeSurface(icon);
318 /* Parse command-line arguments: */
320 void parseargs(int argc, char * argv[])
340 /* Parse arguments: */
342 for (i = 1; i < argc; i++)
344 if (strcmp(argv[i], "--fullscreen") == 0 ||
345 strcmp(argv[i], "-f") == 0)
347 /* Use full screen: */
349 use_fullscreen = YES;
351 else if (strcmp(argv[i], "--usage") == 0)
357 else if (strcmp(argv[i], "--version") == 0)
361 printf("Super Tux - version " VERSION "\n");
364 else if (strcmp(argv[i], "--disable-sound") == 0)
366 /* Disable the compiled in sound feature */
368 printf("Sounds disabled \n");
372 printf("Warning: Sounds feature is not compiled in \n");
373 printf("Warning: Sounds feature is not compiled in \n");
376 else if (strcmp(argv[i], "--disable-music") == 0)
378 /* Disable the compiled in sound feature */
380 printf("Music disabled \n");
383 printf("Warning: Music feature is not compiled in \n");
387 else if (strcmp(argv[i], "--help") == 0)
390 printf("Super Tux " VERSION "\n\n");
392 printf("---------- Command-line options ----------\n\n");
394 printf(" --disable-sound - If sound support was compiled in, this will\n disable sound for this session of the game.\n\n");
396 printf(" --disable-music - Like above, but this will disable music.\n\n");
398 printf(" --fullscreen - Run in fullscreen mode.\n\n");
400 printf(" --help - Display a help message summarizing command-line\n options, license and game controls.\n\n");
402 printf(" --usage - Display a brief message summarizing command-line options.\n\n");
404 printf(" --version - Display the version of SuperTux you're running.\n\n\n");
407 printf("---------- License ----------\n\n");
408 printf(" This program comes with ABSOLUTELY NO WARRANTY.\n");
409 printf(" This is free software, and you are welcome to redistribute\n");
410 printf(" or modify it under certain conditions. See the file \n");
411 printf(" \"COPYING.txt\" for more details.\n\n\n");
413 printf("---------- Game controls ----------\n\n");
414 printf(" Please see the file \"README.txt\"\n\n");
420 /* Unknown - complain! */
430 void usage(char * prog, int ret)
435 /* Determine which stream to write to: */
443 /* Display the usage message: */
445 fprintf(fi, "Usage: %s [--fullscreen] [--disable-sound] [--disable-music] | [--usage | --help | --version]\n",