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