home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / star / blank.c next >
C/C++ Source or Header  |  1994-10-08  |  4KB  |  221 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/types.h>
  10. #include <exec/memory.h>
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <dos/dos.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/graphics_protos.h>
  19. #include <clib/alib_protos.h>
  20.  
  21. #include "/Garshnelib/Garshnelib_protos.h"
  22. #include "/Garshnelib/Garshnelib_pragmas.h"
  23.  
  24. #include "Star.h"
  25. #include "//defs.h"
  26. #include "/main.h"
  27.  
  28. #define    DE    200
  29. #define    de    1000
  30.  
  31. #define WRITEPIXEL( r, x, y ) { if(( x >= 0 )&&( x < Wid )&&( y >= 0 )&&( y < Hei )) WritePixel( r, x, y ); }
  32.  
  33. struct ModulePrefs
  34. {
  35.     LONG Mode;
  36.     LONG Stars;
  37.     LONG Speed;
  38. };
  39.  
  40. struct pt_3d
  41. {
  42.     LONG x;
  43.     LONG y;
  44.     LONG z;
  45.     LONG speed;
  46. };
  47.  
  48. struct pt_2d
  49. {
  50.     LONG x;
  51.     LONG y;
  52. };
  53.  
  54. extern struct ModulePrefs nP;
  55.  
  56. struct pt_3d *tab_pt_3d;
  57. struct pt_2d *tab_old;
  58.  
  59. void new_star( struct pt_3d *p, LONG speed )
  60. {
  61.     p->x = 1500 - ( LONG )RangeRand( 3000 );
  62.     p->y = 1000 - ( LONG )RangeRand( 2000 );
  63.     p->z = 1000 + ( LONG )RangeRand( 2000 );
  64.     p->speed = ( LONG )RangeRand( 10 ) + speed;
  65. }
  66.  
  67. LONG Blank( VOID *Prefs )
  68. {
  69.     struct ModulePrefs *mP;
  70.     struct RastPort *Rast;
  71.     struct Screen *Scr;
  72.     struct Window *Wnd;
  73.     struct pt_3d *p;
  74.     struct pt_2d *p2;
  75.     LONG ToFrontCount = 0, Wid, Hei, i, x, y, Stars, Speed, RetVal = OK;
  76.     
  77.     if( StarWnd )
  78.         mP = &nP;
  79.     else
  80.         mP = ( struct ModulePrefs * )Prefs;
  81.     
  82.     Stars = mP->Stars;
  83.     Speed = mP->Speed;
  84.     
  85.     tab_pt_3d = AllocVec( Stars * sizeof( struct pt_3d ), MEMF_CLEAR );
  86.     tab_old = AllocVec( Stars * sizeof( struct pt_2d ), MEMF_CLEAR );
  87.     Scr = OpenScreenTags( 0L, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD,
  88.                          SA_DisplayID, mP->Mode, SA_Quiet, TRUE, SA_Behind,
  89.                          TRUE, TAG_DONE );
  90.     
  91.     if( tab_pt_3d && tab_old && Scr )
  92.     {
  93.         Wid = Scr->Width;
  94.         Hei = Scr->Height;
  95.         
  96.         Rast = &( Scr->RastPort );
  97.         SetRast( Rast, 0 );
  98.         for( i = 0; i < 4; i++ )
  99.             SetRGB4(&( Scr->ViewPort ), i, 4 * i, 4 * i, 4 * i );
  100.         
  101.         for( i = 0; i < Stars; i++ )
  102.         {
  103.             new_star( &tab_pt_3d[i], Speed );
  104.             tab_old[i].x = 0;
  105.             tab_old[i].y = 0;
  106.         }
  107.         
  108.         Wnd = BlankMousePointer( Scr );
  109.         ScreenToFront( Scr );
  110.         
  111.         while( RetVal == OK )
  112.         {
  113.             WaitTOF();
  114.  
  115.             if(!( ++ToFrontCount % 60 ))
  116.                 ScreenToFront( Scr );
  117.             
  118.             p2 = tab_old;
  119.             p = tab_pt_3d;
  120.             for( i = 0; i < Stars; i++ )
  121.             {
  122.                 x = p2->x;
  123.                 y = p2->y;
  124.                 
  125.                 SetAPen( Rast, 0 );
  126.                 if( p->z > 1000 )
  127.                 {
  128.                     WRITEPIXEL( Rast, x, y );
  129.                 }
  130.                 else
  131.                 {
  132.                     if( p->z > 200 )
  133.                     {
  134.                         WRITEPIXEL( Rast, x, y );
  135.                         WRITEPIXEL( Rast, x+1, y );
  136.                     }
  137.                     else
  138.                     {
  139.                         WRITEPIXEL( Rast, x, y );
  140.                         WRITEPIXEL( Rast, x+1, y );
  141.                         WRITEPIXEL( Rast, x, y+1 );
  142.                         WRITEPIXEL( Rast, x+1, y+1 );
  143.                     }
  144.                 }
  145.                 p->z -= p->speed;
  146.                 if( p->z <= -de )
  147.                     new_star( p, Speed );
  148.                 
  149.                 x = Wid/2 + ( DE * p->x ) / ( p->z + de );
  150.                 y = Hei/2 + ( DE * p->y ) / ( p->z + de );
  151.                 
  152.                 if(( x < 0 )||( x >= Wid )||( y < 0 )||( y >= Hei ))
  153.                 {
  154.                     new_star( p, Speed );
  155.                     p2->x = 0;
  156.                     p2->y = 0;
  157.                 }
  158.                 else
  159.                 {
  160.                     p2->x = x;
  161.                     p2->y = y;
  162.                     if( p->z > 2000 )
  163.                     {
  164.                         SetAPen( Rast, 1 );
  165.                         WRITEPIXEL( Rast, x, y );
  166.                     }
  167.                     else
  168.                     {
  169.                         if( p->z > 1500 )
  170.                         {
  171.                             SetAPen( Rast, 2 );
  172.                             WRITEPIXEL( Rast, x, y );
  173.                         }
  174.                         else
  175.                         {
  176.                             if( p->z > 1000 )
  177.                             {
  178.                                 SetAPen( Rast, 3 );
  179.                                 WRITEPIXEL( Rast, x, y );
  180.                             }
  181.                             else
  182.                             {
  183.                                 if( p->z > 200 )
  184.                                 {
  185.                                     SetAPen( Rast, 3 );
  186.                                     WRITEPIXEL( Rast, x, y );
  187.                                     WRITEPIXEL( Rast, x+1, y );
  188.                                 }
  189.                                 else
  190.                                 {
  191.                                     SetAPen( Rast, 3 );
  192.                                     WRITEPIXEL( Rast, x, y );
  193.                                     WRITEPIXEL( Rast, x+1, y );
  194.                                     WRITEPIXEL( Rast, x, y+1 );
  195.                                     WRITEPIXEL( Rast, x+1, y+1 );
  196.                                 }
  197.                             }
  198.                         }
  199.                     }
  200.                 }
  201.                 p2++;
  202.                 p++;
  203.             }
  204.             if(!( ToFrontCount % 5 ))
  205.                 RetVal = ContinueBlanking();
  206.         }
  207.         UnblankMousePointer( Wnd );
  208.     }
  209.     else
  210.         RetVal = FAILED;
  211.  
  212.     if( Scr )
  213.         CloseScreen( Scr );
  214.     if( tab_pt_3d )
  215.         FreeVec( tab_pt_3d );
  216.     if( tab_old )
  217.         FreeVec( tab_old );
  218.  
  219.     return RetVal;
  220. }
  221.