home *** CD-ROM | disk | FTP | other *** search
/ Aztec Shareware Collection / ARCADE_1.ISO / snarf / edit.c < prev    next >
C/C++ Source or Header  |  1988-01-10  |  8KB  |  344 lines

  1. #include    <stdio.h>
  2. #include    <fcntl.h>
  3. #include    <math.h>
  4. #include    "snarf.h"
  5.  
  6. /****************************************************************
  7.  * BEYOND HERE, THE CODE IS DEVELOPMENT ROUTINES ONLY. THEY CAN    *
  8.  * BE TRASHED WHEN THE CODE DEVELOPMENT CYCLE IS FINISHED.    *
  9.  ****************************************************************/
  10.  
  11. void    choose_palette() {
  12.  
  13.     int    color, i;
  14.  
  15.     color = 1;
  16.     while(1) {
  17.         setpalette(color, 1);
  18.         i = key();
  19.         setpalette(color, 0);
  20.         switch(i) {
  21.             case 0x4d00:    /* rtcurs */
  22.                 color = (++color) & 15;
  23.                 break;
  24.             case 0x4b00:    /* lfcurs */
  25.                 color = (--color) & 15;
  26.                 break;
  27.             case 0x4800:    /* upcurs */
  28.                 palette[color] = (++palette[color]) & 63;
  29.                 break;
  30.             case 0x5000:    /* dncurs */
  31.                 palette[color] = (--palette[color]) & 63;
  32.                 break;
  33.             case 0x011b:    /* esc    */
  34.                 return;
  35.             default:
  36.                 beepon(14000);
  37.                 for(i=0; i<500; i++) iskey();
  38.                 beepoff();
  39.                 break;
  40.         }
  41.     }
  42. }
  43.  
  44.  
  45. void    choose_colors() {
  46.  
  47.     int    i, color;
  48.     char    temp[81];
  49.  
  50.     color = 0;
  51.     while(1) {
  52.         sprintf(temp, "color: %d = %d  ", color, colors[color]);
  53.         flabel(400, YMAX+18, temp, 15, 0, 0);
  54.         i = key();
  55.         switch( i ) {
  56.          case 0x4d00:    /* rtcurs */
  57.             if(color<MAXCOLOR-1) ++color;
  58.             break;
  59.          case 0x4b00:    /* lfcurs */
  60.             if(color) --color;
  61.             break;
  62.          case 0x4800:    /* upcurs */
  63.             colors[color] = (++colors[color]) & 15;
  64.             break;
  65.          case 0x5000:    /* dncurs */
  66.             colors[color] = (--colors[color]) & 15;
  67.             break;
  68.          case 0x011b:    /* esc    */
  69.             return;
  70.          default:
  71.             beepon(14000);
  72.             for(i=0; i<500; i++) iskey();
  73.             beepoff();
  74.             break;
  75.         }
  76.     }
  77. }
  78.  
  79.  
  80.  
  81. void    up_walls() {
  82.  
  83.     int    i, j, k, t;
  84.     unsigned char    *p, c;
  85.  
  86.     for(i=0; i<90; i++) walls[curwall][i] = 0;
  87.     for(i=0; i<MAXGOODIES; i++) {
  88.         treasure[curwall][i].x = 0;
  89.         treasure[curwall][i].y = 0;
  90.         treasure[curwall][i].item = 0;
  91.     }
  92.     t = 0;
  93.     for(i=1; i<19; i++) {
  94.         for(j=1; j<40; j++) {
  95.             switch( (c=field[i*41+j]) & 0xf0 ) {
  96.              case 0x00:    /* WALL */
  97.                 if( c ) walls[curwall][(i-1)*5+((j-1)>>3)] |= (0x80>>((j-1)&7));
  98.                 break;
  99.              case 0x10:    /* TELEPORT */
  100.                 if( t<MAXOBJECTS && (c & 0xfe)==0x14) {
  101.                     treasure[curwall][t].x = j;
  102.                     treasure[curwall][t].y = i;
  103.                     treasure[curwall][t].item = c;
  104.                     ++t;
  105.                 }                    
  106.                 break;
  107.              case 0x20:    /* PIT */
  108.                 if( t<MAXOBJECTS && (c & 1) ) {
  109.                     treasure[curwall][t].x = j;
  110.                     treasure[curwall][t].y = i;
  111.                     treasure[curwall][t].item = c;
  112.                     ++t;
  113.                 }                    
  114.                 break;
  115.              case 0x30:    /* MAN start position */
  116.              case 0x40:    /* TREASURE */
  117.              case 0x60:    /* KEY */
  118.              case 0x70:    /* LOCK */
  119.              case 0x80:    /* TAGBOOST */
  120.                 if( t<MAXOBJECTS ) {
  121.                     treasure[curwall][t].x = j;
  122.                     treasure[curwall][t].y = i;
  123.                     treasure[curwall][t].item = c;
  124.                     ++t;
  125.                 }                    
  126.                 break;
  127.              default:
  128.                 break;
  129.             }
  130.         }
  131.     }
  132. }
  133.  
  134. void    edit_error() {
  135.  
  136.     int    i;
  137.  
  138.     beepon(10000);
  139.     for(i=0; i<500; i++) iskey();
  140.     beepoff();
  141. }
  142.  
  143. int    empty(x,y)
  144. int    x,y;
  145. {
  146.     unsigned char    c;
  147.  
  148.     c = field[y*41+x] & 0xf0;
  149.     if( c==0x30 || c==0xf0 ) return 0;
  150.     return 1;
  151. }
  152.  
  153.  
  154. int    ewx=20, ewy=9;
  155.  
  156. void    edit_walls() {
  157.  
  158.     int    i, j, k;
  159.     unsigned char    *p, temp[81];
  160.     FILE    *fp;
  161.  
  162.     curscreen = curwall-1;
  163. ewstart:
  164.     curscreen = curwall+1;
  165.     next_screen();
  166.     field[(19-(mans.y>>4))*41+(mans.x>>4)+1] = 0x30;
  167.  
  168.     flabel(0, 8, "F1-save  F2-tagboo  F3-field  F4-teleport  F5-lock  F6-key  F7-gold  F8-pit  F9-wall  F10-man  ESC-end_edit",15,0,0);
  169.     while(1) {
  170.         while( !iskey() ) {
  171.             horline(XORG-4+((ewx-1)<<4), YORG-8+((19-ewy)<<4), XORG+4+(ewx<<4), 15, 3);
  172.             verline(XORG+8+((ewx-1)<<4), YORG+4+((19-ewy)<<4), YORG-4+((18-ewy)<<4), 15, 3);
  173.             for(i=0; i<500 && !iskey(); i++) ;
  174.             horline(XORG-4+((ewx-1)<<4), YORG-8+((19-ewy)<<4), XORG+4+(ewx<<4), 15, 3);
  175.             verline(XORG+8+((ewx-1)<<4), YORG+4+((19-ewy)<<4), YORG-4+((18-ewy)<<4), 15, 3);
  176.             for(i=0; i<200 && !iskey(); i++) ;
  177.         }
  178.          p = &field[ewy*41+ewx];
  179.         switch( key() ) {
  180.          case 0x3b00:    /* f1 */
  181.             up_walls();
  182.             sprintf(temp,"WALL%d", curwall);
  183.             fp = fopen(temp, "w");
  184.             fprintf(fp, "walls\n");
  185.             for(i=0; i<18; i++) {
  186.                 fprintf(fp, "\t\t");
  187.                 for(j=0; j<5; j++) {
  188.                     fprintf(fp, "0x%2.2x, ", walls[curwall][i*5+j]);
  189.                 }
  190.                 fprintf(fp, "\n");
  191.             }
  192.             fprintf(fp, "treasure\n");
  193.             for(i=0; i<MAXOBJECTS; i++) {
  194.                 if(treasure[curwall][i].x==0) continue;
  195.                 fprintf(fp, "\t\t0x%2.2x, 0x%2.2x, 0x%2.2x,\n",treasure[curwall][i].x,treasure[curwall][i].y,treasure[curwall][i].item);
  196.             }
  197.             fclose(fp);
  198.             break;
  199.          case 0x3c00:    /* f2 */
  200.             disp_field( ewx, ewy );
  201.             *p = 0x80;
  202.             disp_field( ewx, ewy );
  203.             break;
  204.          case 0x3d00:    /* f3 */
  205.             up_walls();
  206.             goto ewstart;
  207.          case 0x5600:    /* shift f3 */
  208.             up_walls();
  209.             if( (curwall -= 2) < 0 ) curwall += MAXWALLS;
  210.             goto ewstart;
  211.          case 0x3e00:    /* f4 */
  212.             disp_field( ewx, ewy );
  213.             disp_field( ewx-1, ewy);
  214.             disp_field( ewx+1, ewy);
  215.             switch( key() ) {
  216.              case 0x4800:    /* up cursor */
  217.                 *p = 0x15;
  218.                 *(p+1) = 0x13;
  219.                 *(p-1) = 0x12;
  220.                 break;
  221.              case 0x5000:    /* dn cursor */
  222.                 *p = 0x14;
  223.                 *(p+1) = 0x11;
  224.                 *(p-1) = 0x10;
  225.                 break;
  226.              default:
  227.                 *p = 0;
  228.                 break;
  229.             }
  230.             disp_field( ewx, ewy );
  231.             disp_field( ewx-1, ewy);
  232.             disp_field( ewx+1, ewy);
  233.             break;
  234.          case 0x3f00:    /* f5 */
  235.             disp_field( ewx, ewy );
  236.             *p = 0x70;
  237.             disp_field( ewx, ewy );
  238.             break;
  239.          case 0x4000:    /* f6 */
  240.             disp_field( ewx, ewy );
  241.             *p = 0x60;
  242.             disp_field( ewx, ewy );
  243.             break;
  244.          case 0x4100:    /* f7 */
  245.             disp_field(ewx, ewy);
  246.             switch( *p ) {
  247.              case 0:
  248.                 *p = 0x3f;
  249.              case 0x40:
  250.              case 0x41:
  251.              case 0x42:
  252.                 *p = ++(*p);
  253.                 disp_field(ewx, ewy);
  254.                 break;
  255.              default:
  256.                 *p = 0;
  257.                 break;
  258.             }
  259.             break;
  260.          case 0x011b:    /* esc */
  261.             return;
  262.          case 0x4d00:    /* rtcurs */
  263.             if(ewx<39) ++ewx;
  264.             break;
  265.          case 0x4800:    /* upcurs */
  266.             if(ewy>1) --ewy;
  267.             break;
  268.          case 0x4b00:    /* lfcurs */
  269.             if(ewx>1) --ewx;
  270.             break;
  271.          case 0x5000:    /* dncurs */
  272.             if(ewy<18) ++ewy;
  273.             break;
  274.          case 0x4200:    /* f8 */
  275.             disp_field(ewx, ewy);
  276.             switch( key() ) {
  277.              case 0x4d00:    /* rtcurs */
  278.                 disp_field( ewx, ewy+1);
  279.                 disp_field( ewx, ewy-1);
  280.                 *p = 0x21;
  281.                 *(p-41) = 0x2a;
  282.                 *(p+41) = 0x20;
  283.                 disp_field(ewx, ewy);
  284.                 disp_field(ewx, ewy+1);
  285.                 disp_field(ewx, ewy-1);
  286.                 break;
  287.              case 0x4800:    /* upcurs */
  288.                 disp_field( ewx+1, ewy);
  289.                 disp_field( ewx-1, ewy);
  290.                 *p = 0x23;
  291.                 *(p-1) = 0x2e;
  292.                 *(p+1) = 0x24;
  293.                 disp_field(ewx, ewy);
  294.                 disp_field(ewx+1, ewy);
  295.                 disp_field(ewx-1, ewy);
  296.                 break;
  297.              case 0x4b00:    /* lfcurs */
  298.                 disp_field( ewx, ewy+1);
  299.                 disp_field( ewx, ewy-1);
  300.                 *p = 0x25;
  301.                 *(p-41) = 0x26;
  302.                 *(p+41) = 0x22;
  303.                 disp_field(ewx, ewy);
  304.                 disp_field(ewx, ewy+1);
  305.                 disp_field(ewx, ewy-1);
  306.                 break;
  307.              case 0x5000:    /* dncurs */
  308.                 disp_field( ewx+1, ewy);
  309.                 disp_field( ewx-1, ewy);
  310.                 *p = 0x27;
  311.                 *(p-1) = 0x2c;
  312.                 *(p+1) = 0x28;
  313.                 disp_field(ewx, ewy);
  314.                 disp_field(ewx+1, ewy);
  315.                 disp_field(ewx-1, ewy);
  316.                 break;
  317.              default:
  318.                 *p = 0;
  319.                 break;
  320.             }
  321.             break;
  322.          case 0x4300:    /* f9 */
  323.             if( *p ) {
  324.                 disp_field(ewx, ewy);
  325.                 *p = 0;
  326.             } else {
  327.                  *p = 1;
  328.                 disp_field(ewx, ewy);
  329.             }
  330.             break;
  331.          case 0x4400:    /* f10 */
  332.             show_man();
  333.             *p = 0x30;
  334.              field[(19-(mans.y>>4))*41+(mans.x>>4)+1] = 0;
  335.             mans.x = (ewx-1)<<4;
  336.             mans.y = (19-ewy)<<4;
  337.             show_man();
  338.             break;
  339.          default:
  340.             break;
  341.         }
  342.     }
  343. }
  344.