home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / XBD2_SRC.ZIP / XBD2_SRC / XBD.C < prev    next >
C/C++ Source or Header  |  1991-02-10  |  6KB  |  345 lines

  1. /*********************************************/
  2. /* you just keep on pushing my luck over the */
  3. /*          BOULDER        DASH              */
  4. /*                                           */
  5. /*     Jeroen Houttuin, ETH Zurich, 1990     */
  6. /*                                           */
  7. /*                                           */
  8. /*      PC-VGA version from :                */
  9. /*                                           */
  10. /*        Herve SOULARD, Paris, 1990        */
  11. /*                                           */
  12. /*********************************************/
  13.  
  14. #include <stdio.h>
  15. #include <fcntl.h>
  16. #include <io.h>
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <malloc.h>
  20. #include <string.h>
  21. #include <memory.h>
  22. #include <conio.h>
  23. #include <ctype.h>
  24. #include <dos.h>
  25. #include <graph.h>
  26.  
  27. #include "xbd.h"
  28.  
  29.  
  30. char    *getenv();
  31. void (interrupt far *oldVect)();
  32.  
  33. int count = 0;
  34. Bool startCount = FALSE;
  35. Bool newLevel = FALSE;
  36.  
  37. Bool noSound = FALSE;
  38.  
  39.  
  40. void far interrupt newClock()
  41. {
  42.     if (startCount && count)
  43.         count--;
  44.     _chain_intr(oldVect);
  45. }
  46.  
  47.  
  48. Bool kbdHit(void)
  49.     if (*kbdPtrRead == *kbdPtrWrite)
  50.         return(FALSE);
  51.     else
  52.         return(TRUE);
  53. }
  54.  
  55. void getKbd(byte *TT,byte *T)
  56.     *T = *(kbdBuffer + *kbdPtrRead);
  57.     if (*T == 0x00 || *T == 0xE0) {
  58.         *T = *(kbdBuffer + *kbdPtrRead + 1);
  59.         *TT = 'F';
  60.     }
  61.     else
  62.         *TT = 'T';
  63.     *kbdPtrRead += 2;
  64.     if (*kbdPtrRead == 0x3E)
  65.         *kbdPtrRead = 0x1E;
  66. }
  67.  
  68.  
  69. void init_vars()
  70. {
  71.     blobbreak = 100;
  72.     critical = 100;
  73.     blobcells = 0;
  74.     curorder = STAND;
  75.     gamestop = TRUE;
  76.     scoreobs = TRUE;
  77.     stoplevel = FALSE;
  78.     levelnum = 1;
  79.     speed = 1;
  80.     lives = 4;
  81.     xin = 0;
  82.     yin = 0;
  83.     players = 1;
  84. }
  85.  
  86.  
  87. void adapt_timer()
  88. {
  89.     if (speed <= 0)
  90.         speed = 1;
  91.     count = 34 / speed;
  92. }
  93.  
  94.  
  95.  
  96. /* Handle a key stroke by the user. */
  97. void handle_key(byte keytype, byte keyhit)
  98. {
  99.     if (players <= 0) {
  100.         init_level(levelnum);
  101.         adapt_timer();
  102.         stoplevel = FALSE;
  103.         draw_field(TRUE);
  104.         gamestop = TRUE;
  105.         players = 1;
  106.         return;
  107.     }
  108.     if (keytype == 'T') {
  109.         switch (keyhit) {
  110.             case K_SPACE:
  111.                 gamestop = !gamestop;
  112.                 break;
  113.         }
  114.     }
  115.     else {
  116.         switch (keyhit) {
  117.             case K_LEFT:
  118.                 steal = FALSE;
  119.                 curorder = LEFT;
  120.                 gamestop = FALSE;
  121.                 break;
  122.             case K_UP:
  123.                 steal = FALSE;
  124.                 curorder = UP;
  125.                 gamestop = FALSE;
  126.                 break;
  127.             case K_DOWN:
  128.                 steal = FALSE;
  129.                 curorder = DOWN;
  130.                 gamestop = FALSE;
  131.                 break;
  132.             case K_RIGHT:
  133.                 steal = FALSE;
  134.                 curorder = RIGHT;
  135.                 gamestop = FALSE;
  136.                 break;
  137.             case K_CTL_LEFT:
  138.                 steal = TRUE;
  139.                 curorder = LEFT;
  140.                 gamestop = FALSE;
  141.                 break;
  142.             case K_CTL_UP:
  143.                 steal = TRUE;
  144.                 curorder = UP;
  145.                 gamestop = FALSE;
  146.                 break;
  147.             case K_CTL_DOWN:
  148.                 steal = TRUE;
  149.                 curorder = DOWN;
  150.                 gamestop = FALSE;
  151.                 break;
  152.             case K_CTL_RIGHT:
  153.                 steal = TRUE;
  154.                 curorder = RIGHT;
  155.                 gamestop = FALSE;
  156.                 break;
  157.         }
  158.     }
  159. }
  160.  
  161.  
  162. /* Function which is called whenever the timer signal goes off */
  163. void ticker()
  164. {
  165.     startCount = FALSE;
  166.     if (curtime)
  167.         curtime--;
  168.     if (tinkact)
  169.         tinkdur--;
  170.     if (curtime % 10 == 1)
  171.         scoreobs = TRUE;
  172.  
  173.     if (!gamestop) {
  174.         if (newLevel) {
  175.             newLevel = FALSE;
  176.             _clearscreen(_GCLEARSCREEN);
  177.         }
  178.         calculate_field();
  179.         draw_field(0);
  180.     }
  181.     if (stoplevel) {
  182.         init_level(levelnum);
  183.         adapt_timer();
  184.         gamestop = TRUE;
  185.         stoplevel = FALSE;
  186.         newLevel = TRUE;
  187.     }
  188.     adapt_timer();
  189.     startCount = TRUE;
  190. }
  191.  
  192.  
  193.  
  194.  
  195. void main(argc, argv)
  196. int argc;
  197. char **argv;
  198. {
  199.     long        period;
  200.     char        buf[50];
  201.     int        i;
  202.     char        *tmp;
  203.     char        aux[200];
  204.     char        soundName[255];
  205.  
  206.     byte    keyhit;
  207.     byte    keytype;
  208.     
  209.     
  210.     if (tmp = getenv("XBDLIB"))
  211.         strcpy(aux, tmp);
  212.     else
  213.         strcpy(aux, LIB);
  214.  
  215.     init_vars();
  216.  
  217.     /* scan the command line for executing parameters and flags */
  218.     for (i = 1; i < argc; ++i) {
  219.         if (argv[i][0] == '-') {
  220.             switch (argv[i][1]) {
  221.                 case 'l' :
  222.                     if (argv[i][2] == '\0' && i + 1 < argc) {
  223.                         sscanf(argv[i + 1], "%d", &levelnum);
  224.                         i++;    
  225.                     }
  226.                     else
  227.                         sscanf(argv[i] + 2, "%d", &levelnum);
  228.                     break;
  229.                 case 's' :
  230.                     noSound = TRUE;
  231.                     soundDone = FALSE;
  232.                     break;
  233.             }
  234.         }
  235.         else {
  236.             printf("usage: xbd [-l <level>] [-s] \n");
  237.             printf("                              \n");
  238.             printf("       -l = starting level    \n");
  239.             printf("       -s = no digitized sound\n");
  240.             exit(1);
  241.         }
  242.     }
  243.  
  244.     levelstart = levelnum;
  245.     init_level(levelnum);
  246.  
  247.     if (!noSound) {
  248.         strcpy(soundName,aux);
  249.         strcat(soundName,"\\explode");
  250.         readSound(soundName, &sndExplode);
  251.  
  252.         strcpy(soundName,aux);
  253.         strcat(soundName,"\\whizz");
  254.         readSound(soundName, &sndWhizz);
  255.  
  256.         strcpy(soundName,aux);
  257.         strcat(soundName,"\\gameover");
  258.         readSound(soundName, &sndOver);
  259.  
  260.         strcpy(soundName,aux);
  261.         strcat(soundName,"\\yahoo");
  262.         readSound(soundName, &sndYahoo);
  263.     }
  264.  
  265.     oldVect = _dos_getvect(0x1C);
  266.     xstart();
  267.  
  268.     load();
  269.     
  270.     make_gcs();
  271.     _clearscreen(_GCLEARSCREEN);
  272.     draw_field(TRUE);
  273.     draw_score();
  274.  
  275.     /* initialize timer structure according to speed */
  276.     adapt_timer();
  277.  
  278.     startCount = FALSE;
  279.     _dos_setvect(0x1C,newClock);
  280.     
  281.     while (lives > 0) {        /* MAIN LOOP */
  282.         if (!count) 
  283.             ticker();
  284.         if (kbdHit()) {
  285.             getKbd(&keytype,&keyhit);
  286.             if (keytype == 'T') {
  287.                 switch (keyhit) {
  288.                     case K_ESC:
  289.                         if (!noSound) {
  290.                             playSound(sndOver);
  291.                             while (!soundDone);
  292.                         }
  293.                         xend();
  294.                         _dos_setvect(0x1C,oldVect);
  295.                         add_score();
  296.                         if (!noSound) {
  297.                             closeSound(&sndExplode);
  298.                             closeSound(&sndWhizz);
  299.                             closeSound(&sndOver);
  300.                             closeSound(&sndYahoo);
  301.                         }
  302.                         exit(-1);
  303.                         break;
  304.                     case K_D:
  305.                     case K_d:
  306.                         curorder = KILL;
  307.                         break;
  308.                     case K_R:
  309.                     case    K_r:
  310.                         _clearscreen(_GCLEARSCREEN);
  311.                         draw_field(TRUE);
  312.                         break;
  313.                     default:
  314.                         handle_key(keytype,keyhit);
  315.                         break;
  316.                 }
  317.             }
  318.             else
  319.                 handle_key(keytype,keyhit);
  320.         }
  321.         if (!gamestop)
  322.             startCount = TRUE;
  323.     }
  324.  
  325.     if (!noSound) {
  326.         playSound(sndOver);
  327.         while (!soundDone);
  328.     }
  329.  
  330.     xend();
  331.     _dos_setvect(0x1C,oldVect);
  332.     add_score();
  333.  
  334.     if (!noSound) {
  335.         closeSound(&sndExplode);
  336.         closeSound(&sndWhizz);
  337.         closeSound(&sndOver);
  338.         closeSound(&sndYahoo);
  339.     }
  340.     exit(-1);
  341. }
  342.  
  343.