home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / util / gblanker-38.8.lha / GBlanker / GSource / Blankers / Star / blank.c next >
C/C++ Source or Header  |  1994-12-02  |  3KB  |  176 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include "/includes.h"
  11.  
  12. typedef struct _Coord3D
  13. {
  14.     LONG x;
  15.     LONG y;
  16.     LONG z;
  17.     LONG speed;
  18. }
  19. Coord3D;
  20.  
  21. typedef struct _Coord2D
  22. {
  23.     LONG x;
  24.     LONG y;
  25. }
  26. Coord2D;
  27.  
  28. Coord3D *Coords;
  29. Coord2D *OldCoords;
  30.  
  31. #include "Star_rev.h"
  32. STATIC const UBYTE VersTag[] = VERSTAG;
  33.  
  34. VOID Defaults( PrefObject *Prefs )
  35. {
  36.     Prefs[0].po_Level = 250;
  37.     Prefs[2].po_Level = 100;
  38.     Prefs[4].po_ModeID = getTopScreenMode();
  39. }
  40.  
  41. VOID InitStar( Coord3D *p, LONG speed )
  42. {
  43.     p->x = 1500 - ( LONG )RangeRand( 3000 );
  44.     p->y = 1000 - ( LONG )RangeRand( 2000 );
  45.     p->z = 1000 + ( LONG )RangeRand( 2000 );
  46.     p->speed = ( LONG )RangeRand( 10 ) + speed;
  47. }
  48.  
  49. LONG Blank( PrefObject *Prefs )
  50. {
  51.     LONG ToFrontCount = 0, Wid, Hei, i, x, y, Stars, Speed, RetVal = OK;
  52.     struct RastPort *Rast;
  53.     struct Screen *Scr;
  54.     struct Window *Wnd;
  55.     Coord3D *p;
  56.     Coord2D *p2;
  57.     
  58.     Stars = Prefs[0].po_Level;
  59.     Speed = Prefs[2].po_Level;
  60.     
  61.     Coords = AllocVec( Stars * sizeof( Coord3D ), MEMF_CLEAR );
  62.     OldCoords = AllocVec( Stars * sizeof( Coord2D ), MEMF_CLEAR );
  63.     Scr = OpenScreenTags( 0L, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD,
  64.                          SA_DisplayID, Prefs[4].po_ModeID, SA_Behind, TRUE,
  65.                          SA_Quiet, TRUE, TAG_DONE );
  66.  
  67.     if( Coords && OldCoords && Scr )
  68.     {
  69.         Wid = Scr->Width;
  70.         Hei = Scr->Height;
  71.         
  72.         Rast = &( Scr->RastPort );
  73.         SetRast( Rast, 0 );
  74.         for( i = 0; i < 4; i++ )
  75.             SetRGB4(&( Scr->ViewPort ), i, 4 * i, 4 * i, 4 * i );
  76.         
  77.         for( i = 0; i < Stars; i++ )
  78.         {
  79.             InitStar( &Coords[i], Speed );
  80.             OldCoords[i].x = 0;
  81.             OldCoords[i].y = 0;
  82.         }
  83.         
  84.         Wnd = BlankMousePointer( Scr );
  85.         ScreenToFront( Scr );
  86.         
  87.         while( RetVal == OK )
  88.         {
  89.             WaitTOF();
  90.  
  91.             if(!( ++ToFrontCount % 60 ))
  92.                 ScreenToFront( Scr );
  93.             
  94.             for( p2 = OldCoords, p = Coords, i = 0;
  95.                 i < Stars; i++, p++, p2++ )
  96.             {
  97.                 x = p2->x;
  98.                 y = p2->y;
  99.                 
  100.                 SetAPen( Rast, 0 );
  101.                 switch( p->z / 200 )
  102.                 {
  103.                 case 0:
  104.                     WritePixel( Rast, x, y+1 );
  105.                     WritePixel( Rast, x+1, y+1 );
  106.                 case 1:
  107.                 case 2:
  108.                 case 3:
  109.                 case 4:
  110.                     WritePixel( Rast, x+1, y );
  111.                 default:
  112.                     WritePixel( Rast, x, y );
  113.                 }
  114.  
  115.                 p->z -= p->speed;
  116.                 if( p->z <= -1000 )
  117.                     InitStar( p, Speed );
  118.                 
  119.                 x = Wid/2 + ( 200 * p->x ) / ( p->z + 1000 );
  120.                 y = Hei/2 + ( 200 * p->y ) / ( p->z + 1000 );
  121.                 
  122.                 if(( x < 0 )||( x > Wid-2 )||( y < 0 )||( y > Hei-2 ))
  123.                 {
  124.                     InitStar( p, Speed );
  125.                     p2->x = 0;
  126.                     p2->y = 0;
  127.                 }
  128.                 else
  129.                 {
  130.                     p2->x = x;
  131.                     p2->y = y;
  132.                     SetAPen( Rast, 3 );
  133.                     /* Warning: This is a little twisted. */
  134.                     switch( p->z/200 )
  135.                     {
  136.                     case 9:
  137.                     case 8:
  138.                         SetAPen( Rast, 2 );
  139.                         break;
  140.                     case 0:
  141.                         WritePixel( Rast, x, y+1 );
  142.                         WritePixel( Rast, x+1, y+1 );
  143.                     case 4:
  144.                     case 3:
  145.                     case 2:
  146.                     case 1:
  147.                         WritePixel( Rast, x+1, y );
  148.                     case 7:
  149.                     case 6:
  150.                     case 5:
  151.                         break;
  152.                     default:
  153.                         SetAPen( Rast, 1 );
  154.                         break;
  155.                     }
  156.                     WritePixel( Rast, x, y );
  157.                 }
  158.             }
  159.             if(!( ToFrontCount % 5 ))
  160.                 RetVal = ContinueBlanking();
  161.         }
  162.         UnblankMousePointer( Wnd );
  163.     }
  164.     else
  165.         RetVal = FAILED;
  166.  
  167.     if( Scr )
  168.         CloseScreen( Scr );
  169.     if( Coords )
  170.         FreeVec( Coords );
  171.     if( OldCoords )
  172.         FreeVec( OldCoords );
  173.  
  174.     return RetVal;
  175. }
  176.