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 / WGT20.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  5KB  |  189 lines

  1. #include <alloc.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <wgt.h>
  7. #include <spr.h>
  8.  
  9. /*   WORDUP Graphics Toolkit   Version 3.0
  10.      Demonstration program 20
  11.  
  12.   This program uses the same sprites as last time but
  13.   this time in a shoot-em-up game.
  14.   Now that you've seen this one, get ready for some larger
  15.   scale examples of animation and sprites!
  16.  
  17.  
  18. */
  19.  
  20. // Large example demonstrating many functions from WGT 
  21.  
  22. void scrolldown(void);        // scroll the screen down
  23. void credits(void);
  24. void changepalette256(void);
  25. void l(void);
  26.  
  27.  
  28. block scr,scr2;
  29. block sprites[201];
  30.  
  31. int shoot[10],sx[10],sy[10];
  32.  
  33. int cd;
  34. int i,scrll=1;                          // scrll is ctr for offset
  35. int ix=30,iy=0,ix2=250,iy2=199;        // coords of scrolling area
  36. int speed=-1;                 // the scrolling speed
  37.                     // try changing speed and sign
  38. color palette[256];
  39.  
  40.  
  41. void main(void)
  42. {
  43. vga256();                    // init
  44. minit();
  45. moff();
  46. wsetpalette(0,255,&palette);
  47. credits();
  48. wloadsprites(&palette,"space.spr",sprites);        // load sprites
  49.  
  50. scr=wnewblock(0,0,319,199);            // get two virtual screens
  51. scr2=wnewblock(0,0,319,199);
  52. wsetscreen(scr2);                // go to second one
  53. wcls(0);                    // clear it
  54. for (i=1; i<300; i++)                // put some stars on (small)
  55.   wputblock(rand() % 320,rand() % 200,sprites[3],0);   // sprite[3] is small stars
  56.  
  57. for (i=1; i<5; i++)
  58.   wputblock(rand() % 320,rand() % 200,sprites[4],0);   // sprite[4] is large ones
  59.  
  60. wnormscreen();                    // go back to normal screen
  61. wcls(0);                    // clear it
  62. wbutt(0,0,29,199);                // make some side panels
  63. wbutt(252,0,319,199);
  64. my=0;
  65. wsetscreen(scr);                // go to first screen
  66. noclick();
  67. speed=-1;
  68. do {
  69. mread();                    // read mouse
  70.  
  71. scrolldown();                    // scroll the second
  72.                         // screen by copying it to
  73.                         // a different offset on
  74.                         // screen one
  75.  
  76. if (but==1) {                // if you clicked the mouse
  77.  i=0;                                   // set counter to 0
  78.  do {
  79.  if (shoot[i]==0)            // check to see if slot available
  80.     {
  81.     sound(100);                // yes, then make a sound
  82.     shoot[i]=1;                // make it unavailable
  83.     sx[i]=mx+7;                // set coords for shot
  84.     sy[i]=my-7;
  85.     i=9;                // end the loop
  86.     }
  87.  i++;                // otherwise look at the next slot
  88.  } while (i<9);            // can shoot 9 at once
  89.  }
  90.  
  91.  for (i=0; i<9; i++)        // if shot is active
  92.     {
  93.     if (shoot[i]==1)        // then show the sprite
  94.        {
  95.        wputblock(sx[i],sy[i],sprites[2],0);    // at the right coords
  96.        sy[i]-=6;                // make it go up
  97.        if (sy[i]<1)          // if it is at top,
  98.       shoot[i]=0;          // make it available again
  99.        }
  100.     }
  101. wcopyscreen(ix,iy,ix2,iy2,scr,ix,iy,NULL);    // copy the first screen
  102.                         // to the base screen
  103.  nosound();
  104. } while (!kbhit());            // until right button is pressed
  105. wfreeblock(scr);
  106. wfreeblock(scr2);
  107. wfreesprites(sprites);
  108. textmode(C80);
  109. }
  110.  
  111.  
  112.  
  113. void scrolldown(void)
  114. {
  115. // With a bit of work, you could make this routine scroll in
  116. // four directions and make new graphics come on as it scrolls!
  117. // Of course, we've already gone and done that for you! Check out wgt4scr.lib
  118. wcopyscreen(ix,scrll,ix2,iy2,scr2,ix,iy,scr);          // You may understand
  119. wcopyscreen(ix,iy,ix2,scrll,scr2,ix,iy2-scrll,scr);   // this if you think
  120.                               // hard enough!
  121.                               // Don't worry about
  122.                               // it for now!
  123. wputblock(mx,my,sprites[1],1);
  124. scrll+=speed;
  125. if ((scrll<iy) & (speed<0))
  126.   scrll=iy2+1-abs(scrll);
  127. if ((scrll>iy2) & (speed>0))
  128.   scrll=abs(iy2-scrll);
  129. }
  130.  
  131. void credits(void)
  132. {
  133. wnormscreen();
  134. wtextcolor(1);
  135. wtextbackground(0);
  136.  
  137. cd=2;
  138. // draw a pattern on the screen
  139. for (i=0; i<320; i++) { l(); wsetcolor(cd);  wline(160,100,i,0);  }
  140. for (i=0; i<200; i++) { l(); wsetcolor(cd);  wline(160,100,319,i);}
  141. for (i=319; i>=0; i--) { l(); wsetcolor(cd);  wline(160,100,i,199);}
  142. for (i=199; i>=0; i--) { l(); wsetcolor(cd);  wline(160,100,0,i);  }
  143.  
  144.  
  145. changepalette256();
  146.  
  147. wouttextxy(50,20,"Shoot 'Em Up Sprite Example",NULL);
  148. wouttextxy(50,28,"Showing what YOU could do with",NULL);
  149. wouttextxy(50,36,"the WordUp Graphics Toolkit!",NULL);
  150. wouttextxy(50,44,"Use mouse to move, button shoots",NULL);
  151. wouttextxy(50,52,"Press any key to start",NULL);
  152. wsetrgb(1,63,63,63,&palette);
  153. wfade_in(0,255,1,palette);
  154. do {
  155.   wcolrotate(2,255,0,palette);
  156.   } while (!kbhit());
  157.  
  158. getch();
  159. wcls(0);
  160. }
  161.  
  162. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. // change the palette to the right colours
  164. void changepalette256(void)
  165. {
  166.   wsetrgb(0,0,0,0,&palette);
  167.  
  168.   for (i=2; i<64; i++) 
  169.        wsetrgb(i,i,0,0,&palette);
  170.   for (i=64; i<128; i++) 
  171.        wsetrgb(i,127-i,0,0,&palette);
  172.   for (i=128; i<192; i++) 
  173.        wsetrgb(i,0,0,i-128,&palette);
  174.   for (i=192; i<256; i++) 
  175.        wsetrgb(i,0,0,256-i,&palette);
  176.  wsetrgb(253,60,60,60,&palette);
  177.  wsetrgb(254,45,45,45,&palette);
  178.  wsetrgb(255,30,30,30,&palette);
  179.  wsetrgb(1,63,63,63,&palette);
  180. // wsetpalette(0,255,palette);
  181. }
  182.  
  183. void l(void)
  184. {
  185. cd++;
  186. if (cd>127)
  187.   cd=2;
  188. }
  189.