home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Miscellaneous / WBStars2.0 / source / WBStars_plot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-24  |  2.9 KB  |  186 lines

  1. /* $VER: WBStars_plot.c 2.0b4 (28 May 1997)
  2. */
  3.  
  4. #include <exec/types.h>
  5. #include <exec/memory.h>
  6. #include <intuition/intuition.h>
  7. #include <proto/exec.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "WBStars_plot.h"
  11.  
  12. struct Flake
  13. {
  14.     struct Flake    *next;
  15.     struct Flake    *last;
  16.     int    x;
  17.     int    y;
  18.     int    sticky;
  19.     char    drawn;
  20.     int    dir;
  21.     char    color;
  22. };
  23.  
  24. void    NewFlake( void );
  25. void    ClearFlake(struct Flake *f);
  26.  
  27. struct Flake    *Flakes        = NULL;
  28. int         Flake_cnt    = 0;
  29.  
  30. void    InitObjects()
  31. {
  32.     /* nothing to do here */
  33. }
  34.  
  35. void    NewFlake()
  36. {
  37.     struct Flake    *f;
  38.  
  39.     if( ((Max_Objects<0)||(Flake_cnt<Max_Objects)) && (f=(struct Flake*)AllocMem(sizeof(struct Flake),0)) )
  40.     {
  41.         f->next        = Flakes;
  42.         if( Flakes!=NULL ) Flakes->last    = f;
  43.         f->last        = NULL;
  44.         f->x        = RangeRand(width);
  45.         f->y        = 0;
  46.         f->sticky    = 0;
  47.         f->drawn    = FALSE;
  48.         Flakes        = f;
  49.         Flake_cnt++;
  50.     }
  51. }
  52.  
  53. void    ClearFlake(struct Flake *f)
  54. {
  55.     if( f->next!=NULL ) f->next->last=f->last;
  56.     if( f->last!=NULL )
  57.     {
  58.         f->last->next=f->next;
  59.     }
  60.     else
  61.     {
  62.         Flakes=f->next;
  63.     }
  64.     FreeMem( f, sizeof(struct Flake) );
  65.     Flake_cnt--;
  66. }
  67.  
  68. void    ClearObjects()
  69. {
  70.     struct    Flake    *f;
  71.  
  72.     while( Flakes!=NULL )
  73.     {
  74.         ClearPixel(Flakes->x,Flakes->y,Flakes->color);
  75.  
  76.         f=Flakes->next;
  77.         FreeMem( Flakes, sizeof(struct Flake) );
  78.         Flakes=f;
  79.     }
  80.     Flake_cnt=0;
  81. }
  82.  
  83. void    PlotObjects()
  84. {
  85.     struct Flake    *f;
  86.     struct Flake    *next;
  87.     int        newx;
  88.     int        newy;
  89.     int        addx;
  90.     char        v_flut;
  91.     char        color;
  92.  
  93.     NewFlake();
  94.  
  95.     for(f=Flakes; f!=NULL; f=next)
  96.     {
  97.         next= f->next;
  98.         if( (!(f->sticky) || (Max_Stick>=0)) &! (f->sticky%Check_Stick) )
  99.         {
  100.             if( (RangeRand((V_Flutter)+100)<100) || f->sticky )
  101.             {
  102.                 newy    = f->y +1;
  103.                 v_flut    = FALSE;
  104.             }
  105.             else
  106.             {
  107.                 newy    = f->y;
  108.                 v_flut    = TRUE;
  109.             }
  110.  
  111.             if( f->dir==0 )
  112.             {
  113.                 addx    = RangeRand(3) -1;
  114.             }
  115.             else
  116.             {
  117.                 addx    = RangeRand(2)*SIGN(f->dir);
  118.             }
  119.             newx        = f->x +addx;
  120.  
  121.             LockPlotArea();
  122.  
  123.             if( (newy>=height) || (newx<0) || (newx>=width) )
  124.             {
  125.                 if(f->drawn) ClearPixel(f->x,f->y,f->color);
  126.                 ClearFlake(f);
  127.             }
  128.             else
  129.             {
  130.                 if( (color=SetPixel(newx,newy,Force))!=-1 )
  131.                 {
  132.                     if(f->drawn) ClearPixel(f->x,f->y,f->color);
  133.                     f->x        = newx;
  134.                     f->y        = newy;
  135.                     f->sticky    = 0;
  136.                     f->drawn    = TRUE;
  137.                     f->dir        = addx;
  138.                     f->color    = color;
  139.                 }
  140.                 else
  141.                 {
  142.                     if( !v_flut )
  143.                     {
  144.                         f->dir        = 0;
  145.                         if( (color=SetPixel(f->x,newy,Force))!=-1 )
  146.                         {
  147.                             if(f->drawn) ClearPixel(f->x,f->y,f->color);
  148.                             f->y        = newy;
  149.                             f->sticky    = 0;
  150.                             f->drawn    = TRUE;
  151.                             f->color    = color;
  152.                         }
  153.                         else
  154.                         {
  155.                             if( !f->drawn )
  156.                             {
  157.                                 ClearFlake(f);
  158.                             }
  159.                             else
  160.                             {
  161.                                 if( Remember || Test1Pixel(f->x,f->y) )
  162.                                 {
  163.                                     if( ((f->sticky++)>Max_Stick) && (Max_Stick>=0) )
  164.                                     {
  165.                                         ClearPixel(f->x,f->y,f->color);
  166.                                         ClearFlake(f);
  167.                                     }
  168.                                 }
  169.                                 else
  170.                                 {
  171.                                     ClearFlake(f);
  172.                                 }
  173.                             }
  174.                         }
  175.                     }
  176.                 }
  177.             }
  178.             UnlockPlotArea();
  179.         }
  180.         else
  181.         {
  182.             f->sticky++;
  183.         }
  184.     }
  185. }
  186.