home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WGT_TC21.ZIP / BREAKOUT.C < prev    next >
C/C++ Source or Header  |  1992-07-17  |  4KB  |  222 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include "c:\tc\wgt\wgt.h"
  7. #include "c:\tc\wgt\spr.h"
  8.  
  9. color palette[256];
  10. block sprites[201];
  11. int x,y,i;
  12. int chk1,chk2,chk3,chk4;
  13. int blk[10][28]={
  14.    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  15.    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  16.    0,3,4,3,3,3,4,3,3,3,3,3,4,4,4,4,4,3,3,3,3,3,4,4,4,4,4,3,
  17.    0,3,4,3,3,3,4,3,3,3,3,3,4,3,3,3,3,3,3,3,3,3,3,3,4,3,3,3,
  18.    0,3,4,3,3,3,4,3,3,3,3,3,4,3,3,3,3,3,3,3,3,3,3,3,4,3,3,3,
  19.    0,3,4,3,4,3,4,3,3,3,3,3,4,3,4,4,4,3,3,3,3,3,3,3,4,3,3,3,
  20.    0,3,4,3,4,3,4,3,3,3,3,3,4,3,3,3,4,3,3,3,3,3,3,3,4,3,3,3,
  21.    0,3,4,3,4,3,4,3,3,3,3,3,4,3,3,3,4,3,3,3,3,3,3,3,4,3,3,3,
  22.    0,3,4,4,4,4,4,3,3,3,3,3,4,4,4,4,4,3,3,3,3,3,3,3,4,3,3,3,
  23.    0,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3};
  24.  
  25. ;
  26.  
  27. void dobounce(void);
  28.  
  29. float sbx,sby,sp,lx,ly;
  30. float xsp,ysp;
  31.  
  32. void looper();
  33. void hit(int,int);
  34.  
  35. int hits;            // number of bricks hit
  36.  
  37. void main(void)
  38. {
  39. i=minit();
  40. printf("%i   ",i);
  41. if (i==0)
  42.    {
  43.    printf("Mouse not detected.  You need a mouse for this example program\n");
  44.    printf("Press any key\n");
  45.    getch();
  46.    exit(1);
  47.    }
  48. else printf("Mouse with %i buttons detected.\n",i);
  49. printf("Press any key\n");
  50. getch();
  51.  
  52. vga256();
  53. wloadsprites(&palette,"c:\\tc\\wgt\\break.spr",sprites);
  54. initspr();
  55. spon=2;
  56.  
  57. wsetscreen(spritescreen);
  58.  
  59.  
  60. for (y=0; y<200; y++)
  61.     {
  62.     wsetcolor((y/8)+1);
  63.     wline(0,y,319,y);
  64.     }
  65. wsetcolor(0);
  66. wbar(50,10,270,189);
  67. wsetcolor(16);
  68. wrectangle(49,9,271,190);
  69.  
  70.  
  71. for (x=1; x<28; x++)
  72.   for (y=1; y<10; y++)
  73.     {
  74.     wputblock(x*7+57,y*5+20,sprites[blk[y][x]],0);
  75.     }
  76.  
  77.  
  78.  
  79. wcopyscreen(0,0,319,199,spritescreen,0,0,NULL);
  80.  
  81. spriteon(1,160,100,1);
  82. spriteon(2,160,100,2);
  83.  
  84. //msetbounds(50,129,245,179);
  85.  
  86.  
  87. xsp=.1;
  88. ysp=.3;
  89.  
  90. sbx=xsp;
  91. sby=ysp;
  92. lx=160; ly=100;
  93.  
  94.  
  95. do {
  96. looper();
  97. } while (but!=2);
  98.  
  99. msetbounds(0,0,319,199);
  100. textmode(C80);
  101. }
  102.  
  103.  
  104. void looper(void)
  105. {
  106. erasespr();
  107.  
  108. mread();
  109. s[1].x=mx;
  110. s[1].y=my;
  111.  
  112. if (lx>267) {
  113.    dobounce();
  114.    lx=267;
  115.    sbx=-sbx; }
  116. if (lx<49)  {
  117.    dobounce();
  118.    lx=49;
  119.    sbx=-sbx; }
  120. if (ly<9) {
  121.    dobounce();
  122.    ly=9;
  123.    sby=-sby;  }
  124.  
  125. lx+=sbx;
  126. ly+=sby;
  127. s[2].x=(float)lx;
  128. s[2].y=(float)ly;
  129.  
  130.  
  131. if (s[2].y>186)
  132.    {
  133.    for (i=2000; i>=200; i--)
  134.       sound(i);
  135.    nosound();
  136.    lx=160; ly=100;
  137.    }
  138.  
  139.  
  140. if (overlap(1,2))
  141.    {
  142.    sound(900);
  143.      sby=-ysp;
  144.    if (s[2].x>s[1].x+21)
  145.      sbx=xsp*4;
  146.    else if (s[2].x>s[1].x+18)
  147.      sbx=xsp*2;
  148.    else if (s[2].x>s[1].x+12)
  149.      sbx=xsp;
  150.    else if (s[2].x>s[1].x+6)
  151.      sbx=-xsp;
  152.    else if (s[2].x>s[1].x+3)
  153.      sbx=-xsp*2;
  154.    else
  155.      sbx=-xsp*4;
  156.   }
  157.  
  158. chk1=wgetpixel(s[2].x+3,s[2].y-1);
  159. chk2=wgetpixel(s[2].x+3,s[2].y+6);
  160. chk3=wgetpixel(s[2].x-1,s[2].y+3);
  161. chk4=wgetpixel(s[2].x+6,s[2].y+3);
  162. if (chk1>28)
  163.    {
  164.    hit(3,-1);
  165.    sby=ysp;
  166.    }
  167. else if (chk2>28)
  168.    {
  169.    hit(3,6);
  170.    sby=-ysp;
  171.    }
  172. if (chk3>28)
  173.    {
  174.    hit(-1,3);
  175.    sbx=-sbx;
  176.    lx+=2;
  177.    }
  178. else if (chk4>28)
  179.    {
  180.    hit(6,3);
  181.    sbx=-sbx;
  182.    lx-=2;
  183.    }
  184.  
  185. nosound();
  186. drawspr();
  187. }
  188.  
  189.  
  190.  
  191.  
  192. void hit(int ix,int iy)
  193. {
  194. sound(600);
  195. for (x=1; x<28; x++)
  196.   for (y=1; y<10; y++)
  197.     {
  198.     if ((s[2].x+ix>=x*7+57) & (s[2].x+ix<=x*7+63)
  199.      &  (s[2].y+iy>=y*5+20)  & (s[2].y+iy<=y*5+24) & (blk[y][x] !=0))
  200.       {
  201.       wsetcolor(0);
  202.       wbar(x*7+57,y*5+20,x*7+63,y*5+24);
  203.       s[2].minx=49; s[2].miny=20; s[2].maxx=271; s[2].maxy=98;
  204.       blk[y][x]=0;
  205.       hits++;
  206.       if ((hits % 15)==0)
  207.      {
  208.      xsp+=.1;
  209.      ysp+=.1;
  210.      }
  211.  
  212.       }
  213.     }
  214. }
  215.  
  216. void dobounce(void)
  217. {
  218. sound(200);
  219. nosound();
  220. }
  221.  
  222.