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