home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / BOB.ZIP / BOB.CPP next >
Encoding:
C/C++ Source or Header  |  1995-08-09  |  3.0 KB  |  134 lines

  1. /*
  2.     ********************
  3.     *    PeterSoft's Bob *
  4.     ********************        < body.cpp >
  5.  
  6.     This program is written by Peter Hsieh and Jeffery Hu, and
  7.     is finished on    July 21, 1995.
  8.  
  9.     The purpose of this program is to demostrate the basic sprite
  10.     skills that are applied on the computer graphic animations.
  11.  
  12.     Body.exe is for mod-13 (MCGA) and Bodyh.exe is for 640*480*
  13.     256 colors resolution.  Just simply choose the proper include
  14.     file and video initialization function.
  15.  
  16.     If you are interest to contact us, please write to
  17.  
  18.         24 Cecil Street
  19.         Toronto, Ontario
  20.         M5T 1N2    Canada
  21.  
  22.     Email: g3jjhh@cdf.utoronto.ca
  23.              zhsieh@undergrad.math.uwaterloo.ca
  24. */
  25.  
  26. # include "a:\work\mod13.h"    // header file for MCGA
  27. //# include "a:\work\vgahi.h"    // header file for 640*480*256 colors
  28. # include "a:\work\graph.h"
  29. # include "a:\person\data.h"
  30.  
  31. void drawbody (int, int, int, int);    // draw dog body
  32. void drawhand (int, int, int, int);    // hand
  33. void drawleg (int, int, int, int);    // leg
  34. void changesprite ();                    // change the components of dog
  35. void dog ();                                // draw the whole dog
  36. void recover ();                            // erase the previous image
  37.  
  38. void main ()
  39. {
  40.     char c[1];
  41.  
  42.     mode13 ();            // to access mode 13
  43. //    vesa ();                // to access vesa 640*480*256 colors mode
  44.     printf ("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n PeterSoft's BOB");
  45.     drawbody (0, 0, 0, 0);    // sample to show all components
  46.     drawhand (0, 0, 26, 0);
  47.     drawleg (0, 0, 40, 0);
  48.     drawleg (1, 0, 55, 0);
  49.     drawleg (2, 0, 70, 0);
  50.     drawleg (3, 0, 85, 0);
  51.     dog ();
  52.     do {
  53.         c[0]= getch ();
  54.         switch (c[0])
  55.         {
  56.             case 75: //left
  57.                 if (spritx> LEFT)
  58.                 {
  59.                     recover ();
  60.                     spritx-= BODYINC;
  61.                     dog ();
  62.                 }
  63.                 break;
  64.             case 77: // right;
  65.                 if (spritx< RIGHT)
  66.                 {
  67.                     recover ();
  68.                     spritx+= BODYINC;
  69.                     dog ();
  70.                 }
  71.                 break;
  72.             default:
  73.                 break;
  74.         }
  75.     } while (c[0]!= 'q');
  76.  
  77.     textmode ();            // back to text mode
  78. }
  79.  
  80. void drawbody (int n, int x, int y, int dis)
  81. {
  82.     int i, j;
  83.  
  84.     for (i= 0; i< ICONH; i++)
  85.         for  (j= 0; j< ICONW; j++)
  86.             if (body[n][i][j]!= -1)
  87.                 pixel (x+ j, y+ i, body[n][i][j]+ dis);
  88. }
  89.  
  90. void drawhand (int n, int x, int y, int dis)
  91. {
  92.     int i, j;
  93.  
  94.     for (i= 0; i< HANDW; i++)
  95.         for  (j= 0; j< HANDH; j++)
  96.             if (hand[n][j][i]!= -1)
  97.                 pixel (x+ i, y+ j+ 4, hand[n][j][i]+ dis);
  98. }
  99.  
  100. void drawleg (int n, int x, int y, int dis)
  101. {
  102.     int i, j;
  103.  
  104.     for (i= 0; i< LEGW; i++)
  105.         for  (j= 0; j< LEGH; j++)
  106.             if (leg[n][i][j]!= -1)
  107.                 pixel (x+ j, y+ i, leg[n][i][j]+ dis);
  108. }
  109.  
  110. void dog ()
  111. {
  112.     changesprite ();
  113.     drawleg (leg2, spritx+ 11, sprity+ 18, 14);
  114.     drawhand (0, spritx+ 10- handx1, sprity+ 11, -2);
  115.     drawbody (0, spritx, sprity, 0);
  116.     drawhand (0, spritx+ 10- handx2, sprity+ 10, 0);
  117.     drawleg (leg1, spritx+ 9, sprity+ 18, 0);
  118. }
  119. void changesprite ()
  120. {
  121.     if (handx1== 0 || handx1== 7)
  122.         handinc= -handinc;
  123.     handx1-= handinc;
  124.     handx2+= handinc;
  125.     if (leg1==0 || leg1 == 3)
  126.         leginc=-leginc;
  127.     leg1-= leginc;
  128.     leg2+= leginc;
  129. }
  130.  
  131. void recover ()
  132. {
  133.     bar (spritx, sprity, spritx+ ICONW, sprity+ 35, 0, 0);
  134. }