home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / firework.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-10  |  5KB  |  273 lines

  1.  /* Fichier star.dark.c                */
  2. /* Module appele par le programme principal    */
  3. /* pour effectuer un effet defini..appele par    */
  4. /* loadseg                    */
  5.  
  6. #include    <exec/types.h>
  7. #include    <dos/dos.h>
  8. #include    <intuition/intuition.h>
  9. #include    <intuition/gadgetclass.h>
  10. #include    <graphics/gfx.h>
  11. #include    <graphics/gfxmacros.h>
  12. #include    <graphics/gfxbase.h>
  13. #include    <graphics/rastport.h>
  14. #include    <clib/exec_protos.h>
  15. #include    <clib/intuition_protos.h>
  16. #include    "/includes/struct.h"
  17. #include    "/includes/tom_gadget.h"
  18.  
  19. struct    RastPort    *rp;
  20. struct    Screen    *s;
  21. extern    struct    appel_proc    *p_data_proc;
  22. extern    struct    GfxBase    *GfxBase;
  23.  
  24. #define    WIDTH    320
  25. #define    HEIGHT    256
  26. #define    DEPTH    3
  27.  
  28. char    p_ver[]="$VER: FireWork v1.0 (12/02/93)";
  29.  
  30. char    *p_text_info="Effect 'FireWork'\nBy T.Landspurg";
  31.  
  32. #define reg register
  33. extern    void __asm MultiPlot(reg __a0 struct Screen *,reg __d0 WORD, reg __d1 WORD,reg __d2 WORD);
  34.  
  35. struct NewScreen    Screen = {
  36.     0, 0, WIDTH,  HEIGHT, DEPTH, 0,0, 0, CUSTOMSCREEN, NULL, NULL ,NULL, NULL};
  37.  
  38. UWORD  ScreenColors[] = {
  39.     0x000,
  40.     0xF00,
  41.     0xFFF,
  42.     0xF0F,
  43.     0x0FF,
  44.     0xF98,
  45.     0x8AF,
  46.     0xFB0,
  47.     0xFC0,
  48.     0xFD0,
  49.     0xFE0,
  50.     0xFF0,
  51.     0xBF0,
  52.     0x8F0,
  53.     0x7D0,
  54.     0x5B0,
  55.     0x000,
  56.     0x490,
  57.     0x360,
  58.     0x340,
  59.     0x444,
  60.     0x555,
  61.     0x666,
  62.     0x777,
  63.     0x888,
  64.     0x999,
  65.     0xAAA,
  66.     0xBBB,
  67.     0xCCC,
  68.     0xDDD,
  69.     0xEEE,
  70.     0xFFF,
  71.     0x000 };
  72.  
  73. #define    COEF    100
  74. #define    ACC    3
  75. #define    MAX_FIRE 200
  76. #define    MAX_ECLAT 25
  77. #define    MAX_NB    51
  78.  
  79. int    max_nb;
  80. int    nb_fire;
  81.  
  82. struct tom_gadget my_gadg[]={
  83.     {"_Number"    ,SLIDER,    100,20,139,9,20, 10,MAX_NB-1,0,0},
  84.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  85. };
  86.  
  87.  
  88. #define    NONE    0
  89. #define    FIRE    1
  90. #define    ECLAT    2
  91. #define    NB_OLD    10
  92.  
  93. typedef    struct    fire{
  94.     int    type;
  95.     int    time;
  96.     int    x,y;
  97.     int    tx[NB_OLD];
  98.     int    ty[NB_OLD];
  99.     int    sx,sy;
  100.     int    color;
  101. };
  102.  
  103. struct    fire    tab_fire[MAX_FIRE+1];
  104. unsigned    int    seed;
  105.  
  106. /********************************************************** my_rand() ***/
  107.  
  108. unsigned        int     my_rand()
  109. {
  110.         
  111.         seed=25173*seed+138490;
  112.         return(seed);
  113. }
  114.  
  115. /********************************************************** new_fire() ***/
  116.  
  117. void    new_fire()
  118. {
  119.     int    i;
  120.     register struct    fire    *f;
  121.     f=tab_fire;
  122.     i=0;
  123.     while((i<MAX_FIRE)&&(f->type!=NONE)){
  124.         i++;
  125.         f++;
  126.     }
  127.     if(i!=MAX_FIRE){
  128.         f->type=FIRE;
  129.         f->x=my_rand()%(WIDTH*COEF);
  130.         f->y=0;
  131.         f->color=my_rand()%((1<<DEPTH)-1)+1;
  132.         f->sx=my_rand()%(100)-50;
  133.         f->sy=my_rand()%(200)+200;
  134.         f->time=my_rand()%100+100;
  135.         nb_fire++;
  136.  
  137.     }
  138. }
  139.  
  140. /********************************************************** eclat() ***/
  141.  
  142. void    eclat(struct    fire    *f)
  143. {
  144.     struct    fire    *tf;
  145.     int    n;
  146.  
  147.     tf=tab_fire;
  148.     for(n=0;(n<MAX_ECLAT)&&(tf!=&tab_fire[MAX_FIRE]);tf++){
  149.         if(tf->type==NONE){    
  150.             tf->type=ECLAT;
  151.             tf->x=f->x;
  152.             tf->y=f->y;
  153.             tf->color=f->color;
  154.             tf->sx=my_rand()%50-25;
  155.             tf->sy=my_rand()%100-50;
  156.             tf->time=my_rand()%10+50;
  157.             n++;
  158.         }
  159.     }
  160.     nb_fire--;
  161. }
  162.  
  163. /********************************************************** aff_trainee() ***/
  164.  
  165. void    aff_trainee(struct    fire    *f,int nb)
  166. {
  167.     int    i;
  168.     SetAPen(rp,0);
  169.     MultiPlot(s,(WORD)(f->tx[nb-1]),(WORD)(f->ty[nb-1]),0);
  170.     for(i=nb-1;i>=1;i--){
  171.         f->tx[i]=f->tx[i-1];
  172.         f->ty[i]=f->ty[i-1];
  173.     }
  174.     if(f->time>nb){
  175.         f->tx[0]=f->x/COEF;
  176.         f->ty[0]=HEIGHT-f->y/COEF;
  177.         MultiPlot(s,(WORD)(f->tx[0]),(WORD)(f->ty[0]),f->color);
  178.     }
  179. }
  180.  
  181. /********************************************************** main_fire() ***/
  182.  
  183. void    main_fire()
  184. {
  185.     int    i,n;
  186.  
  187.     register struct    fire    *f;
  188.  
  189.     if(nb_fire<max_nb){
  190.         if((my_rand()%100>90)){
  191.             new_fire();
  192.         }
  193.     }
  194.     n=0;
  195.     f=tab_fire;
  196.     for(i=0;i<MAX_FIRE;i++){
  197.         switch(f->type){
  198.            case NONE:
  199.             break;
  200.            case FIRE:
  201.             n++;
  202.             if(f->time==0){
  203.                 eclat(f);
  204.                 f->type=NONE;
  205.             }else{
  206.                 f->x+=f->sx;
  207.                 f->y+=f->sy;
  208.                 f->sy-=ACC;
  209.                 f->time--;
  210.                 aff_trainee(f,2);
  211.             }
  212.             break;
  213.            case ECLAT:
  214.             n++;
  215.             if(f->time==0){
  216.                 f->type=NONE;
  217.             }else{
  218.                 f->x+=f->sx;
  219.                 f->y+=f->sy;
  220.                 f->sy-=1;
  221.                 f->time--;
  222.                 aff_trainee(f,NB_OLD-1);
  223.             }
  224.             break;
  225.         }
  226.         f++;
  227.     }
  228. }
  229.  
  230.  
  231. /********************************************************** dark ***/
  232.  
  233. void    dark()
  234. {
  235.     int    d,i;
  236.  
  237.         if ( NOT( s = OpenScreen(&Screen)))
  238.         return;
  239.  
  240.     FreeSprite (0);
  241.     GfxBase->SpriteReserved|=1;
  242.     rp = &(s->RastPort);
  243.     LoadRGB4(&s->ViewPort,ScreenColors,(1<<DEPTH));
  244.  
  245.     SetRast(rp,0);
  246.     max_nb=my_gadg[0].value;
  247.     nb_fire=0;
  248.  
  249.     for(i=0;i<MAX_FIRE;i++){
  250.         tab_fire[i].type=NONE;
  251.     }
  252.     while(tst_end()==FALSE){
  253.         WaitTOF();
  254.         main_fire();
  255.     }
  256.     CloseScreen(s);
  257. }
  258.  
  259. /********************************************************** ***/
  260.  
  261. void    proc_init()
  262. {
  263.         seed=VBeamPos();
  264. }
  265. void    proc_save()
  266. {
  267. }
  268.  
  269. void    proc_end()
  270. {
  271. }
  272.  
  273.