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 / FLY.C < prev    next >
C/C++ Source or Header  |  1992-09-15  |  3KB  |  160 lines

  1. #include <conio.h>
  2. #include "wgt.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6.  
  7. color p[256];
  8. int back[21];
  9. int starx[20],stary[20];
  10. int i,y,bottom,c,ctr,c2;
  11. int speed=5,ofs=0;
  12. block sc;
  13. block sprites[201];
  14. int numg;
  15. int ox,turns,turn=5;
  16. int shootx[20],shooty[20],shootoy[20],shooton[20],numshots=0;
  17.  
  18.  
  19. void resizepill(int);
  20. void setupground(void);
  21.  
  22. void main(void)
  23. {
  24. vga256();
  25. wloadsprites(&p,"fly.spr",sprites);
  26. sc=wnewblock(0,0,319,199);
  27. resizepill(19);
  28. resizepill(29);
  29. resizepill(39);
  30. minit();
  31.  
  32. setupground();
  33.  wbutt(0,0,319,50);
  34. wsetscreen(sc);
  35. y=0;
  36.  
  37.  wsetcolor(0);
  38.  wbar(0,0,319,50);
  39. do {
  40. mread();
  41.  
  42.     if ((but==1) & (numshots<19))  // shoot with left mouse button
  43.     {
  44.     for (i=0; i<20; i++)
  45.       {
  46.       if (shooton[i]==0)
  47.     {
  48.     sound(300);
  49.     shootx[i]=mx+24;
  50.     shooty[i]=180;
  51.     shootoy[i]=my+7;
  52.     shooton[i]=1;
  53.     numshots++;
  54.     break;
  55.     }
  56.       }
  57.     }
  58.  
  59.  wsetcolor(0);
  60.  wbar(0,0,319,50);
  61.  wsetcolor(17);
  62.  wbar(0,50,319,150);
  63. nosound();
  64. for (i=0; i<20; i++)
  65.    {
  66.    starx[i]-=(turn-5)*2;
  67.    if (starx[i]<0) starx[i]=319;
  68.    else if (starx[i]>319) starx[i]=0;
  69.    shootx[i]-=(turn-5)*4;
  70.    if (shootx[i]<0) shootx[i]=319;
  71.    else if (shootx[i]>319) shootx[i]=0;
  72.    wsetcolor(1);
  73.    wfastputpixel(starx[i],stary[i]);
  74.    }
  75.  
  76. for (i=numg; i>=0; i--)
  77.  {
  78.  c2=(float)((float)back[i]/(600-back[i]))*back[i];
  79.  c=back[i]/30;
  80.  if (c2<100)
  81.  {
  82.  wsetcolor(12);
  83.  wbar(0,50+c2,319,c2+c+50);
  84.  }
  85.  back[i]+=speed;
  86.  if (back[i]>200)
  87.       back[i]=back[i]-200;
  88.  }
  89.  
  90. turns=(mx-ox)/5;
  91. if (turns==0)
  92.    {
  93.    if (turn<5) turn++;
  94.    if (turn>5) turn--;
  95.    }
  96. if (turns<0) turn--;
  97. if (turns>0) turn++;
  98.  
  99. if (turn<1) turn=1;
  100. if (turn>9) turn=9;
  101.  for (i=0; i<20; i++)
  102.    {
  103.    if (shooton[i]==1)
  104.       {
  105.       shooty[i]-=10;
  106.       if (shooty[i]<0)
  107.      {
  108.      shooton[i]=0;
  109.      shooty[i]=0;
  110.      numshots--;
  111.      }
  112.       }
  113.    }
  114. wputblock(mx,105,sprites[turn+9],1);
  115.  for (i=0; i<20; i++)
  116.    {
  117.    if (shooton[i]==1)
  118.       wputblock(shootx[i],(float)((float)shooty[i]/(600-shooty[i]))*shooty[i]+shootoy[i]-50,sprites[38-(shooty[i]/20)],1);
  119.    }
  120. wputblock(mx,my,sprites[turn],1);
  121. ox=mx;
  122. wcopyscreen(0,0,319,150,sc,0,50,NULL);
  123. } while (but !=2);
  124. wfreeblock(sc);
  125. textmode(C80);
  126. }
  127.  
  128. void setupground(void)
  129. {
  130. for (i=0; i<21; i++)
  131.    back[i]=i*15;
  132. i=0;
  133.  
  134. numg=12;
  135.  
  136. for (i=0; i<20; i++)
  137.  {
  138.  starx[i]=rand() % 319;
  139.  stary[i]=rand() % 50;
  140.  }
  141. }
  142.  
  143.  
  144. void resizepill(int num)
  145. {
  146. int g,h,nx,ny;
  147.  
  148. g=wgetblockwidth(sprites[num]);
  149. h=wgetblockheight(sprites[num]);
  150.  
  151. for (i=9; i>=1; i--)
  152.   {
  153.   wcls(0);
  154.   nx=(float)i/10*g;
  155.   ny=(float)i/10*h;
  156.  
  157.   wresize(0,0,nx,ny,sprites[num]);
  158.   sprites[num+1+(9-i)]=wnewblock(0,0,nx,ny);
  159.  }
  160. }