home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / util / blank / gblanker / source / blankers / fireworks / blank.c next >
C/C++ Source or Header  |  1994-10-09  |  4KB  |  232 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. #include <dos/dos.h>
  12. #include <hardware/custom.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/alib_protos.h>
  18.  
  19. #include "/Garshnelib/Garshnelib_protos.h"
  20. #include "/Garshnelib/Garshnelib_pragmas.h"
  21.  
  22. #include "Fireworks.h"
  23. #include "//defs.h"
  24. #include "/main.h"
  25.  
  26. #define SCALE 100
  27. #define ACCEL 4
  28.  
  29. #define    MAX_FIRE       200
  30. #define    MAX_EXPLOSIONS 25
  31.  
  32. #define    NONE      0
  33. #define    FIRE      1
  34. #define    EXPLODING 2
  35.  
  36. extern __far struct Custom custom;
  37.  
  38. struct Fire
  39. {
  40.     BYTE type;
  41.     BYTE time;
  42.     ULONG x;
  43.     ULONG y;
  44.     LONG vx;
  45.     LONG vy;
  46.     LONG color;
  47. };
  48.  
  49. struct ModulePrefs
  50. {
  51.     LONG Mode;
  52.     LONG Depth;
  53.     LONG Number;
  54.     LONG Power;
  55.     LONG Radius;
  56. };
  57.  
  58. extern struct ModulePrefs nP;
  59. struct Fire *FireTable, *LastFire;
  60. LONG MaxFires, NumFires, Power, Radius, Wid, Hei;
  61.  
  62. LONG CheckFire( struct Fire *f )
  63. {
  64.     if( f->x/SCALE >= Wid )
  65.         return 1;
  66.     
  67.     if( f->y/SCALE >= Hei )
  68.         return 1;
  69.     
  70.     return 0 ;
  71. }
  72.  
  73. VOID IterateFire( struct RastPort *Rast )
  74. {
  75.     LONG l;
  76.     struct Fire *f, *tf;
  77.     
  78.     if(( NumFires < MaxFires )&&( RangeRand( 100 ) > 90 ))
  79.     {
  80.         for( tf = FireTable; tf->type; tf++ );
  81.         if( tf != LastFire )
  82.         {
  83.             tf->type = FIRE;
  84.             tf->x = ( Wid / 4 + RangeRand( Wid / 2 )) * SCALE;
  85.             tf->y = ( Hei - 5 ) * SCALE;
  86.             tf->color = RangeRand(( 1L << Rast->BitMap->Depth ) - 1 ) + 1;
  87.             tf->vx = RangeRand( SCALE * Hei / 100 ) - SCALE;
  88.             tf->vy = -1 * ( Power * SCALE * Hei / 400 );
  89.             tf->time = RangeRand( 100 ) + 100;
  90.             NumFires++;
  91.         }
  92.     }
  93.     
  94.     for( f = FireTable; f != LastFire; f++ )
  95.     {
  96.         switch( f->type )
  97.         {
  98.         case NONE:
  99.             break;
  100.         case FIRE:
  101.             if( !f->time )
  102.             {
  103.                 for( l = 0, tf = FireTable; ( l < MAX_EXPLOSIONS )&&
  104.                     ( tf != LastFire ); tf++ )
  105.                 {
  106.                     if( !tf->type )
  107.                     {
  108.                         CopyMem( f, tf, sizeof( struct Fire ));
  109.                         tf->type = EXPLODING;
  110.                         tf->vx = ( RangeRand( 100 ) - 50 ) *
  111.                             ( Radius * Wid / 1000 );
  112.                         tf->vy = ( RangeRand( 100 ) - 50 ) *
  113.                             ( Radius * Hei / 1000 );
  114.                         tf->time = RangeRand( 10 ) + 50;
  115.                         l++;
  116.                     }
  117.                 }
  118.                 NumFires--;
  119.                 f->type = NONE;
  120.             }
  121.             else
  122.             {
  123.                 SetAPen( Rast, 0 );
  124.                 WritePixel( Rast, f->x/SCALE, f->y/SCALE );
  125.                 f->x += f->vx;
  126.                 f->y += f->vy;
  127.                 if( CheckFire( f ))
  128.                 {
  129.                     f->type = NONE;
  130.                     NumFires--;
  131.                 }
  132.                 else
  133.                 {
  134.                     SetAPen( Rast, f->color );
  135.                     WritePixel( Rast, f->x/SCALE, f->y/SCALE );
  136.                     f->vy += ACCEL;
  137.                     f->time--;
  138.                 }
  139.             }
  140.             break;
  141.         case EXPLODING:
  142.             SetAPen( Rast, 0 );
  143.             WritePixel( Rast, f->x/SCALE, f->y/SCALE );
  144.             if( !f->time )
  145.                 f->type = NONE;
  146.             else
  147.             {
  148.                 f->x += f->vx;
  149.                 f->y += f->vy;
  150.                 if( CheckFire( f ))
  151.                     f->type = NONE;
  152.                 else
  153.                 {
  154.                     SetAPen( Rast, f->color );
  155.                     WritePixel( Rast, f->x/SCALE, f->y/SCALE );
  156.                     f->vy += ACCEL;
  157.                     f->time--;
  158.                 }
  159.             }
  160.             break;
  161.         }
  162.     }
  163. }
  164.  
  165. LONG Blank( VOID *Prefs )
  166. {
  167.     struct ModulePrefs *mP;
  168.     struct Screen *Scr;
  169.     struct Window *Wnd;
  170.     LONG ToFrontCount = 0, RetVal = OK;
  171.     
  172.     if( FireworksWnd )
  173.         mP = &nP;
  174.     else
  175.         mP = ( struct ModulePrefs * )Prefs;
  176.     
  177.     MaxFires = mP->Number;
  178.     Power = mP->Power;
  179.     Radius = mP->Radius;
  180.     
  181.     FireTable = AllocVec( sizeof( struct Fire ) * ( MAX_FIRE + 1 ),
  182.                          MEMF_CLEAR );
  183.     
  184.     if( FireTable )
  185.     {
  186.         Scr = OpenScreenTags( 0L, SA_Depth, mP->Depth, SA_Overscan,
  187.                              OSCAN_STANDARD, SA_DisplayID, mP->Mode, SA_Quiet,
  188.                              TRUE, SA_Behind, TRUE, TAG_DONE );
  189.         if( Scr )
  190.         {
  191.             LastFire = &( FireTable[MAX_FIRE] );
  192.             
  193.             Wid = Scr->Width;
  194.             Hei = Scr->Height;
  195.             
  196.             if( mP->Depth < 3 )
  197.                 setCopperList( Hei, 1, &( Scr->ViewPort ), &custom );
  198.             
  199.             SetRGB4(&( Scr->ViewPort ), 0, 0, 0, 0 );
  200.             SetRGB4(&( Scr->ViewPort ), 1, 0x0F, 0x0F, 0x0F );
  201.             SetRast(&( Scr->RastPort ), 0 );
  202.             
  203.             NumFires = 0;
  204.             Wnd = BlankMousePointer( Scr );
  205.             ScreenToFront( Scr );
  206.             
  207.             while( RetVal == OK )
  208.             {
  209.                 WaitTOF();
  210.                 IterateFire(&( Scr->RastPort ));
  211.                 if(!( ToFrontCount++ % 60 ))
  212.                     ScreenToFront( Scr );
  213.                 if(!( ToFrontCount % 5 ))
  214.                     RetVal = ContinueBlanking();
  215.             }
  216.             
  217.             UnblankMousePointer( Wnd );
  218.             if( mP->Depth < 3 )
  219.                 clearCopperList( &Scr->ViewPort );
  220.             CloseScreen( Scr );
  221.         }
  222.         else
  223.             RetVal = FAILED;
  224.  
  225.         FreeVec( FireTable );
  226.     }
  227.     else
  228.         RetVal = FAILED;
  229.     
  230.     return RetVal;
  231. }
  232.