home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / commod / sdark14s.lha / blankers / shuffle.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-10  |  5KB  |  187 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/intuitionbase.h>
  10. #include    <intuition/gadgetclass.h>
  11. #include    <graphics/gfx.h>
  12. #include    <graphics/gfxbase.h>
  13. #include    <graphics/gfxmacros.h>
  14. #include    <graphics/rastport.h>
  15. #include    <clib/exec_protos.h>
  16. #include    <clib/intuition_protos.h>
  17. #include     <hardware/dmabits.h>
  18. #include     <hardware/custom.h>
  19. #include    "/includes/struct.h"
  20. #include    "/includes/tom_gadget.h"
  21.  
  22. struct    RastPort    *rp;
  23. extern    struct    appel_proc    *p_data_proc;
  24.  
  25.  
  26. char    p_ver[]=" $VER: Shuffle v1.1 (28/02/93)";
  27.  
  28. #define    WIDTH    640
  29. #define    HEIGHT    256
  30.  
  31. char    *p_text_info="XSB-based Shuffle Blanker\n\nDivert and shuffle the\nfrontmost screen";
  32.  
  33. char *SpeedNames[] = /* List of Speed Modes */
  34.  {"Slow","Medium","Fast","Very Fast",NULL};
  35.  
  36. struct tom_gadget my_gadg[]={
  37.     {"_Speed",CYCLE,    125,20,100,15,0, 0,3,0,(char *)SpeedNames},
  38.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  39. };
  40. int    speed=1;
  41.  
  42. struct timerequest *tr;
  43. struct    RastPort    *rp,*rps;
  44. int    width,height;
  45.  
  46. extern struct Custom __far custom;
  47. extern    struct    GfxBase    *GfxBase;
  48. extern    struct    IntuitionBase *IntuitionBase;
  49.  
  50. int    xs,ys,xb,yb,x1,y1;
  51.  
  52. #define rnd(x) (rand()%(x))
  53. void    srand(int);
  54. int    rand(void);
  55. long    quitsig;
  56. int    lastdir=-1;
  57. int    rep;
  58.  
  59. /***************************************************************************/
  60.  
  61. void drawframe(int x,int y)
  62. {
  63.     SetAPen(rp,1);
  64.     Move(rp,x*xs,y*ys);
  65.     Draw(rp,x*xs+xs-1,y*ys);
  66.     Draw(rp,x*xs+xs-1,y*ys+ys-1);
  67.     Draw(rp,x*xs,y*ys+ys-1);
  68.     Draw(rp,x*xs,y*ys);
  69. }
  70.  
  71. /***************************************************************************/
  72.  
  73. void pause(void)
  74. {
  75.     WaitTOF();
  76. }
  77.  
  78. /***************************************************************************/
  79.  
  80. void doscroll(int m)
  81. {
  82.     int c;
  83.     switch(m) {
  84.         case 0: for(c=0; (c<xs)&&(tst_end()==FALSE); c+=speed) { ScrollRaster(rp,-speed,0, xb*xs-xs, yb*ys, xb*xs+xs-1, yb*ys+ys-1); pause(); } break;
  85.         case 1: for(c=0; (c<xs)&&(tst_end()==FALSE); c+=speed) { ScrollRaster(rp,speed,0, xb*xs, yb*ys, xb*xs+xs+xs-1, yb*ys+ys-1); pause(); } break;
  86.         case 2: for(c=0; (c<ys)&&(tst_end()==FALSE); c+=speed) { ScrollRaster(rp,0,-speed, xb*xs, yb*ys-ys, xb*xs+xs-1, yb*ys+ys-1); pause(); } break;
  87.         case 3: for(c=0; (c<ys)&&(tst_end()==FALSE); c+=speed) { ScrollRaster(rp,0,speed, xb*xs, yb*ys, xb*xs+xs-1, yb*ys+ys+ys-1); pause(); } break;
  88.     }
  89. }
  90.  
  91. /***************************************************************************/
  92.  
  93. void scroll(void)
  94. {
  95.     int m,rv=rand();
  96.  
  97.     for(;;) {
  98.         rv+=VBeamPos()+rand();
  99.         m=rv%4;
  100.         if(lastdir==0 && m==1) continue;
  101.         if(lastdir==1 && m==0) continue;
  102.         if(lastdir==2 && m==3) continue;
  103.         if(lastdir==3 && m==2) continue;
  104.         if(lastdir==m) {
  105.             if(++rep>4) continue;
  106.         }
  107.         else rep=0;
  108.         if(!m && xb>0) { doscroll(0); xb--; break; }
  109.         if(m==1 && xb<7) { doscroll(1); xb++; break; }
  110.         if(m==2 && yb>0) { doscroll(2); yb--; break; }
  111.         if(m==3 && yb<7) { doscroll(3); yb++; break; }
  112.     }
  113.     lastdir=m;
  114. }
  115.  
  116. /***************************************************************************/
  117.  
  118. void __saveds dark()
  119. {
  120.     struct Screen *scr;
  121.     ULONG     x,y,n;
  122.     ULONG    x2,y2,dir;
  123.     
  124.     FreeSprite (0);
  125.     GfxBase->SpriteReserved|=1;
  126.     srand(VBeamPos());
  127.     rp=p_data_proc->rp;
  128.     rps=p_data_proc->rps;
  129.     scr=p_data_proc->s;
  130.     width=p_data_proc->width;
  131.     height=p_data_proc->height;
  132.  
  133.     xs=width/8; ys=height/8;
  134.     xs=xs/8;
  135.     xs=xs*8;
  136.     ys=ys/8;
  137.     ys=ys*8;
  138.     for(x=0; x<8; x++) {
  139.         for(y=0; y<8; y++) drawframe(x,y);
  140.     }
  141.     xb=rnd(8); yb=rnd(8);
  142.     SetAPen(rp,0);
  143.  
  144.     /* Si on n'arrive pas a faire 8 carreau exactement de large,    */
  145.     /* on efface ce qui debord a gauche et a droite..        */
  146.     if(width!=xs*8)RectFill(rp,xs*8,0,width-1,height-1);
  147.     if(height!=ys*8)RectFill(rp,0,ys*8,width-1,height-1);
  148.  
  149.     /*************************************/
  150.     /* Maintenant disparition du carreau */
  151.     /*************************************/
  152.     x=xb*xs;
  153.     y=yb*ys;
  154.     x2=xs/2;
  155.     y2=ys/2;
  156.     if(rnd(2)==1)    dir=1;
  157.     else        dir=-1;
  158.  
  159.     for(n=0;n<xs/2;n++){
  160.         WaitTOF();
  161.         ScrollRaster(rp,dir,dir,x,y,x+x2-1,y+y2-1);
  162.         ScrollRaster(rp,-dir,dir,x+x2,y,x+xs-1,y+y2-1);
  163.         ScrollRaster(rp,-dir,-dir,x+x2,y+y2,x+xs-1,y+ys-1);
  164.         ScrollRaster(rp,dir,-dir,x,y+y2,x+x2-1,y+ys-1);
  165.     }
  166.     RectFill(rp,x,y,x+xs-1,y+ys-1);
  167.  
  168.     custom.dmacon=(1<<5);
  169.     speed=(1<<my_gadg[0].value);
  170.     while(tst_end()==FALSE) scroll();
  171. }
  172.  
  173. /***************************************************************************/
  174.  
  175. void    proc_init()
  176. {
  177.     p_data_proc->type_screen=SCR_GIVEN;
  178. }
  179. void    proc_save()
  180. {
  181. }
  182.  
  183. void    proc_end()
  184. {
  185. }
  186.  
  187.