home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / AT_WORLD / ATRIW1.MSA / OTHER_MODULES_POLLYMOD_POLLYMOD.C < prev    next >
C/C++ Source or Header  |  1994-04-23  |  12KB  |  258 lines

  1.  
  2.  
  3. /************************************************************************************************************************************************************/
  4. /*                                                                                                                                                                                                                             */
  5. /*                                        Pollymod.c Dark Lord Module written By Bill Self                                                                                                 */
  6. /*                                                           23 Apr 94                                                                                                                       */
  7. /************************************************************************************************************************************************************/
  8.  
  9. #include "vdi.h"
  10. #include "stdlib.h"
  11. #include "mod_head.h"
  12. #include "osbind.h"
  13.  
  14.  
  15. #define BLACK 0
  16.  
  17. #ifndef TRUE
  18. #define TRUE 1
  19. #define FALSE 0
  20. #endif
  21.  
  22. int calc_num(int, int);
  23.  
  24. int main(DKL_INFO *dark_pars)
  25. {
  26.  
  27. short handle, xres, yres;
  28. short pxy[4];
  29. int *exit_flag;
  30. int max_colours;
  31. short x,coloura,colourb,totala,totalb,colour_changea,colour_changeb;
  32.  
  33. int no_recs,col_change,poly_speed,speed,def_sides,count;
  34. int num_recs[2];
  35. short num[2][10];
  36. short coords1[17][10];                                                 /* Coordinates for 1st rectangle                        */
  37. short direction[2][10];                                                 /* Direction individual coordinates are moving    */
  38. short coords2[17][10];                                                 /* Coordinates for second rectangles                 */    
  39. int sides[2][22];
  40.  
  41.  
  42.     xres=dark_pars->dk_xres;                                         /* Screen size x axis                                      */ 
  43.     yres=dark_pars->dk_yres;                                         /* Screen size y axis                                      */
  44.     handle=dark_pars->dk_handle;                                         /* Workstation handle                                      */
  45.     exit_flag=dark_pars->dklord_flag;                                     /* Watch for it to become TRUE                          */
  46.     max_colours=dark_pars->dk_pens;                                         /* Max no of colours (screen res)                    */
  47.     num_recs[0]=dark_pars->dk_start1;                                     /* No of trailing rectangles 1st rectangle set    */
  48.     num_recs[1]=dark_pars->dk_start2;                                     /* No of trailing rectangles 2nd rectangle set    */
  49.     col_change=dark_pars->dk_start3;                                     /* Speed of colour change                               */
  50.     no_recs=dark_pars->dk_flag1;                                         /* Draw one or both sets, delete old etc          */
  51.     poly_speed=dark_pars->dk_flag2;                                         /* Rate of progres for rectangles,                   */
  52.     def_sides=dark_pars->dk_flag3;                                         /* No of sides of rectangles to draw                 */
  53.     
  54.     pxy[0]=0;
  55.     pxy[1]=0;
  56.     pxy[2]=xres;
  57.     pxy[3]=yres;
  58.     vs_clip(handle, TRUE, pxy);                                         /* set clip rectangle                                */
  59.  
  60.     for (x=0;x<8;x=x+2){ 
  61.         coords1[0][x]=(short)calc_num(1,xres);                                 /* Initialize coordinates with random numbers  */
  62.         coords2[0][x]=(short)calc_num(1,xres);                                 /* x axis first                                         */
  63.     }
  64.  
  65.     for (x=1;x<8;x=x+2){
  66.         coords1[0][x]=(short)calc_num(1,yres);                                 /* Then the y axis                                      */
  67.         coords2[0][x]=(short)calc_num(1,yres);
  68.     }
  69.     coords1[0][8]=coords1[0][0];                                           /* Ensure the rectangles fourth edge           */
  70.     coords1[0][9]=coords1[0][1];                                                                         /*                joins the first corner          */
  71.  
  72.     coords2[0][8]=coords2[0][0];
  73.     coords2[0][9]=coords2[0][1];
  74.  
  75.     for (x=0;x<17;++x){                                               /* Initialize all elements in coordinate       */
  76.         copy_coords(coords1);                                                 /*                   arrays with coords above     */
  77.         copy_coords(coords2);
  78.     }
  79.  
  80.     for (x=0;x<10;++x){
  81.         direction[0][x]=0;                                         /* Initialize other variables and arrays          */
  82.         direction[1][x]=1;
  83.     }
  84.  
  85.     switch (poly_speed){                                             /* Find which speed selected by user                 */
  86.     case 1 :speed=50;                                             /* and set the speed variable accordingly         */
  87.         break;        
  88.     case 2 :speed=35;                                             /* Poly_speed = DarkLord flag2                          */
  89.         break;
  90.     case 3 :speed=20;
  91.         break;
  92.     case 4 :speed=15;
  93.         break;
  94.     case 5 :speed=10;
  95.         break;
  96.     case 6 :speed=03;
  97.         break;
  98.     default:speed=10;
  99.         }
  100.  
  101.     for(x=0;x<10;++x){
  102.         num[0][x] = (short)calc_num(1,speed);                            /* Initialize num array with random numbers between    */
  103.         num[1][x] = (short)calc_num(1,speed);                            /* 1 and the max speed chosen above from flag 2           */
  104.     }
  105.  
  106.     for (x=0;x<21;++x){
  107.         keep_sides(sides);
  108.     }
  109.     totala=0;                                            /* Initialize more variables,                             */
  110.     totalb=0;                                                                                       /*             totala & b = speed of colour change  */
  111.     count=0;                                             /* count = how long before clearing screen,                        */
  112.  
  113.     coloura=(short)calc_num(1,max_colours);                                /* Get colour for first polygon                        */
  114.     colourb=(short)calc_num(1,max_colours);                                /* Get colour for second polygon                       */
  115.  
  116.     colour_changea = calc_num(1,col_change);                            /* Initial time to change colour a                     */
  117.     colour_changeb = calc_num(1,col_change);                            /* Initial time to change colour b                     */
  118.  
  119.     while(*exit_flag) {
  120.  
  121.         if ((no_recs==5 || no_recs==6) && count==5000){
  122.             v_clrwk(handle);                                /* If option selected, flag1, and count reached        */
  123.             count=0;                                    /* threshold, clear the screen and                  */
  124.         }                                                                                       /*              reset count variables               */
  125.  
  126.         keep_sides(sides);                                                                      /* Keep record of num sides drawn for each rectangle*/
  127.  
  128.         if (def_sides==6)sides[0][0]=calc_num(1,6);                        /* If random no of sides selected choose no of            */
  129.         else sides[0][0]=def_sides;                                /* sides to draw, else use flag as is.                       */
  130.  
  131.         vsl_color(handle,coloura);                                /* Set colour to draw with.                                     */
  132.         v_pline (handle,sides[0][0],coords1[0]);                         /* Draw rectangle with first set of coords                */
  133.         vsl_color(handle,BLACK);                                /* Select colour Black to erase trail                        */
  134.         if (no_recs==1 || no_recs==2) v_pline (handle,sides[0][num_recs[0]+1],coords1[num_recs[0]+1]);
  135.  
  136.                                                     /* if selected flag1 erase last polygon according      */
  137.                                                     /* to length of trail selected coords[num_recs[0]+1]*/
  138.         vsl_color(handle,colourb);                                /* select colour to draw second rectangle with            */
  139.         if (no_recs==2 || no_recs==4 || no_recs==6){
  140.             v_pline (handle,sides[0][0],coords2[0]);                    /* do second rectangle if flag set                           */
  141.             vsl_color(handle,BLACK);                            /* Colour to Black to erase last rectangle in trail */ 
  142.             if (no_recs==2) v_pline (handle,sides[0][num_recs[1]+1],coords2[num_recs[1]+1]);/* as above for second set                             */
  143.         }
  144.         
  145.  
  146.         if (totala == colour_changea){                                  /* is it time to change colour for the first set       */ 
  147.             coloura=(short)calc_num(1,max_colours);                        /* if so choose random colour <= max_colours        */
  148.             colour_changea = calc_num(1,col_change);                    /* reset time to change colour (random number             */
  149.             totala = 0;                                    /* between 1 and col_change(DarkLord variable3)           */
  150.         }
  151.         if (totalb == colour_changeb){                                /* as above but for second set of rectangles              */
  152.             colourb=(short)calc_num(1,max_colours);
  153.             colour_changeb = calc_num(1,col_change);
  154.             totalb = 0;
  155.         }
  156.  
  157.         copy_coords(coords1);                                    /* Back up coordinates for both sets of rectangles     */
  158.         copy_coords(coords2);
  159.  
  160.  
  161.         for (x=0;x<8;x=x+2){                                    /* Get the new coorditates for the x axis                 */
  162.             do_coord(coords1,&direction[0],x,xres,&num[0],&speed);
  163.         }
  164.  
  165.         for (x=1;x<8;x=x+2){                                    /* Get the new coordinates for the y axis                 */
  166.             do_coord(coords1,&direction[0],x,yres,&num[0],&speed);
  167.         }
  168.  
  169.         coords1[0][8]=coords1[0][0];                                /* Join up the rectangle                                        */
  170.         coords1[0][9]=coords1[0][1];
  171.  
  172.         for (x=0;x<8;x=x+2){                                    /* as above but for the second rectangle set              */
  173.             do_coord(coords2,&direction[1],x,xres,&num[1],&speed);
  174.         }        
  175.         for (x=1;x<8;x=x+2){
  176.             do_coord(coords2,&direction[1],x,yres,&num[1],&speed);
  177.         }
  178.         coords2[0][8]=coords2[0][0];
  179.         coords2[0][9]=coords2[0][1];        
  180.  
  181.         totala++;
  182.         totalb++;                                        /* Increment counters                               */
  183.         count++;
  184.     }
  185.     return 0;
  186. }
  187.  
  188.  
  189. /* -------------------------------------------------------------------- */
  190. int calc_num(int min, int max)
  191. {
  192. int diff;                                                /* Function to return a random                            */
  193.                                                                                                         /*                    number between min and max    */
  194.     diff=max-min;
  195.     if(!diff) diff=1;          /* avoid divide-by-zero exception */
  196.     return ((Random()%diff)+min);
  197. }
  198. /* -------------------------------------------------------------------- */
  199.  
  200. do_coord(coord,direct,point,screen_max,n,speed)                                /* This is the important bit, deals with one coord  */
  201. short coord[17][10];                                                                                    /* at a time, checks which direction it is going in */
  202. short direct[];                                                                                         /* and if it's not at the edge of the screen,       */
  203. short n[];                                                                                              /* sends it on it's merry way.                      */
  204.  
  205. short screen_max;
  206. short point;
  207. int *speed;
  208.  
  209. {     
  210.     if (coord[0][point] <= (screen_max-(*speed+1)) && direct[point]==1){                /* Is coord at the screen boundry                      */
  211.         coord[0][point] = coord[0][point] + n[point];                        /* If not continue in that direction                   */
  212.         direct[point]=1;
  213.     }
  214.     else {
  215.         if (direct[point] == 1) {                                   /* If direction about to change                        */
  216.             n[point] = (short)calc_num(1,*speed);                               /* set new speed for this coord                           */
  217.         }
  218.         coord[0][point] = coord[0][point] - n[point];                        /* Change direction of coord                              */
  219.         direct[point]=0;
  220.     }
  221.     if (coord[0][point] >= (*speed+1) && direct[point]==0){                     /* is coord at left (x axis) or top (y axis) of     */
  222.         coord[0][point] = coord[0][point] - n[point];                        /*    screen if not continue in that direction                        */
  223.         direct[point]=0;
  224.     }
  225.     else {
  226.         if (direct[point] == 0) {
  227.             n[point] = (short)calc_num(1,*speed);                        /* If about to change direction get new speed value    */
  228.         }
  229.         coord[0][point] = coord[0][point] + n[point];                        /* if the coordinate has reached the boundry change    */
  230.         direct[point]=1;
  231.     }
  232. return 0;            
  233. }
  234.  
  235. copy_coords(coords)
  236. short coords[17][10];
  237.  
  238. {
  239. short x,y;
  240.  
  241.     for (x=16;x>0;--x){                            /* Function to copy coords to next down the line in the coords array.          */
  242.         for (y=0;y<10;y++){                        /* Backs up previous coords in array.                                                         */
  243.             coords[x][y]=coords[x-1][y];
  244.         }
  245.     }
  246.     return 0;
  247. }
  248.  
  249.  
  250. keep_sides(sides)                                /* Function to retain the number of sides drawn for each rectangle          */
  251. int sides[2][22];                                                               /*   necessary when random sides chosen, it's be a strange choice but still */
  252. {
  253. short x;
  254.     for (x=22;x>0;--x){
  255.         sides[0][x]=sides[0][x-1];
  256.     }
  257.     return 0;
  258. }