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 / INVADE5.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  3KB  |  141 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;
  15. char k;
  16. int shoot;
  17.  
  18.  
  19. // sprites numbers (So you don't get confused)
  20. // 1    = spaceship
  21. // 2    = missile fired
  22. // 3    = aliens!
  23.  
  24. void looper();
  25. extern spclip;
  26.  
  27. void main(void)
  28. {
  29. printf("WordUp Graphics Toolkit Example Program\n\n");
  30. printf("This program is meant to show off what the\n");
  31. printf("WGT Library can do, and is not meant as a\n");
  32. printf("complete shareware or public domain game.\n");
  33. printf("Please remember this while playing the game.\n\n");
  34. printf("Press q during the game to quit...\n\n\n");
  35.  
  36.  
  37. i=minit();
  38. if (i==0)
  39.    {
  40.    printf("Mouse not detected.  You need a mouse for this example program\n");
  41.    printf("Press any key\n");
  42.    getch();
  43.    exit(1);
  44.    }
  45. else printf("Mouse with %i buttons detected.\n",i);
  46. printf("Press any key\n");
  47. getch();
  48.  
  49. vga256();
  50. title=wloadpak("invade.pak");
  51. wloadsprites(&palette,"invader.spr",sprites);
  52. initspr();
  53. spon=24;                // twenty four sprites on now
  54.  
  55. wsetscreen(spritescreen);
  56.  
  57. wputblock(0,0,title,0);
  58. wcopyscreen(0,0,319,199,spritescreen,0,0,NULL);
  59.  
  60. getch();
  61.  
  62. wsetcolor(0);
  63. wbar(0,0,319,140);
  64. wcopyscreen(0,0,319,199,spritescreen,0,0,NULL);
  65.  
  66. spriteon(1,160,148,1);
  67.  
  68. for (y=0; y<3; y++)
  69.   for (x=1; x<8; x++)
  70.     {
  71.     spriteon((y*7)+x+2,x*20+10,20+y*30,3);            // turn alien on
  72.     animate((y*7)+x+2,"(3,3)(4,3)(5,3)(4,3)R");            // animate it
  73.     animon((y*7)+x+2);
  74.     movex((y*7)+x+2,"(1,150,0)(0,30,0)(-1,150,0)(0,30,0)R");     // set up x movement
  75.     movey((y*7)+x+2,"(0,150,0)(1,30,0)(0,150,0)(-1,30,0)R");    // set up y movement
  76.     movexon((y*7)+x+2);
  77.     moveyon((y*7)+x+2);
  78.     }
  79.  
  80.  
  81.  
  82. msetbounds(0,148,319,148);
  83.  
  84. do {
  85. looper();
  86. } while (k !='Q');
  87.  
  88. msetbounds(0,0,319,199);
  89. textmode(C80);
  90. }
  91.  
  92.  
  93. void looper(void)
  94. {
  95. erasespr();
  96.  
  97. mread();
  98. s[1].x=mx;
  99. s[1].y=my;
  100.  
  101. if (but==1)                // if you pressed the left button
  102.   {
  103.     if (shoot==0)            // not shooting then
  104.       {
  105.       spriteon(2,s[1].x+3,s[1].y,2);    // turn on the missile sprite
  106.       movey(2,"(-2,200,0)");          // make it move up
  107.       moveyon(2);            // turn the movement on
  108.       shoot=1;
  109.       }
  110.   }
  111.  
  112.   for (y=0; y<3; y++)            // loop through all aliens
  113.     for (x=1; x<8; x++)
  114.      {
  115.      if (s[(y*7)+x+2].on !=0)        // if you haven't hit it yet
  116.      {
  117.      if (overlap(2,(y*7)+x+2)==1)       // and your missile is hitting it
  118.     {
  119.     spriteoff(2);            // turn off the missile
  120.     shoot=0;            // not shooting anymore
  121.     animate((y*7)+x+2,"(6,5)(7,5)(8,5)(9,5)(10,5)");  // show explosion
  122.     animon((y*7)+x+2);                   // reset animation
  123.     }
  124.      if (s[(y*7)+x+2].num==10)        // if finished animating,
  125.      spriteoff((y*7)+x+2);        // turn off the sprite
  126.        }
  127.      }
  128.  
  129.  
  130. if (s[2].y<-10)
  131.   shoot=0;
  132.  
  133. if (kbhit())
  134.    k=toupper(getch());            // convert to uppercase letter
  135. drawspr();
  136.  
  137.  
  138.  
  139. }
  140.  
  141.