home *** CD-ROM | disk | FTP | other *** search
/ HomeWare 14 / HOMEWARE14.bin / prog / spider3.cpp < prev    next >
C/C++ Source or Header  |  1995-02-06  |  9KB  |  252 lines

  1. // Simple sprite drawing program
  2. // with all the relevant bits.
  3. // Oliver Hutcheon 18-6-94 00:43am
  4.  
  5. #include <dos.h>
  6. #include <conio.h>
  7.  
  8. #define SIZE 50000
  9.  
  10. void setgmode();
  11. void clrgmode(int);
  12. void cls(void);
  13. void sprite(int,int,int,int);
  14. void erase(int,int,int,int);
  15. void sprite2(int,int,int,int);
  16. void erase2(int,int,int,int);
  17.  
  18.  
  19.  
  20. /* spider.cpp */
  21. const unsigned char image[1024]={
  22.   0,0,0,0,0,0,0,0,0,0,0,0,35,35,35,35,35,35,35,0,0,0,0,0,0,0,0,0,0,0,0,0,
  23.   0,0,0,0,0,0,0,0,0,0,35,35,44,44,44,44,44,44,44,35,35,0,0,0,0,0,0,0,0,0,0,0,
  24.   0,0,0,0,0,0,0,0,35,35,44,44,44,44,44,44,44,44,44,44,44,35,35,0,0,0,0,0,0,0,0,0,
  25.   0,0,0,0,0,0,0,35,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,35,0,0,0,0,0,0,0,0,
  26.   0,0,0,0,0,0,35,44,182,182,182,44,44,44,44,44,44,44,182,182,182,44,44,44,35,0,0,0,0,0,0,0,
  27.   0,0,0,0,0,35,44,182,182,182,182,182,44,44,44,44,44,182,182,182,182,182,44,44,44,35,0,0,0,0,0,0,
  28.   0,0,0,0,0,35,182,182,182,182,182,182,182,44,44,44,182,182,182,182,182,182,182,44,44,35,0,0,0,0,0,0,
  29.   0,0,0,0,35,44,182,182,15,15,182,182,182,44,44,44,182,182,15,15,182,182,182,44,44,44,35,0,0,0,0,0,
  30.   0,0,0,0,35,44,182,182,15,15,182,182,182,44,44,44,182,182,15,15,182,182,182,44,44,44,35,0,0,0,0,0,
  31.   0,0,0,35,44,44,44,182,182,182,182,182,44,44,44,44,44,182,182,182,182,182,44,44,44,44,44,35,0,0,0,0,
  32.   0,0,0,35,44,44,44,44,182,182,182,44,44,44,44,44,44,44,182,182,182,44,44,44,44,77,44,35,0,0,0,0,
  33.   0,0,0,35,44,44,44,44,44,44,44,44,44,44,39,44,44,44,44,44,44,44,44,44,44,77,77,77,0,0,0,0,
  34.   0,0,0,35,44,44,44,44,44,44,44,44,44,39,39,39,44,44,44,44,44,44,44,44,44,44,44,35,77,77,77,0,
  35.   0,0,0,77,77,44,44,44,44,44,44,44,39,39,39,39,39,44,44,44,44,44,44,44,44,44,44,35,0,77,0,0,
  36.   0,0,77,77,44,44,44,44,44,44,44,44,44,39,39,39,44,44,44,44,44,44,44,44,44,44,44,35,77,0,77,0,
  37.   0,0,77,77,44,44,44,44,44,44,44,44,44,44,39,44,44,44,44,44,44,44,44,44,44,44,44,77,0,0,77,0,
  38.   0,77,0,77,35,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,77,0,0,0,77,0,
  39.   0,77,0,77,35,44,44,44,44,217,217,44,44,44,44,44,44,44,44,44,217,217,44,44,44,77,77,77,77,0,77,0,
  40.   77,77,77,77,77,77,77,44,44,44,217,217,217,217,217,217,217,217,217,217,217,44,44,44,44,77,0,0,0,77,77,0,
  41.   0,0,77,0,0,35,44,44,44,44,44,44,217,217,217,217,217,217,217,44,44,44,44,44,44,35,0,0,0,77,77,0,
  42.   0,0,77,0,0,0,35,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,35,0,0,0,0,77,0,77,
  43.   0,77,77,77,77,77,77,35,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,35,0,0,0,0,0,77,0,77,
  44.   0,77,0,0,0,0,0,0,35,35,44,44,44,44,44,44,44,44,44,44,44,35,35,0,0,0,0,0,0,77,0,77,
  45.   0,77,0,0,0,0,0,0,0,0,35,35,44,44,44,44,44,44,44,35,35,0,0,0,0,0,0,0,0,77,0,77,
  46.   0,77,0,0,0,0,0,0,0,0,0,0,35,35,35,35,35,35,35,0,0,0,0,0,0,0,0,0,0,77,0,77,
  47.   0,77,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,77,77,
  48.   77,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,0,77,0,
  49.   77,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,0,77,0,
  50.   77,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,0,77,0,
  51.   77,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,0,77,0,
  52.   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,0,0,77,0,
  53.   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,0,0,0,0
  54. };
  55.  
  56. /* boxes.cpp */
  57. const unsigned char image2[1024]={
  58.   171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,0,0,0,0,0,0,0,0,0,0,0,0,0,
  59.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,44,44,44,171,44,44,44,44,44,44,44,44,44,44,44,44,44,
  60.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  61.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  62.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  63.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  64.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  65.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  66.   171,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,0,0,0,0,44,
  67.   177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,0,0,0,44,
  68.   177,0,0,0,0,0,0,0,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  69.   177,0,0,0,0,0,0,44,44,44,44,44,44,44,44,44,44,44,171,44,44,44,44,44,44,44,44,177,44,44,44,44,
  70.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  71.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  72.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  73.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,44,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  74.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,44,44,44,44,171,44,44,44,44,44,44,44,44,177,44,44,44,44,
  75.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  76.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  77.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  78.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  79.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  80.   177,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,0,0,0,0,0,0,0,0,177,0,0,0,44,
  81.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  82.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  83.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  84.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  85.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  86.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  87.   177,0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,177,0,0,0,44,
  88.   177,0,0,0,0,0,0,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,177,44,44,44,44,
  89.   177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,0,0,0,0
  90. };
  91.  
  92. int x,y,width,depth,width2,depth2;
  93. float x2,y2;
  94. char far *screen=(char far*)MK_FP(0xa000,0);
  95. char letter;
  96. int direction_x,direction_y,dx,dy;
  97. unsigned char buffer[1024],buffer2[1024];
  98. unsigned char vid_buffer[SIZE];
  99.  
  100. main(void)
  101. {
  102.  
  103.     x=y=10;
  104.     x2=200,y2=45;
  105.     direction_x=direction_y=1;
  106.     dx=-1;
  107.     dy=1;
  108.  
  109. // initialize the graphics system
  110.  
  111.     int oldmode=*(int *)MK_FP(0x40,0x49);
  112.     setgmode();
  113.     cls();
  114.     for (int frame=0;frame<1000;frame++)
  115.         {
  116.         sprite(x,y,32,32);
  117.         sprite2(x2,y2,32,32);
  118.         for (int i=y-1;i<y+33;i++) {
  119.             for (int j=(x-1);j<(x+33);j++)
  120.             screen[i*320+j]=vid_buffer[i*320+j] ;
  121.             }
  122.         for (int p=y2-1;p<y2+33;p++) {
  123.             for (int q=(x2-1);q<(x2+33);q++)
  124.             screen[p*320+q]=vid_buffer[p*320+q] ;
  125.             }
  126. //            for (int delay=0;delay<5000;delay++);
  127.         erase2(x2,y2,32,32);
  128.         erase(x,y,32,32);
  129.         x=x+direction_x;
  130.         y=y+direction_y;
  131.         x2=x2+dx;
  132.         y2=y2+dy;
  133.         if (x==320-32) direction_x=-1;
  134.         if (x==1) direction_x=1;
  135.         if (y==(SIZE/320)-32) direction_y=-1;
  136.         if (y==1) direction_y=1;
  137.         if (x2==320-32) dx=-1.05;
  138.         if (x2==1) dx=1.2;
  139.         if (y2==(SIZE/320)-32) dy=-1.1;
  140.         if (y2==1) dy=1.15;
  141.         }
  142.     clrgmode(oldmode);
  143.     return 0;
  144. }
  145.  
  146. void sprite(int x,int y,int width,int depth)
  147.  
  148. {
  149. int offset,temp,index;
  150.  
  151. offset = y*320+x;
  152. index=0;
  153.  
  154. for (int row=0; row<depth; row++) {
  155.     for (int col=0; col<width; col++) {
  156.         temp=image[index];
  157.         buffer[index]=vid_buffer[offset];
  158.         if (temp) vid_buffer[offset]=temp;
  159.         index++;
  160.         offset++;
  161.         }
  162.     offset+=(320-width);
  163.     }
  164. }
  165.  
  166.  
  167. void erase(int x,int y,int width,int depth)
  168.  
  169. {
  170. int offset,index;
  171.  
  172. offset = y*320+x;
  173. index=0;
  174.  
  175. for (int row=0; row<depth; row++) {
  176.     for (int col=0; col<width; col++) {
  177.         vid_buffer[offset] = buffer[index];
  178.         offset++;
  179.         index++;
  180.         }
  181.         offset+=(320-width);
  182.     }
  183. }
  184. void sprite2(int x,int y,int width,int depth)
  185.  
  186. {
  187. int offset,temp,index;
  188.  
  189. offset = y2*320+x2;
  190. index=0;
  191.  
  192. for (int row=0; row<depth; row++) {
  193.     for (int col=0; col<width; col++) {
  194.         temp=image2[index];
  195.         buffer2[index]=vid_buffer[offset];
  196.         if (temp) vid_buffer[offset]=temp;
  197.         index++;
  198.         offset++;
  199.         }
  200.     offset+=(320-width);
  201.     }
  202. }
  203.  
  204.  
  205. void erase2(int x,int y,int width,int depth)
  206.  
  207. {
  208. int offset,index;
  209.  
  210. offset = y2*320+x2;
  211. index=0;
  212.  
  213. for (int row=0; row<depth; row++) {
  214.     for (int col=0; col<width; col++) {
  215.         vid_buffer[offset] = buffer2[index];
  216.         offset++;
  217.         index++;
  218.         }
  219.         offset+=(320-width);
  220.     }
  221. }
  222.  
  223. void cls()
  224.  
  225. {
  226. for (long int i=0; i<SIZE; i++) {
  227.     screen[i]=i;
  228.     vid_buffer[i]=i; }
  229.  
  230. }
  231.  
  232.  
  233. void setgmode()
  234. {
  235. asm {
  236.         mov    ax,13h
  237.         mov    ah,0
  238.         int    10h
  239.  
  240. }
  241. }
  242.  
  243. void clrgmode(int oldmode)
  244. {
  245. asm{
  246.         mov    ax,oldmode
  247.         mov    ah,0
  248.         int    10h
  249.  
  250. }
  251. }
  252.