home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 2.ddi / SPRITE.ZIP / DROP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-30  |  9.8 KB  |  293 lines

  1. /*-------------------------------------------------------------------
  2.    DROP.C         *** WATER DROP ANIMATION SEQUENCE ***
  3.  
  4.    Programmed By Amaury M. Valdes    July 30, 1990
  5.    (C) Copyright 1990 Omega Software, Inc.
  6.    All Rights Reserved
  7.  
  8.    This program will demostrate how to incorporate sprites created with
  9.    "SPRED" and compiled with "DEFINE" both of which are included with
  10.    the package.
  11.  
  12.    If you have any comments or suggestions please feel free to drop 
  13.    me a line.  GOOD LUCK & ENJOY !!!
  14.  
  15.    COMPUSERVE: 73447,2273  or   MAIL:             Amaury Valdes
  16.                           11 Myrtle Avenue
  17.                           Passaic, NJ 07055
  18. --------------------------------------------------------------------*/
  19.  
  20. #include <graphics.h>
  21. #include <conio.h>
  22. #include <stdio.h>
  23. #include <alloc.h>
  24.  
  25. #define TRUE 1;
  26. #define FALSE 0;
  27.  
  28. int DROP1[]={5,6,0,1,9,1,0,1,9,9,1,1,1,9,1,1,1,1,1,1,1,1,1,1,
  29.              1,1,1,0,1,1,1,0};
  30.  
  31. int DROP2[]={7,6,0,0,1,9,1,0,0,0,1,9,9,1,1,0,1,1,9,1,1,1,1,1,
  32.              1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0};
  33.  
  34. int DROP3[]={7,4,0,1,9,1,1,1,0,1,9,9,1,1,1,1,1,1,1,1,1,1,1,0,
  35.              0,1,1,1,0,0};
  36.  
  37. int DROP4[]={12,7,0,0,0,0,0,0,0,0,9,0,0,0,0,1,9,1,0,0,0,1,1,0,
  38.              0,0,0,0,0,1,0,0,0,1,0,0,9,1,1,9,0,0,0,0,0,0,
  39.              0,9,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,9,
  40.              9,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0};
  41.  
  42. int DROP5[]={22,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,0,0,
  43.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,1,0,
  44.              0,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  45.              1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  46.              0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,0,0,0,
  47.              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0,
  48.              0,0,0,9,9,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  49.              0,0,9,1,1,1,1,1,0,0,0,0,0,0,1,9,0,0,0,0,0,9,
  50.              0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,9,0,0,0,0,0,
  51.              0,0,0,0,0,0,0,0,0,9,9,9,0,0,0,0,1,0,0,0,0,0
  52.              };
  53.  
  54. int DROP6[]={22,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0,0,0,0,
  55.              9,0,1,9,1,0,0,0,9,9,9,0,0,0,0,1,9,1,0,1,9,1
  56.              };
  57.  
  58. int COPYRGHT[]={8,9,0,0,14,14,14,14,0,0,0,14,0,0,0,0,14,0,14,0,0,14,14,0,
  59.                 0,14,14,0,14,0,0,14,0,14,14,0,14,0,0,0,0,14,14,0,14,0,
  60.                 0,14,0,14,14,0,0,14,14,0,0,14,0,14,0,0,0,0,14,0,0,0,
  61.                 14,14,14,14,0,0};
  62.  
  63. int FAUCET1[]={23,17,0,0,0,0,0,0,0,7,7,0,0,0,0,0,0,0,0,7,7,7,7,0,
  64.                0,0,0,0,0,0,8,7,7,7,7,8,7,0,0,0,8,7,7,7,7,7,
  65.                7,7,0,0,0,0,0,7,8,0,8,0,8,8,0,0,0,8,7,8,8,7,
  66.                8,8,7,0,0,0,0,0,0,0,0,8,0,7,7,7,7,7,8,8,8,7,
  67.                7,8,8,0,0,0,0,0,0,7,7,7,7,7,8,8,8,8,8,8,8,8,
  68.                8,8,8,0,0,0,8,8,7,8,7,8,8,8,8,8,8,8,7,8,8,8,
  69.                8,8,0,0,0,0,8,7,8,8,8,8,8,8,8,8,8,8,0,7,8,8,
  70.                8,8,8,0,0,0,0,8,7,8,8,8,8,0,0,0,0,0,0,0,7,8,
  71.                7,8,8,8,0,0,0,0,8,7,8,8,8,0,0,0,0,0,0,0,0,0,
  72.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  73.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  74.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  75.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  76.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  77.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  78.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  79.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  80.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  81.  
  82. int FAUCET2[]={23,11,0,0,0,0,0,0,0,7,7,0,0,0,0,0,0,0,0,7,7,7,7,0,
  83.                0,0,0,0,0,0,8,7,7,7,7,8,7,0,0,0,8,7,7,7,7,7,
  84.                7,7,0,0,0,0,0,7,8,0,8,0,8,8,0,0,0,8,7,8,8,7,
  85.                8,8,7,0,0,0,0,0,0,0,0,8,0,7,7,7,7,7,8,8,8,7,
  86.                7,8,8,0,0,0,0,0,0,7,7,7,7,7,8,8,8,8,8,8,8,8,
  87.                8,8,8,0,0,0,8,8,7,8,7,8,8,8,8,8,8,8,7,8,8,8,
  88.                8,8,0,0,0,0,8,7,8,8,8,8,8,8,8,8,8,8,0,7,8,8,
  89.                8,8,8,0,0,0,0,8,7,8,8,8,8,0,0,0,0,0,0,0,7,8,
  90.                7,8,8,8,0,0,0,0,8,7,8,8,8,0,0,0,0,0,0,0,0,0,
  91.                0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,
  92.                0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,
  93.                0,0,0,0,0,0,0,0,0,0,0};
  94.  
  95. int FAUCET3[]={23,13,0,0,0,0,0,0,0,7,7,0,0,0,0,0,0,0,0,7,7,7,7,0,
  96.            0,0,0,0,0,0,8,7,7,7,7,8,7,0,0,0,8,7,7,7,7,7,
  97.            7,7,0,0,0,0,0,7,8,0,8,0,8,8,0,0,0,8,7,8,8,7,
  98.            8,8,7,0,0,0,0,0,0,0,0,8,0,7,7,7,7,7,8,8,8,7,
  99.            7,8,8,0,0,0,0,0,0,7,7,7,7,7,8,8,8,8,8,8,8,8,
  100.            8,8,8,0,0,0,8,8,7,8,7,8,8,8,8,8,8,8,7,8,8,8,
  101.            8,8,0,0,0,0,8,7,8,8,8,8,8,8,8,8,8,8,0,7,8,8,
  102.            8,8,8,0,0,0,0,8,7,8,8,8,8,0,0,0,0,0,0,0,7,8,
  103.            7,8,8,8,0,0,0,0,8,7,8,8,8,0,0,0,0,0,0,0,0,0,
  104.            0,0,0,0,0,0,0,0,0,1,9,1,1,0,0,0,0,0,0,0,0,0,
  105.            0,0,0,0,0,0,0,0,0,0,9,9,1,1,0,0,0,0,0,0,0,0,
  106.            0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,
  107.            0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  108.            0,0,0,0,0,0,0,0,0,0,0,0,0};
  109.  
  110. int FAUCET4[]={23,15,0,0,0,0,0,0,0,7,7,0,0,0,0,0,0,0,0,7,7,7,7,0,
  111.            0,0,0,0,0,0,8,7,7,7,7,8,7,0,0,0,8,7,7,7,7,7,
  112.                7,7,0,0,0,0,0,7,8,0,8,0,8,8,0,0,0,8,7,8,8,7,
  113.                8,8,7,0,0,0,0,0,0,0,0,8,0,7,7,7,7,7,8,8,8,7,
  114.                7,8,8,0,0,0,0,0,0,7,7,7,7,7,8,8,8,8,8,8,8,8,
  115.                8,8,8,0,0,0,8,8,7,8,7,8,8,8,8,8,8,8,7,8,8,8,
  116.                8,8,0,0,0,0,8,7,8,8,8,8,8,8,8,8,8,8,0,7,8,8,
  117.                8,8,8,0,0,0,0,8,7,8,8,8,8,0,0,0,0,0,0,0,7,8,
  118.                7,8,8,8,0,0,0,0,8,7,8,8,8,0,0,0,0,0,0,0,0,0,
  119.                0,0,0,0,0,0,0,0,0,1,9,1,1,0,0,0,0,0,0,0,0,0,
  120.                0,0,0,0,0,0,0,0,0,0,9,9,1,1,1,0,0,0,0,0,0,0,
  121.                0,0,0,0,0,0,0,0,0,0,0,1,9,9,1,1,0,0,0,0,0,0,
  122.                0,0,0,0,0,0,0,0,0,0,0,0,1,9,9,1,1,0,0,0,0,0,
  123.                0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,
  124.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,
  125.                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  126.  
  127.  
  128. void *image;
  129.  
  130. int x,y,len,width,ch,cc;
  131. long size;
  132.  
  133. int main(void)
  134. {
  135.   init_graphics_system();
  136.   put(230,30,"WATER DROP ANIMATION",2);
  137.   rectangle(260,50,350,200);
  138.   pos_sprite(COPYRGHT,10,339);
  139.   put(25,340,"OMEGA SOFTWARE, INC.                        Programmed By Amaury M. Valdes",14);
  140.   while (!kbhit())
  141.   {
  142.     pos_sprite(FAUCET1,302,72);delay(100);
  143.     pos_sprite(FAUCET2,302,72);delay(100);
  144.     pos_sprite(FAUCET3,302,72);delay(100);
  145.     pos_sprite(FAUCET4,302,72);delay(100); 
  146.     pos_sprite(FAUCET1,302,72);
  147.     animate_drop();delay(300);
  148.   }
  149.   closegraph();
  150.   _setcursortype(_NORMALCURSOR);
  151.   return 0;
  152. }
  153.  
  154. int init_graphics_system(void)
  155. {
  156.   int gdriver,gmode,errorcode;
  157.  
  158.   /*-------------------------------------------------------
  159.      INITIALIZE SYSTEM FOR EGA GRAPHICS ONLY !!!
  160.   --------------------------------------------------------*/
  161.   gdriver=EGA;
  162.   gmode=EGAHI;
  163.   initgraph(&gdriver,&gmode,"");
  164.   errorcode=graphresult();
  165.   if (errorcode!=0) 
  166.   {
  167.     clrscr();color(4,0);
  168.     printf("\nERROR: PROGRAM WILL ONLY WORK ON COMPUTERS \n");
  169.     printf("       WITH EGA GRAPHICS CAPABILITIES !!! \n");
  170.     color(7,0);
  171.     exit(1);
  172.   }
  173.   return 0;
  174. }
  175.  
  176. int animate_drop(void)
  177. {
  178.   pos_sprite(DROP1,301,86);           /*   POSITION DROP @ X,Y           */
  179.   size=imagesize(300,85,308,92);      /*   STORE IMAGE IN BUFFER     */
  180.   image=malloc(size);                /*   USE HEAP SPACE            */    
  181.   if (size<coreleft())               /*   CHECK IF ENOUGH MEMORY       */
  182.   {
  183.     getimage(300,85,308,92,image);
  184.     for (y=0;y<=85;y++) 
  185.     {
  186.       putimage(300,85+y,image,XOR_PUT);    /*  ERASE OLD IMAGE  */    
  187.       putimage(300,85+y,image,COPY_PUT);   /*  PUT NEW ONE      */
  188.       delay(10);
  189.     }
  190.   }
  191.   putimage(300,170,image,XOR_PUT);         /*  ERASE LAST IMAGE  */ 
  192.   free(image);                             /*  FREE BUFFER SPACE */
  193.   beep(800,10);beep(700,10);  
  194.   pos_sprite(DROP2,300,170);delay(50);     /* PLACE DROP2 ON SCREEN */
  195.   xor_pos_sprite(DROP2,300,170);           /* WAIT, AND ERASE       */
  196.   pos_sprite(DROP3,300,170);delay(50);     /*  "  "   "   "   "        */
  197.   xor_pos_sprite(DROP3,300,170);           /* THE FOLLOWING SIX     */
  198.   pos_sprite(DROP4,295,165);delay(50);     /* STEPS ARE ALL THE     */
  199.   xor_pos_sprite(DROP4,295,165);           /* USING DIFF SPRITES    */
  200.   pos_sprite(DROP5,295,165);delay(50);     /* FOR THE ANIMATION     */
  201.   xor_pos_sprite(DROP5,295,165);           /* SEQUENCE.            */    
  202.   pos_sprite(DROP6,295,173);
  203.   return 0;
  204. }
  205.  
  206. int pos_sprite(int cur_data[],int startx,int starty)
  207. {
  208.   int a,p,xx,yy,x,y;
  209.  
  210.   p=1;
  211.   len=cur_data[0];
  212.   width=cur_data[1];
  213.   for (y=2;y<width+2;y++)
  214.    for (x=2;x<len+2;x++)
  215.    {
  216.      a=((y-2)*40)+(x-2);
  217.      p++;
  218.      xx=a % 40;
  219.      yy=a / 40;
  220.      putpixel(startx+xx,starty+yy,cur_data[p]);
  221.    } 
  222.   return 0;
  223. }
  224.  
  225. int enlarge_pos_sprite(int cur_data[],int startx,int starty,int sizex,int sizey)
  226. {
  227.   int a,p,xx,yy,x,y,cx,cy;
  228.  
  229.   p=1;
  230.   len=cur_data[0];
  231.   width=cur_data[1];
  232.   for (y=2;y<width+2;y++)
  233.    for (x=2;x<len+2;x++)
  234.    {
  235.      a=((y-2)*40)+(x-2);
  236.      p++;
  237.      xx=(a % 40)*sizex;
  238.      yy=(a / 40)*sizey;
  239.      for (cx=0;cx<=sizex;cx++) for (cy=0;cy<=sizey;cy++)
  240.        putpixel(startx+xx+cx,starty+yy+cy,cur_data[p]);
  241.    } 
  242.   return 0;
  243. }
  244.  
  245. int xor_pos_sprite(int cur_data[],int startx,int starty)
  246. {
  247.   int a,p,xx,yy,x,y;
  248.  
  249.   p=1;
  250.   len=cur_data[0];
  251.   width=cur_data[1];
  252.   for (y=2;y<width+2;y++)
  253.    for (x=2;x<len+2;x++)
  254.    {
  255.      a=((y-2)*40)+(x-2);
  256.      p++;
  257.      xx=a % 40;
  258.      yy=a / 40;
  259.      if (cur_data[p]!=0) putpixel(startx+xx,starty+yy,0);
  260.    } 
  261.   return 0;
  262. }
  263.  
  264. int put(int x, int y, char *str1, int col)
  265. {
  266.    setcolor(col);
  267.    outtextxy(x,y,str1);
  268.    return 0;
  269. }
  270.  
  271. int pausekb(void)
  272. {
  273.   int ch;
  274.  
  275.    ch=getch();
  276.    if (!ch) ch=getch();
  277.    return 0;
  278. }
  279.  
  280. int color(int fore,int back)
  281. {
  282.   textcolor(fore);
  283.   textbackground(back);
  284.   return 0;
  285. }
  286.  
  287. int beep(int freq,int duration)
  288. {
  289.   sound(freq);
  290.   delay(duration);
  291.   nosound();
  292.   return 0;
  293. }