home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WGT_TC21.ZIP / MISSILE.C < prev    next >
C/C++ Source or Header  |  1992-07-17  |  5KB  |  288 lines

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