home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume11 / pc-xbd / part01 / xbd.c < prev    next >
C/C++ Source or Header  |  1990-12-17  |  5KB  |  284 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 <conio.h>
  16. #include <ctype.h>
  17. #include <dos.h>
  18. #include <graph.h>
  19.  
  20. #include "xbd.h"
  21.  
  22.  
  23.  
  24. void (interrupt far *oldVect)();
  25.  
  26. int count = 0;
  27. Bool startCount = FALSE;
  28. Bool newLevel = FALSE;
  29.  
  30.  
  31. void far interrupt newClock()
  32. {
  33.     if (startCount && count)
  34.         count--;
  35.     _chain_intr(oldVect);
  36. }
  37.  
  38.  
  39. Bool kbdHit(void)
  40.     if (*kbdPtrRead == *kbdPtrWrite)
  41.         return(FALSE);
  42.     else
  43.         return(TRUE);
  44. }
  45.  
  46. void getKbd(byte *TT,byte *T)
  47.     *T = *(kbdBuffer + *kbdPtrRead);
  48.     if (*T == 0x00 || *T == 0xE0) {
  49.         *T = *(kbdBuffer + *kbdPtrRead + 1);
  50.         *TT = 'F';
  51.     }
  52.     else
  53.         *TT = 'T';
  54.     *kbdPtrRead += 2;
  55.     if (*kbdPtrRead == 0x3E)
  56.         *kbdPtrRead = 0x1E;
  57. }
  58.  
  59.  
  60. void init_vars()
  61. {
  62.     blobbreak = 100;
  63.     critical = 100;
  64.     blobcells = 0;
  65.     curorder = STAND;
  66.     gamestop = TRUE;
  67.     scoreobs = TRUE;
  68.     stoplevel = FALSE;
  69.     levelnum = 1;
  70.     speed = 1;
  71.     lives = 4;
  72.     xin = 0;
  73.     yin = 0;
  74.     players = 1;
  75. }
  76.  
  77.  
  78. void adapt_timer()
  79. {
  80.     if (speed <= 0)
  81.         speed = 1;
  82.     count = 34 / speed;
  83. }
  84.  
  85.  
  86.  
  87. /* Handle a key stroke by the user. */
  88. void handle_key(byte keytype, byte keyhit)
  89. {
  90.     if (players <= 0) {
  91.         init_level(levelnum);
  92.         adapt_timer();
  93.         stoplevel = FALSE;
  94.         draw_field(TRUE);
  95.         gamestop = TRUE;
  96.         players = 1;
  97.         return;
  98.     }
  99.     if (keytype == 'T') {
  100.         switch (keyhit) {
  101.             case K_SPACE:
  102.                 gamestop = !gamestop;
  103.                 break;
  104.         }
  105.     }
  106.     else {
  107.         switch (keyhit) {
  108.             case K_LEFT:
  109.                 curorder = LEFT;
  110.                 gamestop = FALSE;
  111.                 break;
  112.             case K_UP:
  113.                 curorder = UP;
  114.                 gamestop = FALSE;
  115.                 break;
  116.             case K_DOWN:
  117.                 curorder = DOWN;
  118.                 gamestop = FALSE;
  119.                 break;
  120.             case K_RIGHT:
  121.                 curorder = RIGHT;
  122.                 gamestop = FALSE;
  123.                 break;
  124.         }
  125.     }
  126. }
  127.  
  128.  
  129. /* Function which is called whenever the timer signal goes off */
  130. void ticker()
  131. {
  132.     startCount = FALSE;
  133.     if (curtime)
  134.         curtime--;
  135.     if (tinkact)
  136.         tinkdur--;
  137.     if (curtime % 10 == 1)
  138.         scoreobs = TRUE;
  139.  
  140.     if (!gamestop) {
  141.         if (newLevel) {
  142.             newLevel = FALSE;
  143.             _clearscreen(_GCLEARSCREEN);
  144.         }
  145.         calculate_field();
  146.         draw_field(0);
  147.     }
  148.     if (stoplevel) {
  149.         init_level(levelnum);
  150.         adapt_timer();
  151.         gamestop = TRUE;
  152.         stoplevel = FALSE;
  153.         newLevel = TRUE;
  154.     }
  155.     adapt_timer();
  156.     startCount = TRUE;
  157. }
  158.  
  159.  
  160.  
  161.  
  162. void main(argc, argv)
  163. int argc;
  164. char **argv;
  165. {
  166.     long        period;
  167.     char        buf[50];
  168.     int        i;
  169.  
  170.     byte    keyhit;
  171.     byte    keytype;
  172.     
  173.     init_vars();
  174.  
  175.     /* scan the command line for executing parameters and flags */
  176.     for (i = 1; i < argc; ++i) {
  177.         if (argv[i][0] == '-') {
  178.             if (argv[i][1] == 'l') {
  179.                 if (argv[i][2] == '\0' && i + 1 < argc) {
  180.                     sscanf(argv[i + 1], "%d", &levelnum);
  181.                     i++;    
  182.                 } 
  183.                 else
  184.                     sscanf(argv[i] + 2, "%d", &levelnum);
  185.             } 
  186.             else {
  187.                 printf("usage: xbd [-l <level>] \n");
  188.                 exit(1);
  189.             }
  190.         }
  191.     }
  192.  
  193.     levelstart = levelnum;
  194.     init_level(levelnum);
  195.  
  196.     oldVect = _dos_getvect(0x1C);
  197.     xstart();
  198.  
  199.     load();
  200.     
  201.     make_gcs();
  202.     _clearscreen(_GCLEARSCREEN);
  203.     draw_field(TRUE);
  204.     draw_score();
  205.  
  206.     /* initialize timer structure according to speed */
  207.     adapt_timer();
  208.  
  209.     startCount = FALSE;
  210.     _dos_setvect(0x1C,newClock);
  211.     
  212.     while (lives > 0) {        /* MAIN LOOP */
  213.         if (!count) 
  214.             ticker();
  215.         if (kbdHit()) {
  216.             getKbd(&keytype,&keyhit);
  217.             if (keytype == 'T') {
  218.                 switch (keyhit) {
  219.                     case K_ESC:
  220.                         xend();
  221.                         _dos_setvect(0x1C,oldVect);
  222.                         add_score();
  223.                         exit(-1);
  224.                         break;
  225.                     case K_D:
  226.                     case K_d:
  227.                         curorder = KILL;
  228.                         break;
  229.                     case K_R:
  230.                     case    K_r:
  231.                         _clearscreen(_GCLEARSCREEN);
  232.                         draw_field(TRUE);
  233.                         break;
  234.                     default:
  235.                         handle_key(keytype,keyhit);
  236.                         break;
  237.                 }
  238.             }
  239.             /*
  240.                 Handle of CTRL key is to be done
  241.                 
  242.             if ((*kbdStatus & 0x0F) == CTL_SHIFT) {
  243.                 steal = TRUE;
  244.                 if (keytype == 'T') {
  245.                     switch (keyhit) {
  246.                         case K_C:
  247.                         case K_U:
  248.                         case K_c:
  249.                         case K_u:
  250.                             xend();
  251.                             _dos_setvect(0x1C,oldVect);
  252.                             add_score();
  253.                             exit(-1);
  254.                             break;
  255.                         case K_D:
  256.                         case K_d:
  257.                             curorder = KILL;
  258.                         case K_R:
  259.                         case    K_r:
  260.                             draw_field(TRUE);
  261.                             break;
  262.                         default:
  263.                             handle_key(keytype,keyhit);
  264.                             break;
  265.                     }
  266.                 }
  267.             }
  268.             */
  269.             else
  270.                 handle_key(keytype,keyhit);
  271.         }
  272.         if (!gamestop)
  273.             startCount = TRUE;
  274.     }
  275.     xend();
  276.     _dos_setvect(0x1C,oldVect);
  277.     add_score();
  278.     exit(-1);
  279. }
  280.  
  281.  
  282.