home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / w / wgt3_ex.zip / MISSILE.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  5KB  |  289 lines

  1. // missile command type game
  2. // REQUIRES MOUSE!
  3. #include <alloc.h>
  4. #include <mem.h>
  5. #include <conio.h>
  6. #include <dos.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9. #include "wgt.h"
  10.  
  11. #define true 1;
  12. #define down 1
  13. #define left 2
  14. #define right 3
  15. #define vertical 0
  16. #define horizontal 1
  17.  
  18. color palette[255];
  19. int tone;
  20. void so(void);
  21. void init(void);
  22. void changepalette256(void);
  23.  
  24.    unsigned cursor[32] = {
  25.     0xfe3f,0xfe3f,0xfe3f,0xfe3f,0xfe3f,0xfe3f,0x81c0,0x81c0,
  26.     0x81c0,0xfe3f,0xfe3f,0xfe3f,0xfe3f,0xfe3f,0xfe3f,0xffff,
  27.     0x0,0x80,0x80,0x80,0x80,0x0,0x0,0x3c1e,
  28.     0x0,0x0,0x80,0x80,0x80,0x80,0x0,0x0};
  29. block chunk,build,base,noth;
  30. block mouses;
  31. int oldx,oldy;
  32. int i,a,sc,j;
  33. int ex[31],exx[31],exy[31];
  34. int sx[501],sy[501],dx[501];
  35. int maxs=30,level=5,chk,hits,shoot;
  36. int baseh[3];
  37. int buildh[20];
  38. char ans;
  39.  
  40.  
  41. void main(void)
  42. {
  43.  do {
  44. init();
  45.  
  46. msetspeed(6,6);
  47. msetthreshhold(40);
  48. wnormscreen();
  49.     do {
  50.     so();
  51.     shoot=0;
  52.  
  53.     sc=0;
  54.     wsetscreen(chunk);
  55.     for (i=0; i<50; i++)        // clears top of screen
  56.       {
  57.       wsetcolor(i);
  58.       wbar(0,sc,319,sc+3);
  59.       sc+=3;
  60.       }
  61.  
  62.     mread();
  63.  
  64.     moff();
  65.      if ((but==1) & (baseh[0]==1))
  66.        {
  67.       wline(20,149,mx,my);
  68.       shoot=1;
  69.       }
  70.      else if ((but==2) & (baseh[1]==1))
  71.       {
  72.       wline(305,149,mx,my);
  73.       shoot=1;
  74.       }
  75.      i=0;
  76.      do {
  77.      if (ex[i]==0) {
  78.       if (shoot ==1) {
  79.       ex[i]=14;
  80.       exx[i]=mx;
  81.       exy[i]=my;
  82. // shoot snd
  83.     tone=600;
  84.     so();
  85.       i=7;}
  86.       }
  87.       else {
  88.        ex[i]--;
  89.        wsetcolor(128+ex[i]*4);
  90.        wfill_circle(exx[i],exy[i],ex[i]);
  91.     tone=ex[i]*20;
  92.     so();
  93.        }
  94.       i++;
  95.       } while (i<maxs);
  96.  
  97.      i=0;
  98.      do {
  99.      if ((sy[i]<1) & (rand() % 30==5))
  100.        {
  101.        sy[i]=1;
  102.        sx[i]=rand() % 300;
  103.        dx[i]=(rand() % 6)-3;
  104.        }
  105.      else if (sy[i]>0)
  106.        {
  107.        sy[i]+=2;
  108.        sx[i]+=dx[i];
  109.        if (sx[i]>317)
  110.          sx[i]=0;
  111.        if (sx[i]<0)
  112.          sx[i]=317;
  113.        wsetcolor(90);
  114.        chk=wgetpixel(sx[i],sy[i]);
  115.        wbar(sx[i],sy[i],sx[i]+1,sy[i]+1);
  116.        if ((sy[i]>149) | (chk>127))
  117.           {
  118.           if (sy[i]>149)
  119.         {
  120.         if ((sx[i]>10) & (sx[i]<30) & (baseh[0]==1))
  121.           {  // hit base 1
  122.           wnormscreen();
  123.           wputblock(10,150,noth,0);
  124.           wputblock(20,150,noth,0);
  125.           wsetscreen(chunk);
  126.           baseh[0]=0;
  127. // hit snd
  128.     tone=800;
  129.     so();
  130.           }
  131.         if ((sx[i]>300) & (sx[i]<320) & (baseh[1]==1))
  132.           {     // hit base 2
  133.           wnormscreen();
  134.           wputblock(295,150,noth,0);
  135.           wputblock(305,150,noth,0);
  136.           wsetscreen(chunk);
  137.           baseh[1]=0;
  138. // hit snd
  139.     tone=800;
  140.     so();
  141.           }
  142.         for (j=1; j<15; j++)
  143.         {  // check building hits
  144.         chk=j*17+40;
  145.         if ((sx[i]>chk) & (sx[i]<chk+10) & (buildh[j-1]==1))
  146.           {
  147.           wnormscreen();
  148.           wputblock(j*17+40,150,noth,0);
  149.           wsetscreen(chunk);
  150.           buildh[j-1]=0;
  151.           hits++;
  152. // hit snd
  153.     tone=800;
  154.     so();
  155.           }
  156.         }
  157.         }
  158.           sy[i]=-10;
  159. // explo snd
  160.     tone=300;
  161.     so();
  162.         }
  163.        }
  164.      i++;
  165.      } while (i<level);
  166.  
  167.  
  168.     wcopyscreen(0,0,319,149,chunk,0,0,NULL);
  169.      mon();
  170.      } while (!kbhit());
  171.    nosound();
  172.    getch();
  173.      wnormscreen();
  174.      wfreeblock(chunk);
  175.      wfreeblock(build);
  176.      wfreeblock(base);
  177.      wfreeblock(noth);
  178.     moff();
  179.     textmode(C80);
  180.    window(1,1,80,24);
  181.    gotoxy(1,1);
  182.    printf("Play again? (Y/N) ");
  183.    scanf("%s",&ans);
  184.  } while ((ans !='n') & (ans !='N'));
  185. }
  186.  
  187. void changepalette256(void)
  188. {
  189.   wsetrgb(0,0,0,0,&palette);
  190.  
  191.   for (i=1; i<64; i++) 
  192.        wsetrgb(i,0,63-i,63-i/2,&palette);
  193.   for (i=64; i<128; i++) 
  194.        wsetrgb(i,127-i,127-i,127-i,&palette);
  195.   for (i=128; i<192; i++) 
  196.        wsetrgb(i,i-127,(i-127)/2,0,&palette);
  197.   for (i=192; i<256; i++) 
  198.        wsetrgb(i,63,63,i-192,&palette);
  199.  wsetpalette(0,255,palette);
  200. }
  201.  
  202. void init()
  203. {
  204. vga256();
  205. minit();
  206. mon();
  207. mouseshape(8,7,cursor);
  208. randomize();
  209. changepalette256();
  210. wcls(0);
  211.    window(1,1,80,24);
  212.    gotoxy(1,1);
  213.    printf("Start at what level? ");
  214.    scanf("%d",&level);
  215.  
  216.     for (i=1; i<11; i++)
  217.     {
  218.     wsetcolor(i+74);
  219.     wline(i,0,i,9);
  220.     }
  221.     wsetcolor(0);
  222.     wbar(3,1,4,2);
  223.     wbar(6,1,7,2);
  224.     wbar(3,4,4,5);
  225.     wbar(6,4,7,5);
  226.     wbar(8,6,9,9);
  227.     build=wnewblock(1,0,10,9);
  228.     wcls(0);
  229.  
  230.     for (i=150; i<160; i++)
  231.       {
  232.       wsetcolor(i/3);
  233.       wline(0,i-150,319,i-150);
  234.       }
  235.     noth=wnewblock(0,0,9,9);
  236.     for (i=10; i>0; i--)
  237.      {
  238.      wsetcolor(80+i);
  239.     wfill_circle(10,10,i);
  240.     }
  241.     base=wnewblock(0,0,20,10);
  242.     wcls(0);
  243.  
  244.     for (i=150; i<160; i++)
  245.       {
  246.       wsetcolor(i/3);
  247.       wline(0,i,319,i);
  248.       }
  249.     wputblock(10,150,base,0);
  250.     wputblock(295,150,base,0);
  251.     baseh[0]=1;
  252.     baseh[1]=1;
  253.  
  254.     wsetcolor(74);
  255.     for (i=1; i<15; i++)
  256.     {
  257.     wputblock(i*17+40,150,build,0);
  258.     buildh[i-1]=1;
  259.         }
  260.     for (i=160; i<200; i++)
  261.       {
  262.       wsetcolor(i-86);
  263.       wline(0,i,319,i);
  264.       }
  265.  
  266.     chunk=wnewblock(0,0,319,199);
  267.     wsetscreen(chunk);
  268.  
  269.     sc=0;
  270.     for (i=1; i<50; i++)
  271.       {
  272.       wsetcolor(sc);
  273.       wbar(0,sc,319,sc+3);
  274.       sc+=3;
  275.       }
  276. }
  277.  
  278. void so()
  279. {
  280. if (tone>100)
  281.  {
  282. sound(tone);
  283.  tone-=100;
  284.  }
  285. if (tone<105)
  286. nosound();
  287. }
  288.  
  289.