home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / ARSRC21.ZIP / AR256M.CPP < prev    next >
Text File  |  1995-05-25  |  5KB  |  332 lines

  1.  
  2. mouse::togmouse()
  3. {
  4.  
  5. if ( mouseon )
  6.  {
  7.  
  8.  asm mov ax , 0002 ;
  9.  asm INT 0x33 ;
  10.  mouseon = false ;
  11.  
  12.  }
  13. else
  14.  {
  15.  
  16.  asm mov ax,0001 ;
  17.  asm INT 0x33 ;
  18.  mouseon = true ;
  19.  
  20.  }
  21. return 1;
  22.  
  23. }
  24.  
  25. mouse::onmouse()
  26. {
  27.  
  28.  asm mov ax,0001 ;
  29.  asm INT 0x33 ;
  30.  mouseon = true ;
  31.  return(0);
  32. }
  33.  
  34. mouse::offmouse()
  35. {
  36.  asm mov ax , 0002 ;
  37.  asm INT 0x33 ;
  38.  mouseon = false ;
  39.  return(0);
  40. }
  41.  
  42. enum tf mouse::wheremouse(void)
  43.     {
  44.     int a,b,c;
  45.     asm MOV AX,5; //  function 5
  46.     asm MOV BX,0; // bx 0  check for right mouse click
  47.     asm INT 0x33; // pass on to mouse driver
  48.  
  49.     asm MOV a,BX; // save number of events in a
  50.     asm MOV AX,3; // get current mouse location
  51.     asm INT 0x33;
  52.     asm MOV b,CX; // save current pos
  53.     asm MOV c,DX;
  54.  
  55.     x=b;  // these 2 make it fit arena area
  56.     y=c*2.4;
  57.  
  58.     if(bitmap_flag)
  59.     {
  60.     if((oldmx!=x)||(oldmy!=y))
  61.         {
  62.         drawmouse(x,y,current_map);
  63.         }
  64.     oldmx=x;oldmy=y;
  65.     }
  66.  
  67.  
  68.  
  69.  
  70.     if (a==0)
  71.         return false;
  72.     return true;
  73.  
  74.     }
  75.  
  76. enum tf mouse::nearby(int a,int b,int c)
  77.     {
  78.     float d;
  79.     d=sqrt((a-x)*(a-x)+(b-y)*(b-y));
  80.     if (c>d) return true;
  81.     return false;
  82.     }
  83.  
  84.  
  85. mouse::~mouse()
  86.     {
  87.     free(bitmap_0);
  88.     free(bitmap_1);
  89.     free(bitmap_2);
  90.     free(bitmap_3);
  91.     free(background);
  92.  
  93.     asm MOV AX,2;
  94.     asm INT 0x33;
  95.     }
  96. enum tf mouse::wherelastclick(void)
  97.     {
  98.     int a,b,c;
  99.     asm MOV AX,5;
  100.     asm MOV BX,0;
  101.     asm INT 0x33;
  102.  
  103.     asm MOV a,BX;
  104.     asm MOV b,CX;
  105.     asm MOV c,DX;
  106.  
  107.     b>464?x=464:x=b;
  108.     y=c*2.4;
  109.  
  110.     if (a==0)
  111.         return false;
  112.     return true;
  113.     }
  114. enum tf mouse::right(void)    // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  115.  
  116.     {
  117.     int a;
  118.     asm MOV AX,5;
  119.     asm MOV BX,1;
  120.     asm INT 0x33;
  121.     asm MOV a,BX;
  122.  
  123.     if (a==0)
  124.         return false;
  125.     return true;
  126.     }
  127.  
  128. mouse::mouse(void)
  129.     {
  130.     FILE *in;
  131.     int i;
  132.     x=0;
  133.     y=0;
  134.     l=19,r=624,u=19,d=464;
  135.   noputat=0;
  136.     flip=0;
  137.     printf("Checking mouse...\n");
  138.     asm MOV AX,0000;
  139.     asm INT 0x33;
  140.   printf("still doing it\n");
  141.     asm MOV AX,0001;
  142.     asm INT 0x33;
  143.   printf("how long?\n");
  144.          //    asm MOV AX,0008;
  145.          //    asm MOV cx,0;
  146.          //    asm mov dx,0800;
  147.          //    asm INT 0x33;
  148.                 mouseon = true;
  149.  
  150.     bitmap_0=(char *)malloc(0x400);
  151.     bitmap_1=(char *)malloc(0x400);
  152.     bitmap_2=(char *)malloc(0x400);
  153.     bitmap_3=(char *)malloc(0x400);
  154.  
  155.     background=malloc(0x500);  // just to be safe.
  156.  
  157.     in=fopen("mouse0.dat","rb");
  158.     for (i=0;i<0x400;++i)
  159.         {
  160.         fscanf(in,"%c",&bitmap_0[i]);
  161.  
  162.         }
  163.     in=fopen("mouse1.dat","rb");
  164.     for (i=0;i<0x400;++i)
  165.         {
  166.         fscanf(in,"%c",&bitmap_1[i]);
  167.  
  168.         }
  169.     fclose(in);
  170.     in=fopen("mouse2.dat","rb");
  171.     for (i=0;i<0x400;++i)
  172.         {
  173.         fscanf(in,"%c",&bitmap_2[i]);
  174.  
  175.         }
  176.     fclose(in);
  177.     in=fopen("mouse3.dat","rb");
  178.     for (i=0;i<0x400;++i)
  179.         {
  180.         fscanf(in,"%c",&bitmap_3[i]);
  181.  
  182.         }
  183.     fclose(in);
  184.     current_map=bitmap_0;
  185.     return;
  186.     }
  187.  
  188. mouse::dobounds()
  189.     {
  190.  
  191.     int ll,rl,ul,dol;
  192.     ll=l;rl=r;ul=u/2.4;dol=d/2.4;
  193.     asm mov ax,0x07;
  194.     asm mov cx,ll;
  195.     asm mov dx,rl;
  196.     asm INT 0x33;
  197.     asm mov ax,0x08;
  198.     asm mov cx,ul;
  199.     asm mov dx,dol;
  200.     asm INT 0x33;
  201.  
  202.     return(0);
  203.  
  204. }
  205.  
  206. mouse::setbounds(int centrex,int centrey)
  207.     {
  208.  
  209.     l=(7-centrex)*32+16;
  210.     r=((width-centrex)+7)*32-16;
  211.     u=(7-centrey)*32+16;
  212.     d=((height-centrey)+7)*32-16;
  213.  
  214.     if(r>464)r=464;
  215.     if(d>464)d=464;
  216.     if(l<19)l=19;   // left and up limits needed for getimage and putimage
  217.     if(u<19)u=19;   // which crash on negative values
  218.     dobounds();
  219.  
  220.     return(0);
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227. }
  228.  
  229.  
  230. mouse::unsetbounds()
  231.     {
  232.     l=19;r=634;u=19;d=464;
  233.  
  234.     dobounds();
  235.  
  236.     return(0);
  237. }
  238.  
  239.  
  240. void mouse::drawmouse(int ax,int ay, unsigned char * which)
  241.     {
  242.     int i,px,py;
  243.     ax-=16;ay-=16;
  244.     putimage(oldmx-16,oldmy-16,background,0);
  245.  
  246.     getimage(ax,ay,ax+32,ay+32,background);
  247.  
  248.     if(!flip)
  249.         {
  250.         for(i=0;i<0x400;++i)
  251.             {
  252.             px=ax+i%32;py=ay+i/32;
  253.  
  254.             if(which[i]<254)putpixel(px,py,which[i]);
  255.             if(which[i]==254)putpixel(px,py,colour);
  256.             }
  257.         }
  258.     else        //flip over tile if it is a portrait of a left-facing monster
  259.         {
  260.         for(i=0;i<0x400;++i)
  261.             {
  262.             px=ax+32-i%32;py=ay+i/32;
  263.  
  264.             if(which[i]<254)putpixel(px,py,which[i]);
  265.             if(which[i]==254)putpixel(px,py,colour);
  266.             }
  267.         }
  268. }
  269.  
  270. mouse::bitmapon(int which,int col)
  271.     {
  272.     int i,px,py;
  273.     flip=0;
  274.      if(which==0)current_map=bitmap_0;
  275.      if(which==1)current_map=bitmap_1;
  276.      if(which==2)current_map=bitmap_2;
  277.      if(which==3)current_map=bitmap_3;
  278.      if(which==5){current_map=tile[mon[curpla][curmon].graphic];if(curpla%2)flip=1;}
  279.      oldmx=x;oldmy=y;
  280.      getimage(oldmx-16,oldmy-16,oldmx+16,oldmy+16,background);
  281.  
  282.      if(!flip)
  283.      {
  284.         for(i=0;i<0x400;++i)
  285.             {
  286.             px=x+i%32-16;py=y+i/32-16;
  287.             if(current_map[i]<254)putpixel(px,py,current_map[i]);
  288.             if(current_map[i]==254)putpixel(px,py,col);
  289.             }
  290.         }
  291.         else
  292.         {
  293.         for(i=0;i<0x400;++i)
  294.             {
  295.             px=x+32-i%32-16;py=y+i/32-16;
  296.             if(current_map[i]<254)putpixel(px,py,current_map[i]);
  297.             if(current_map[i]==254)putpixel(px,py,col);
  298.             }
  299.         }
  300.         bitmap_flag=1;
  301.         colour=col;
  302. }
  303.  
  304. mouse::bitmapoff()
  305.     {
  306.     putimage(x-16,y-16,background,0);
  307.     bitmap_flag=0;
  308.  
  309. }
  310.  
  311. mouse::initbitmap(int ya_want_centering_with_that)
  312.     {
  313.     if(ya_want_centering_with_that==1)noputat=1;
  314.     getimage(0,0,32,32,background); //just in case the first thing it does
  315.                                             // is bitmapoff(), requiring a putimage...
  316. }
  317.  
  318.  
  319. mouse::putat(int newx, int newy)
  320.     {
  321.     if(noputat)return(0);
  322.     int tempx,tempy;
  323.     tempx=x=newx;
  324.     tempy=y=newy/2.4;
  325.  
  326.  
  327.     asm mov ax,0x04;
  328.     asm mov cx,tempx;
  329.     asm mov dx,tempy;
  330.     asm INT 0x33;
  331.  
  332. }