home *** CD-ROM | disk | FTP | other *** search
/ Adventures in Heaven 2 / adventuresinheaven2powergamesfordosandwindows.iso / windows / arcade / cbzone / c_graphi.c < prev    next >
C/C++ Source or Header  |  1992-05-27  |  17KB  |  517 lines

  1. #include "c_includ.h"
  2. /*
  3.  * cbzone_graphics.c
  4.  *  -- Todd W Mummert, December 1990, CMU
  5.  *
  6.  * RCS Info
  7.  *  $Header: c_graphics.c,v 1.1 91/01/12 02:03:33 mummert Locked $
  8.  */
  9.  
  10. Font controlfont, titlefont, generalfont;
  11.  
  12. void message(number, bell)
  13.      int number;
  14.      Bool bell;
  15. {
  16.   static int xpt = 70;
  17.   static int ypt[] = {507, 567, 627};
  18.   static char* messages[] = {"ENEMY TANK IN FIRING ARC",
  19.                                "MOVEMENT BLOCKED BY OBJECT",
  20.                                "SALVO FIRED BY ENEMY TANK"};
  21.   int ind;
  22.   char text[41];
  23.  
  24.   ind = abs(number) - 1;
  25.   if (number < 0)
  26.     sprintf(text,"%-40s"," ");
  27.   else
  28.     sprintf(text,"%-40s",messages[ind]);
  29.  
  30.   gprsetclippingactive(False);
  31.   printstring(xpt, ypt[ind], text, 40);
  32.   gprsetclippingactive(True);
  33.   if (bell)
  34.     tonetime();
  35. }
  36.  
  37. void screeninit()
  38. {
  39.   controlfont = gprloadfontfile(CONTROLFONT);
  40.   titlefont = gprloadfontfile(TITLEFONT);
  41.   generalfont = gprloadfontfile(GENERALFONT);
  42.   staticscreen();
  43. }
  44.  
  45. void staticscreen()
  46. {
  47.   static int window[2][2] = {70, 75, 860, 350};
  48.   int pt[2], radius;
  49.   char text[30];
  50.   static short line[] = {58, 66, 66, 58, 56, 438, 68, 438, 938, 56,
  51.                            938, 68, 942, 442, 934, 434, 56, 472, 68, 472,
  52.                            934, 468, 942, 476, 58, 644, 66, 652, 932, 648,
  53.                            944, 648};
  54.   static short scan[] = {500, 495, 500, 500, 500, 625, 500, 620, 435, 560,
  55.                            440, 560, 565, 560, 560, 560};
  56.   static short scrn[] = {75, 64, 925, 64, 936, 75, 936, 425, 925, 436,
  57.                            75, 436, 64, 425, 64, 75, 75, 64};
  58.  
  59.   gprsetclippingactive(False);
  60.   gprsettextbackgroundvalue(opt->cpi[COLOR_BG]);
  61.   gprsetdrawvalue(opt->cpi[COLOR_FG]);
  62.   gprsettextvalue(opt->cpi[COLOR_TEXT]);
  63.   drawrectangle(50, 50, 900, 400);      /* draw the outer top rectangle */
  64.   drawrectangle(53, 53, 894, 394);      /*          inner top           */
  65.   drawrectangle(50, 460, 900, 200);     /*          outer bottom        */
  66.   drawrectangle(53, 463, 894, 194);     /*          inner bottom        */
  67.   polyline(scrn, 9);                    /*       inner top frame        */
  68.   pt[0] = 62;
  69.   pt[1] = 62;
  70.   radius = 6;
  71.   gprcircle(pt, radius);                /* now let's draw some screws   */
  72.   pt[0] = 938;
  73.   gprcircle(pt, radius);
  74.   pt[1] = 438;
  75.   gprcircle(pt, radius);
  76.   pt[0] = 62;
  77.   gprcircle(pt, radius);
  78.   pt[0] = 62;
  79.   pt[1] = 472;
  80.   gprcircle(pt, radius);
  81.   pt[0] = 938;
  82.   gprcircle(pt, radius);
  83.   pt[1] = 648;
  84.   gprcircle(pt, radius);
  85.   pt[0] = 62;
  86.   gprcircle(pt, radius);
  87.   multiline(line, 8);                   /*        now the slots         */
  88.   pt[0] = 500;
  89.   pt[1] = 560;
  90.   radius = 65;
  91.   gprsetdrawvalue(opt->cpi[COLOR_SCANNER]);
  92.   gprcircle(pt, radius);                /*      radar screen            */
  93.   radius = 64;
  94.   gprcircle(pt, radius);
  95.   multiline(scan, 4);
  96.   pt[0] = 855;
  97.   pt[1] = 560;
  98.   radius = 65;
  99.   gprsetdrawvalue(opt->cpi[COLOR_JOYSTICK]);
  100.   gprcircle(pt, radius);                /*      joystick screen         */
  101.   radius = 64;
  102.   gprcircle(pt, radius);
  103.   gprsetdrawvalue(opt->cpi[COLOR_TEXT]);
  104.   drawrectangle(590, 570, 55, 30);      /*      missile warning         */
  105.   drawrectangle(655, 570, 55, 30);      /*      lander warning          */
  106.   drawrectangle(590, 520, 120, 30);     /*         score box            */
  107.   gprsettextfont(titlefont);
  108.   strcpy(text, "BATTLEZONE V2.0c");
  109.   printstring(50, 45, text, strlen(text));
  110.   gprsettextvalue(opt->cpi[COLOR_JOYSTICK]);
  111.   strcpy(text, "F");                    /* directions for the joystick  */
  112.   printstring(850, 503, text, 1);
  113.   strcpy(text, "B");
  114.   printstring(850, 630, text, 1);
  115.   strcpy(text, "R");
  116.   printstring(913, 570, text, 1);
  117.   strcpy(text, "L");
  118.   printstring(785, 570, text, 1);
  119.   gprsettextvalue(opt->cpi[COLOR_TEXT]);
  120.   gprsettextfont(controlfont);
  121.   strcpy(text, "Missile");              /*      warning messages        */
  122.   printstring(595, 590, text, 7);
  123.   strcpy(text, "Lander");
  124.   printstring(664, 590, text, 6);
  125.   strcpy(text, "H");                    /*      switch positions        */
  126.   printstring(920, 608, text, 1);
  127.   strcpy(text, "L");
  128.   printstring(920, 642, text, 1);
  129.   gprsetclipwindow(window);             /* define the playing field     */
  130.   gprsettextfont(generalfont);
  131.   pt[0] = 500;
  132.   pt[1] = 355;
  133.   gprsetcursorposition(pt);
  134.   gprsetclippingactive(True);
  135. }
  136.  
  137. void updatedisplay (missile, lander, score, numleft, sens, reset)
  138.      Bool missile, lander, sens, reset;
  139.      LONG score;  // Eric Fogelin made this LONG from int
  140.      int numleft;
  141. {
  142.   char text[11];
  143.   static Bool flasher[] = {False, False};
  144.   static int currentnumleft = 0;
  145.   static int currentscore = -1;
  146.   static int bswitch[] = {918, 612};
  147.   static int blswitch[] = {918, 638};    // Eric Fogelin: added - orig did not work
  148.   static int wind1[][2] = {591, 571, 54, 29};
  149.   static int wind2[][2] = {656, 571, 54, 29};
  150.   static int origin[][2] = {733, 493, 733, 533, 733, 573, 733, 613};
  151.   static Bool currentsens = True;
  152.  
  153.   gprsetclippingactive(False);
  154.   if (reset) {
  155.     flasher[0] = flasher[1] = False;
  156.     currentsens = True;
  157.   }
  158.  
  159.   if ((flasher[0] && !missile) ||       /* change the missile warning */
  160.       (!flasher[0] && missile)) {
  161.     flasher[0] = missile;
  162.     bitblt(wind1);
  163.   }
  164.   if ((flasher[1] && !lander) ||        /* change the lander warning */
  165.       (!flasher[1] && lander)) {
  166.     flasher[1] = lander;
  167.     bitblt(wind2);
  168.   }
  169.   if (score != currentscore) {          /*     change the score      */
  170.     currentscore = score;
  171.     sprintf(text,"%10ld",score);  // Eric Fogelin changed this to ld from d
  172.     printstring(608, 542, text, strlen(text));
  173.   }
  174.   if (numleft < currentnumleft && numleft >= 0)    /* remove tank(s) */
  175.     while (numleft != currentnumleft)
  176.       removepixmap(4, origin[--currentnumleft]);
  177.   if (numleft > currentnumleft)                    /*  add tank(s)   */
  178.     while (numleft != currentnumleft && currentnumleft < 4)
  179.       putpixmap(4, origin[currentnumleft++]);
  180.   if (sens && !currentsens) {           /* change to high gear       */
  181.     removepixmap(3, blswitch); // Eric Fogelin: added - orig did not work
  182.     putpixmap(2, bswitch);
  183.     currentsens = sens;
  184.   }
  185.   else if (!sens && currentsens) {      /* change to low gear        */
  186.     removepixmap(2, bswitch);  // Eric Fogelin: added - orig did not work
  187.     putpixmap(3, blswitch);
  188.     currentsens = sens;
  189.   }
  190.   gprsetclippingactive(True);
  191. }
  192.  
  193. void joystick (position, sens, pl)
  194.      int* position;
  195.      Genericp pl;
  196.      Bool sens;
  197. {
  198.   static float sscale[] = {0.06, 0.03};
  199.   static float rscale[] = {0.00013, 0.000065};
  200.   static int destorigin[] = {845, 550};
  201.   static short stick[8] = {0};
  202.   static Bool first = True;
  203.   static Bool draw = True;
  204.   int ind;
  205.   float scrot, sctot, scale, xl, yl, tl, xoff, yoff;
  206.  
  207.   if (sens)
  208.     ind = 0;
  209.   else
  210.     ind = 1;
  211.   pl->speed = -(position[1] - 355.0) * sscale[ind];
  212.   pl->rotate = (position[0] - 500.0) * rscale[ind];
  213.   if (fabs(pl->speed) > 10.0)
  214.     pl->speed = sign(10.0, pl->speed);
  215.   if (fabs(pl->rotate) > 0.030)
  216.     pl->rotate = sign(0.030, pl->rotate);
  217.   scrot = pl->rotate * 10.0 / 0.030;
  218.   sctot = sqrt(pl->speed*pl->speed + scrot*scrot);
  219.   if (sctot > 10.0) {
  220.     scale = 10.0 / sctot;
  221.     pl->speed *= scale;
  222.     pl->rotate *= scale;
  223.   }
  224.   if (draw) {
  225.     gprsetclippingactive(False);
  226.     if (!first) {
  227.       gprsetdrawvalue(opt->cpi[COLOR_BG]);
  228.       removepixmap(1, destorigin);
  229.       multiline(stick, 2);
  230.     }
  231.     else
  232.       first = False;
  233.     destorigin[0] =  35.0 * (pl->rotate / 0.03) + 845.0;
  234.     destorigin[1] = -35.0 * (pl->speed  / 10.0)  + 550.0;
  235.     putpixmap(1, destorigin);
  236.     xl = pl->rotate / 0.030;
  237.     yl = pl->speed / 10.0;
  238.     tl = sqrt(xl*xl + yl*yl);
  239.     if (tl > 0.05) {
  240.       yoff = xl / tl * 9.0;
  241.       xoff = yl / tl * 9.0;
  242.     }
  243.     else {
  244.       yoff = 0.0;
  245.       xoff = 0.0;
  246.     }
  247.     stick[0] = stick[4] = 855;
  248.     stick[2] = destorigin[0] + 10 + xoff / 2;
  249.     stick[6] = destorigin[0] + 10 - xoff / 2;
  250.     stick[1] = stick[5] = 560;
  251.     stick[3] = destorigin[1] + 10 + yoff / 2;;
  252.     stick[7] = destorigin[1] + 10 - yoff / 2;
  253.     gprsetdrawvalue(opt->cpi[COLOR_JOYSTICK]);
  254.     multiline(stick, 2);
  255.     gprsetclippingactive(True);
  256.   }
  257.   draw = !draw;
  258.   pl->rotate = -pl->rotate;
  259. }
  260.  
  261. /*
  262.  * scanner
  263.  *
  264.  * draws the radar scan...
  265.  */
  266. void scanner(o)
  267.      Genericp o;
  268. {
  269.   static float scale = 0.03;
  270.   static XSegment scanline[] = {500, 560, 500, 560};
  271.   static Bool init = True;
  272.   static XSegment* dot;
  273.   static float ca = 1.0;        /* keep track of where the scanner line */
  274.   static float sa = 0.0;        /* is currently positioned */
  275.   static float sda = 0.087156;
  276.   static float cda = 0.996195;
  277.   static int ind = 0;           /* number of enemies last on scanner */
  278.   float temp;
  279.   Genericp g;
  280.   XSegment* nextdot;
  281.   XSegment* curdot;
  282.  
  283.   if (init) {
  284.     dot = (XSegment*) malloc(sizeof(XSegment)*2*opt->mobjects);
  285.     if (dot == NULL) {
  286.       printf("Malloc failed...too many objects?\n");
  287. #ifdef WIN32
  288.       return;
  289. #else //X11
  290.       exit(1);
  291. #endif
  292.     }
  293.     init = False;
  294.   }
  295.  
  296.   gprsetclippingactive(False);
  297.   gprsetdrawvalue(opt->cpi[COLOR_BG]);
  298.   multiline(scanline, 1);               /*       erase scan line       */
  299.   if (ind)                              /* erase enemies, if necessary */
  300.     multiline(dot, ind);
  301.   temp = ca;
  302.   ca = ca * cda - sa * sda;
  303.   sa = sa * cda + sda * temp;
  304.   scanline->x2 = 60.0 * ca + 500;
  305.   scanline->y2 = 60.0 * sa + 560;
  306.   gprsetdrawvalue(opt->cpi[COLOR_SCANNER]);
  307.   multiline(scanline, 1);               /*     draw scanline           */
  308.   ind = 0;
  309.   curdot = dot;
  310.   for (g=o+opt->estart; g<o+opt->lstart; g++)
  311.     if (g->attr & IS_ALIVE && g->range <= 2000.0 && g->range != 0.0) {
  312.       nextdot = curdot + 1;
  313.       nextdot->x1 = curdot->x1 = 500 + g->prox * scale - 1;
  314.       nextdot->y2 = curdot->y1 = 560 - g->proy * scale + 1;
  315.       nextdot->x2 = curdot->x2 = curdot->x1 + 2;
  316.       nextdot->y1 = curdot->y2 = curdot->y1 - 2;
  317.       ind += 2;
  318.       curdot += 2;
  319.     }
  320.   if (ind)
  321.     multiline(dot, ind);                /* draw enemies, if necessary  */
  322.   gprsetclippingactive(True);
  323. }
  324.  
  325. void xhairs (aligned)
  326.      Bool aligned;
  327. {
  328.   static Bool last = False;
  329.   static short pt1[] = {500, 215, 500, 235, 500, 285, 500, 305, 475, 240,
  330.                           475, 235, 475, 235, 525, 235, 525, 235, 525, 240,
  331.                           475, 280, 475, 285, 475, 285, 525, 285, 525, 285,
  332.                           525, 280};
  333.   static short pt2[] = {500, 215, 500, 235, 500, 285, 500, 305, 475, 245,
  334.                           500, 235, 500, 235, 525, 245, 475, 275, 500, 285,
  335.                           500, 285, 525, 275};
  336.   static Bool draw = True;
  337.   if (draw) {
  338.     if (aligned) {
  339.       if (!last) {
  340.         gprsetdrawvalue(opt->cpi[COLOR_BG]);       /* erase the old */
  341.         multiline(pt1, 8);
  342.         last = True;
  343.       }
  344.       gprsetdrawvalue(opt->cpi[COLOR_XHAIR]);        /* draw the new */
  345.       multiline(pt2, 6);
  346.     }
  347.     else {
  348.       if (last) {
  349.         gprsetdrawvalue(opt->cpi[COLOR_BG]);       /* erase the old */
  350.         multiline(pt2, 6);
  351.         last = False;
  352.       }
  353.       gprsetdrawvalue(opt->cpi[COLOR_XHAIR]);        /* draw the new */
  354.       multiline(pt1, 8);
  355.     }
  356.   }
  357.   draw = !draw;
  358. }
  359.  
  360. void drawhorizon(azm)
  361.      float azm;
  362. {
  363.   static short horizon[] = {500, 240, 500, 240, 500, 240, 500, 240,
  364.                               500, 240, 500, 240, 500, 240, 500, 240,
  365.                               500, 240, 500, 240, 500, 240, 500, 240,
  366.                               500, 240, 500, 240, 500, 240, 500, 240,
  367.                               500, 240, 500, 240, 500, 240, 500, 240,
  368.                               500, 240, 500, 240, 500, 240, 500, 240,
  369.                               500, 240, 500, 240, 500, 240, 500, 240,
  370.                               500, 240, 500, 240, 500, 240, 500, 240,
  371.                               500, 240, 500, 240, 500, 240, 500, 240,
  372.                               500, 240, 500, 240, 500, 240, 500, 240,
  373.                               500, 240, 500, 240, 500, 240, 500, 240,
  374.                               500, 240, 500, 240, 500, 240, 500, 240};
  375.   static int number = 0;
  376.   static float rdc = 0.01745329251;
  377.   static float scale = 15.0;
  378.   static int numclust[] = {8, 12, 10, 12, 10, 10};
  379.   static int clustux[][12] = {150, 140, 150, 60, 85, -100, -50, -150, 0, 0,
  380.                                 0, 0, 150, 50, 75, 0, 0, 7, 0, -40, 0, -110,
  381.                                 -25, -150, 150, 115, 115, 105, 115, -10, 0,
  382.                                 -125, -85, -150, 0, 0, 150, 130, 150, 10, 25,
  383.                                 -35, -35, 0, -35, -140, -110, -150, 150, -10,
  384.                                 25, -70, -50, -125, -125, -100, -125, -150,
  385.                                 0, 0, 150, 100, 140, 0, 0, -30, 0, -120, -60,
  386.                                 -150, 0, 0};
  387.   static int clustuy[][12] = {160, 220, 160, 250, 225, 245, 250, 240, 0, 0, 0,
  388.                                 0, 240, 227, 245, 190, 190, 215, 190, 225, 190,
  389.                                 213, 240, 200, 200, 189, 189, 225, 189, 244,
  390.                                 250, 165, 213, 135, 0, 0, 135, 200, 135, 210,
  391.                                 225, 165, 165, 230, 165, 228, 210, 215, 215,
  392.                                 217, 230, 195, 210, 150, 150, 210, 150, 173,
  393.                                 0, 0, 173, 209, 225, 170, 170, 225, 170, 230,
  394.                                 200, 160, 0, 0};
  395.   static int pt[2];
  396.   static Bool moon = False;
  397.  
  398.   float center, xoff;
  399.   float deg, degmin, degmax;
  400.   int indmin, indmax, i, i1, j;
  401.   Bool flag1, flag2;
  402.   short* current;
  403.  
  404.   gprsetdrawvalue(opt->cpi[COLOR_BG]);
  405.   multiline(horizon, number);           /* erase horizon */
  406.   if (moon)
  407.     removepixmap(0, pt);                /* erase moon    */
  408.   gprsetdrawvalue(opt->cpi[COLOR_HORIZON]);
  409.   deg = azm / rdc;
  410.   if (deg >= 360.0)
  411.     deg -= 360.0;
  412.   degmin = deg - 30.0;
  413.   degmax = deg + 30.0;
  414.   flag1 = False;
  415.   flag2 = False;
  416.   if (degmin < 0.0) {
  417.     degmin += 360.0;
  418.     flag1 = True;
  419.   }
  420.   if (degmax >= 360.0) {
  421.     degmax -= 360.0;
  422.     flag2 = True;
  423.   }
  424.   indmin = (int) (degmin / 20.0);
  425.   indmax = (int) (degmax / 20.0) + 1;
  426.   number = 0;
  427.   current = horizon;
  428.   if (!flag1 && !flag2)
  429.     for (i=indmin; i<indmax; i++) {
  430.       center = 10.0 + i * 20.0;
  431.       xoff = (deg - center) * scale + 500.0;
  432.       i1 = i % 6;
  433.       for (j= 0; j<numclust[i1]; j++){
  434.         *current++ = clustux[i1][j] + xoff;
  435.         *current++ = clustuy[i1][j];
  436.         number++;
  437.       }
  438.     }
  439.   else if (flag1) {
  440.     for (i= indmin; i<18; i++) {
  441.       center = 10.0 + i * 20.0;
  442.       xoff = (360.0 + deg - center) * scale + 500.0;
  443.       i1 = i % 6;
  444.       for (j=0; j<numclust[i1]; j++) {
  445.         *current++ = clustux[i1][j] + xoff;
  446.         *current++ = clustuy[i1][j];
  447.         number++;
  448.       }
  449.     }
  450.     for (i=0; i<indmax; i++) {
  451.       center = 10.0 + i * 20.0;
  452.       xoff = (deg - center) * scale + 500.0;
  453.       i1 = i % 6;
  454.       for (j=0; j<numclust[i1]; j++) {
  455.         *current++ = clustux[i1][j] + xoff;
  456.         *current++ = clustuy[i1][j];
  457.         number++;
  458.       }
  459.     }
  460.   }
  461.   else {
  462.     for (i=indmin; i<18; i++) {
  463.       center = 10.0 + i * 20.0;
  464.       xoff = (deg - center) * scale + 500.0;
  465.       i1 = i % 6;
  466.       for (j=0; j<numclust[i1]; j++) {
  467.         *current++ = clustux[i1][j] + xoff;
  468.         *current++ = clustuy[i1][j];
  469.         number++;
  470.       }
  471.     }
  472.     for (i=0; i<indmax; i++) {
  473.       center = 10.0 + i * 20.0;
  474.       xoff = (deg - 360.0 - center) * scale + 500.0;
  475.       i1 = i % 6;
  476.       for (j=0; j<numclust[i1]; j++) {
  477.         *current++ = clustux[i1][j] + xoff;
  478.         *current++ = clustuy[i1][j];
  479.         number++;
  480.       }
  481.     }
  482.   }
  483.   number >>= 1;
  484.   multiline(horizon, number);           /* draw horizon */
  485.   if (deg <= 360.0 && deg >= 270.0) {
  486.     moon = True;
  487.     pt[0] = 500 + (deg - 315.0) * scale - 20;
  488.     pt[1] = 105 - 20;
  489.     putpixmap(0, pt);                   /* draw moon    */
  490.   }
  491.   else
  492.     moon = False;
  493. }
  494.  
  495. void drawcracks()
  496. {
  497.   static short pt[] = {190, 75, 270, 175, 270, 175, 230, 265, 240, 243,
  498.                          330, 290, 310, 280, 390, 235, 370, 246, 380, 195,
  499.                          200, 425, 290, 365, 270, 378, 300, 325, 630, 425,
  500.                          560, 335, 580, 361, 626, 295, 570, 348, 510, 355,
  501.                          520, 354, 490, 275, 500, 301, 440, 290, 810, 75,
  502.                          720, 125, 720, 125, 695, 205, 700, 200, 590, 210,
  503.                          630, 206, 620, 256, 710, 157, 780, 245, 770, 232,
  504.                          730, 305, 740, 287, 760, 315};
  505.  
  506.   gprsetdrawvalue(opt->cpi[COLOR_CRACKS]);
  507.   multiline(pt, 19);                    /* draw cracks */
  508. }
  509.  
  510. void clearscreen ()
  511. {
  512.   static int destorigin[] = {70, 75};
  513.   static int window[][2] = {70, 75, 860, 350};
  514.  
  515.   clearrectangle(window, destorigin);        /* erase the main viewscreen */
  516. }
  517.