home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / NEURLNET / NERVES.ZIP / NO87 / DRAWBUG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-12  |  5.3 KB  |  160 lines

  1. #include "defn.h"
  2. #include "nsdata.c"
  3. #include "proto.h"
  4.  
  5. void drawbug(struct bug bug,int col)
  6.  {
  7.   int i;
  8.   int temp1,temp2,temp3;
  9.   int bugx,bugy,bugang;
  10.  
  11.   bugx = (bug.x + 1000L)/2000L;
  12.   bugy = (bug.y*AspR + 100000L)/200000L;
  13.   bugang = (bug.ang + 50L)/100L;
  14.  
  15.   /* calculate bug pts */
  16.   bugp.head[0] = bug.mouthx/2;
  17.   bugp.head[1] = ((long)AspR * bug.mouthy)/200L;
  18.   temp1 = bugang + hdsang[0]; /* calculate head pts */
  19.   bugp.head[2] = bugx + (int)(((long)hdsl * lcos(temp1))/2000L);
  20.   bugp.head[3] = bugy + (int)(((long)AspR * hdsl * lsin(temp1))/200000L);
  21.   temp3 = bugang + hdbang;
  22.   bugp.head[4] = bugx + (int)(((long)hdbl * lcos(temp3))/2000L);
  23.   bugp.head[5] = bugy + (int)(((long)AspR * hdbl * lsin(temp3))/200000L);
  24.   temp1 = bugang + hdsang[1];
  25.   bugp.head[6] = bugx + (int)(((long)hdsl * lcos(temp1))/2000L);
  26.   bugp.head[7] = bugy + (int)(((long)AspR * hdsl * lsin(temp1))/200000L);
  27.  
  28.   temp1 = bugang + btang[0]; /* calculate body pts */
  29.   temp2 = bugang + bmang[0];
  30.   temp3 = bugang + bbang[0];
  31.   bugp.body[0] = bugx + (int)(((long)btl * lcos(temp1))/2000L);
  32.   bugp.body[1] = bugy + (int)(((long)AspR * btl * lsin(temp1))/200000L);
  33.   bugp.body[2] = bugx + (int)(((long)bml * lcos(temp2))/2000L);
  34.   bugp.body[3] = bugy + (int)(((long)AspR * bml * lsin(temp2))/200000L);
  35.   bugp.body[4] = bugx + (int)(((long)bbl * lcos(temp3))/2000L);
  36.   bugp.body[5] = bugy + (int)(((long)AspR * bbl * lsin(temp3))/200000L);
  37.   temp1 = bugang + btang[1];
  38.   temp2 = bugang + bmang[1];
  39.   temp3 = bugang + bbang[1];
  40.   bugp.body[10] = bugx + (int)(((long)btl * lcos(temp1))/2000L);
  41.   bugp.body[11] = bugy + (int)(((long)AspR * btl * lsin(temp1))/200000L);
  42.   bugp.body[8] = bugx + (int)(((long)bml * lcos(temp2))/2000L);
  43.   bugp.body[9] = bugy + (int)(((long)AspR * bml * lsin(temp2))/200000L);
  44.   bugp.body[6] = bugx + (int)(((long)bbl * lcos(temp3))/2000L);
  45.   bugp.body[7] = bugy + (int)(((long)AspR * bbl * lsin(temp3))/200000L);
  46.  
  47.   bugp.legx[1] = bugp.body[2]; /* calculate leg attachment pts */
  48.   bugp.legy[1] = bugp.body[3];
  49.   bugp.legx[4] = bugp.body[8];
  50.   bugp.legy[4] = bugp.body[9];
  51.   for (i=0; i<6; i++)
  52.    {
  53.     if (i != 1 && i != 4)
  54.      {
  55.       temp1 = bugang + attang[i];
  56.       bugp.legx[i] = bugx + (int)(((long)attl[i] * lcos(temp1))/2000L);
  57.       bugp.legy[i] = bugy + (int)(((long)AspR * attl[i] * lsin(temp1))/200000L);
  58.      }
  59.     bugp.footx[i] = bug.footx[i]/2;
  60.     bugp.footy[i] = ((long)AspR * bug.footy[i])/200L;
  61.    }
  62.  
  63.   for (i = 0; i < 2; i++) /* calculate antenna attachment pts */
  64.    {
  65.     temp2 = bugang + antbang[i];
  66.     bugp.antax[i] = bugx + (int)(((long)antbl * lcos(temp2))/2000L);
  67.     bugp.antay[i] = bugy + (int)(((long)AspR * antbl * lsin(temp2))/200000L);
  68.     bugp.antx[i] = bug.antx[i]/2;
  69.     bugp.anty[i] = ((long)AspR * bug.anty[i])/200L;
  70.    }
  71.  
  72.   for (i = 0; i < 2; i++) /* calculate cercus attachment pts */
  73.    {
  74.     temp1 = bugang + cerbang[i];
  75.     bugp.cercax[i] = bugx + (int)(((long)cerbl * lcos(temp1))/2000L);
  76.     bugp.cercay[i] = bugy + (int)(((long)AspR * cerbl * lsin(temp1))/200000L);
  77.     bugp.cercx[i] = bug.cercx[i]/2;
  78.     bugp.cercy[i] = ((long)AspR * bug.cercy[i])/200L;
  79.    }
  80.  
  81.   showbug(bug,col);
  82.   if (recnum)
  83.    { /* record bug info */
  84.     if (bug.mouthst)
  85.      rc[reccnt].mouthfood = rc[reccnt].mouthfood | 1;
  86.     rc[reccnt].energy = energy/10000L;
  87.     for (i=0; i<6; i++)
  88.      if (bug.foot[i])
  89.       rc[reccnt].footst = rc[reccnt].footst | (1<<i);
  90.     bugx = bugp.head[0];
  91.     bugy = bugp.head[1];
  92.     rc[reccnt].x = bugx;
  93.     rc[reccnt].y = bugy;
  94.     for (i=0; i<6; i+=2)
  95.      {
  96.       rc[reccnt].head[i] = bugp.head[i+2] - bugx;
  97.       rc[reccnt].head[i+1] = bugp.head[i+3] - bugy;
  98.      }
  99.     for (i=0; i<12; i+=2)
  100.      {
  101.       rc[reccnt].body[i] = bugp.body[i] - bugx;
  102.       rc[reccnt].body[i+1] = bugp.body[i+1] - bugy;
  103.      }
  104.     for (i=0; i<6; i++)
  105.      {
  106.       rc[reccnt].footx[i] = bugp.footx[i] - bugx;
  107.       rc[reccnt].footy[i] = bugp.footy[i] - bugy;
  108.       rc[reccnt].legx[i] = bugp.legx[i] - bugx;
  109.       rc[reccnt].legy[i] = bugp.legy[i] - bugy;
  110.      }
  111.     for (i=0; i<2; i++)
  112.      {
  113.       rc[reccnt].antx[i] = bugp.antx[i] - bugx;
  114.       rc[reccnt].anty[i] = bugp.anty[i] - bugy;
  115.       rc[reccnt].antax[i] = bugp.antax[i] - bugx;
  116.       rc[reccnt].antay[i] = bugp.antay[i] - bugy;
  117.       rc[reccnt].cercx[i] = bugp.cercx[i] - bugx;
  118.       rc[reccnt].cercy[i] = bugp.cercy[i] - bugy;
  119.       rc[reccnt].cercax[i] = bugp.cercax[i] - bugx;
  120.       rc[reccnt].cercay[i] = bugp.cercay[i] - bugy;
  121.      }
  122.    }
  123.  }
  124.  
  125.  
  126. void showbug(struct bug bug,int col)
  127.  {
  128.   int i,poly[10];
  129.  
  130.   setcolor(col);
  131.   /* draw head */
  132.   for (i=0; i<8; i++)
  133.    poly[i] = bugp.head[i];
  134.   poly[8] = poly[0];
  135.   poly[9] = poly[1];
  136.   drawpoly(5,poly);
  137.   if (bug.mouthst)
  138.    line(bugp.head[0],bugp.head[1],bugp.head[4],bugp.head[5]);
  139.  
  140.   /* draw body */
  141.   drawpoly(6,bugp.body);
  142.  
  143.   /* draw antennae */
  144.   for (i=0; i<2; i++)
  145.    {
  146.     line(bugp.antax[i],bugp.antay[i],bugp.antx[i],bugp.anty[i]);
  147.    }
  148.   /* draw cerci */
  149.   for (i=0; i<2; i++)
  150.    line(bugp.cercax[i],bugp.cercay[i],bugp.cercx[i],bugp.cercy[i]);
  151.  
  152.   /* draw legs & feet */
  153.   for (i=0; i<6; i++)
  154.    {
  155.     line(bugp.legx[i],bugp.legy[i],bugp.footx[i],bugp.footy[i]);
  156.     if (bug.foot[i])
  157.      rectangle(bugp.footx[i]-1,bugp.footy[i]-1,bugp.footx[i]+1,bugp.footy[i]+1);
  158.    }
  159.  }
  160.