home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / edu / tux / Tuxtype2-1.5.3-installer.exe / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-31  |  5.1 KB  |  159 lines

  1. /***************************************************************************
  2.                           main.c 
  3.  -  description: main tux type file
  4.                              -------------------
  5.     begin                : Tue May  2 13:25:06 MST 2000
  6.     copyright            : (C) 2000 by Sam Hart
  7.                          : (C) 2003 by Jesse Andrews
  8.     email                : tuxtype-dev@tux4kids.net
  9.  ***************************************************************************/
  10. /***************************************************************************
  11.  *                                                                         *
  12.  *   This program is free software; you can redistribute it and/or modify  *
  13.  *   it under the terms of the GNU General Public License as published by  *
  14.  *   the Free Software Foundation; either version 2 of the License, or     *
  15.  *   (at your option) any later version.                                   *
  16.  *                                                                         *
  17.  ***************************************************************************/
  18.  
  19. #include "globals.h"
  20. #include "funcs.h"
  21.  
  22. SDL_Surface *screen;
  23. SDL_Surface *bkg;
  24.  
  25. // HACK: add tux trudging off after losing laser game...
  26.  
  27. int sys_sound;
  28. SDL_Event  event;
  29.  
  30. extern settings localsettings;
  31.  
  32. /********************
  33.   main : init stuff
  34. *********************/
  35. int main(int argc, char *argv[])
  36. {
  37.     Uint32          video_flags = 0,
  38.                     lib_flags   = 0;
  39.     int i;
  40.    
  41.     sys_sound = 1;      //default using system sounds
  42.     speed_up = 0;       //run at normal speed
  43.     show_tux4kids = 1;  //show tux4kids logo the first time in main menu
  44.     useEnglish = 1;     //default to no theme
  45.     debugOn = 0;        //default to not in debug mode
  46.     hidden = 0;         //default to no "hidden" background
  47.  
  48.     setupTheme(NULL);
  49.     srand(time(NULL));
  50.  
  51.  
  52.     LoadSettings();
  53.     DEBUGCODE { printf("Window setting from config file is: %s\n", localsettings.window );}
  54.  
  55.     if (strncmp ( localsettings.window, "yes", FNLEN ) == 0 ){
  56.         video_flags = (SDL_SWSURFACE | SDL_HWPALETTE);
  57.     } else {
  58.         video_flags = (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE);
  59.     }
  60.         
  61.     lib_flags = SDL_INIT_VIDEO;
  62.  
  63.     // check command line args
  64.     if (argc > 1) 
  65.         for (i = 1; i < argc; i++) {
  66.             if ((strcmp(argv[i], "-h") == 0) |
  67.                 (strcmp(argv[i], "--help") == 0) | 
  68.                 (strcmp(argv[i], "-help") == 0)) {
  69.                 fprintf(stderr, "\nUsage:\n tuxtype [OPTION]...");
  70.                 fprintf(stderr, "\n\nOptions:\n\n\t-h, --help, -help");
  71.                 fprintf(stderr, "\n\t\tPrints this help message");
  72.                 fprintf(stderr, "\n\n\t-f, --fullscreen");
  73.                 fprintf(stderr, "\n\t\tSelects fullscreen display (default)");
  74.                 fprintf(stderr, "\n\n\t-w, --window");
  75.                 fprintf(stderr, "\n\t\tSelects windowed display (not fullscreen)");
  76.                 fprintf(stderr, "\n\n\t-s, --sound");
  77.                 fprintf(stderr, "\n\t\tAllow in-game sounds (default)");
  78.                 fprintf(stderr, "\n\n\t-ns, --nosound");
  79.                 fprintf(stderr, "\n\t\tDisables in-game sounds");
  80.                 fprintf(stderr, "\n\n\t-t {THEME}, --theme {THEME}");
  81.                 fprintf(stderr, "\n\t\tUse theme named {THEME}, if it exists");
  82.                 fprintf(stderr, "\n\n\t-sp, --speed");
  83.                 fprintf(stderr, "\n\t\tSpeed up gameplay (for use on slower");
  84.                 fprintf(stderr, "\n\t\tmachines)");
  85.                 fprintf(stderr, "\n\n\t-d, --debug");
  86.                 fprintf(stderr, "\n\t\tEnable debug mode (output)\n");
  87.                 fprintf(stderr, "\n\n\t-v, --version");
  88.                 fprintf(stderr, "\n\t\tDisplay version number and exit\n");
  89.                 exit(0);
  90.             }
  91.             if ((strcmp(argv[i], "-v") == 0) |
  92.                 (strcmp(argv[i], "--version") == 0)) {
  93.                 fprintf(stderr, "\n%s, Version %s\n", PACKAGE, VERSION);
  94.                 fprintf(stderr, "Copyright (C) Sam Hart <hart@geekcomix.com>, under the GPL\n");
  95.                 fprintf(stderr, "-See COPYING file for more info... Thx ;)\n\n");
  96.                 exit(0);
  97.             }
  98.             if ((strcmp(argv[i], "-f") == 0) |
  99.                 (strcmp(argv[i], "--fullscreen") == 0))
  100.                 video_flags = (SDL_FULLSCREEN | SDL_HWPALETTE); // | SDL_HWSURFACE | SDL_DOUBLEBUF);
  101.             
  102.             if ((strcmp(argv[i], "-w") == 0) |
  103.                 (strcmp(argv[i], "--window") == 0)) 
  104.                 video_flags = (SDL_HWPALETTE);  // | SDL_DOUBLEBUF);
  105.         
  106.             if ((strcmp(argv[i], "-sp") == 0) |
  107.                 (strcmp(argv[i], "--speed") == 0)) 
  108.                 speed_up = 1;
  109.  
  110.             if ((strcmp(argv[i], "-d") == 0) |
  111.                 (strcmp(argv[i], "--debug") == 0)) 
  112.                 debugOn = 1;
  113.  
  114.             if ((strcmp(argv[i], "-s") == 0) |
  115.                 (strcmp(argv[i], "--sound") == 0)) 
  116.                 sys_sound = 1;
  117.             
  118.             if ((strcmp(argv[i], "-ns") == 0) |
  119.                 (strcmp(argv[i], "--nosound") == 0)) 
  120.                 sys_sound = 0;
  121.             
  122.             if ((strcmp(argv[i], "--hidden") == 0) |
  123.                 (strcmp(argv[i], "-hidden") == 0)) 
  124.                 hidden = 1;
  125.             
  126.             if ((strcmp(argv[i], "-t") == 0) |
  127.                 (strcmp(argv[i], "--theme") == 0)) 
  128.                 setupTheme( argv[++i] );
  129.         }
  130.  
  131.     DEBUGCODE {
  132.         fprintf(stderr, "\n%s, version %s BEGIN\n", PACKAGE, VERSION);
  133.     }
  134.  
  135.     if (sys_sound)
  136.         lib_flags |= SDL_INIT_AUDIO;
  137.  
  138.     LibInit(lib_flags);
  139.     GraphicsInit(video_flags);
  140.  
  141.     if (sys_sound){
  142.         Mix_VolumeMusic(localsettings.mus_volume);
  143.         Mix_Volume(-1,localsettings.sfx_volume);
  144.     }
  145.  
  146.     /* Fix: we should check config files/environment variables like LANG! */
  147.  
  148.     LoadLang();
  149.     LoadKeyboard();
  150.  
  151.     TitleScreen();
  152.  
  153.     SaveSettings();
  154.  
  155.     LOG( "---GAME DONE, EXIT---- Thank you.\n" );
  156.  
  157.     return EXIT_SUCCESS;
  158. }
  159.