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 / INVADE6.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  4KB  |  172 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <ctype.h>
  7. #include <wgt.h>
  8. #include <spr.h>
  9.  
  10. block title;
  11.  
  12. color palette[256];
  13. block sprites[201];
  14. int x,y,i,ops;
  15. char k;
  16. int shoot;
  17. int alshoot[15],totshoot;
  18.  
  19.  
  20. // sprites numbers (So you don't get confused)
  21. // 1    = spaceship
  22. // 2    = missile fired
  23. // 3-24 = aliens!
  24. // 25-39= aliens missiles
  25.  
  26. void looper();
  27.  
  28. void main(void)
  29. {
  30. printf("WordUp Graphics Toolkit Example Program\n\n");
  31. printf("This program is meant to show off what the\n");
  32. printf("WGT Library can do, and is not meant as a\n");
  33. printf("complete shareware or public domain game.\n");
  34. printf("Please remember this while playing the game.\n\n");
  35. printf("Press q during the game to quit...\n\n\n");
  36.  
  37.  
  38. i=minit();
  39. if (i==0)
  40.    {
  41.    printf("Mouse not detected.  You need a mouse for this example program\n");
  42.    printf("Press any key\n");
  43.    getch();
  44.    exit(1);
  45.    }
  46. else printf("Mouse with %i buttons detected.\n",i);
  47. printf("Press any key\n");
  48. getch();
  49.  
  50. vga256();
  51. title=wloadpak("invade.pak");
  52. wloadsprites(&palette,"invader.spr",sprites);
  53. initspr();
  54. spon=39;                // thirty nine sprites on now
  55. spclip=1;
  56.  
  57. wsetscreen(spritescreen);
  58.  
  59. wputblock(0,0,title,0);
  60. wcopyscreen(0,0,319,199,spritescreen,0,0,NULL);
  61.  
  62. getch();
  63.  
  64. wsetcolor(0);
  65. wbar(0,0,319,140);
  66. wcopyscreen(0,0,319,199,spritescreen,0,0,NULL);
  67.  
  68. spriteon(1,160,148,1);
  69.  
  70. for (y=0; y<3; y++)
  71.   for (x=1; x<8; x++)
  72.     {
  73.     spriteon((y*7)+x+2,x*20+10,20+y*30,3);            // turn alien on
  74.     animate((y*7)+x+2,"(3,3)(4,3)(5,3)(4,3)R");            // animate it
  75.     animon((y*7)+x+2);
  76.     movex((y*7)+x+2,"(1,150,0)(0,30,0)(-1,150,0)(0,30,0)R");     // set up x movement
  77.     movey((y*7)+x+2,"(0,150,0)(1,30,0)(0,150,0)(-1,30,0)R");    // set up y movement
  78.     movexon((y*7)+x+2);
  79.     moveyon((y*7)+x+2);
  80.     }
  81.  
  82.  
  83.  
  84. msetbounds(0,148,319,148);
  85.  
  86. do {
  87. looper();
  88. } while (k !='Q');
  89.  
  90. msetbounds(0,0,319,199);
  91. textmode(C80);
  92. }
  93.  
  94.  
  95. void looper(void)
  96. {
  97. erasespr();
  98.  
  99. mread();
  100. s[1].x=mx;
  101. s[1].y=my;
  102.  
  103. if (but==1)                // if you pressed the left button
  104.   {
  105.     if (shoot==0)            // not shooting then
  106.       {
  107.       sound(600);
  108.       spriteon(2,s[1].x+3,s[1].y,2);    // turn on the missile sprite
  109.       movey(2,"(-2,200,0)");          // make it move up
  110.       moveyon(2);            // turn the movement on
  111.       shoot=1;
  112.       }
  113.   }
  114.  
  115.   for (y=0; y<3; y++)            // loop through all aliens
  116.     for (x=1; x<8; x++)
  117.      {
  118.      if (s[(y*7)+x+2].on !=0)        // if you haven't hit it yet
  119.      {
  120.      if ((rand() % 50==5) & (totshoot <13))    // 1 in 50 chance of shooting
  121.        {                // cannot shoot more than 14 at once
  122.                     // since we can only have 40 sprites
  123.        ops=1;
  124.        i=1;
  125.     do {
  126.      if (alshoot[i]==0)        // find an open slot for missile
  127.        ops=i;
  128.      i++;
  129.      } while (i<14);
  130.  
  131.        alshoot[ops]=1;
  132.        totshoot++;
  133.        spriteon(ops+24,s[(y*7)+x+2].x+4,s[(y*7)+x+2].y,2); // turn shot on
  134.        movey(ops+24,"(1,160,0)");            // move it down
  135.        moveyon(ops+24);
  136.        }
  137.  
  138.      if (overlap(2,(y*7)+x+2)==1)       // and your missile is hitting it
  139.     {
  140.     sound(200);
  141.     spriteoff(2);            // turn off the missile
  142.     shoot=0;            // not shooting anymore
  143.     animate((y*7)+x+2,"(6,5)(7,5)(8,5)(9,5)(10,5)");  // show explosion
  144.     animon((y*7)+x+2);                   // reset animation
  145.     }
  146.      if (s[(y*7)+x+2].num==10)        // if finished animating,
  147.      spriteoff((y*7)+x+2);        // turn off the sprite
  148.        }
  149.      }
  150.  
  151.  
  152. for (y=1; y<15; y++)
  153.   {
  154.   if (s[y+24].y>154)
  155.      {
  156.      alshoot[y]=0;
  157.      spriteoff(y+24);
  158.      totshoot--;
  159.      }
  160.   }
  161.  
  162.  
  163. if (s[2].y<-10)
  164.   shoot=0;
  165.  
  166. if (kbhit())
  167.    k=toupper(getch());            // convert to uppercase letter
  168. drawspr();
  169. nosound();
  170. }
  171.  
  172.