home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / NGL 2.0 Demo / NGL2.0.0(E)Demo / Cel & Rotate Sample / Cel & Rotate Sample(PPC).c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-03  |  2.5 KB  |  132 lines

  1. /*============================================================
  2.  
  3.                     Cel & Rotate sample program
  4.                     
  5. ============================================================*/
  6. #include        "N_Library.h"
  7.  
  8. short        Data_Rsrc = 0;
  9. long            total_step = 0;
  10. long            wait;
  11. short        i,r=0;
  12. short        x[128];
  13. short        y[128];
  14. short        rt[128];
  15. short        sp[128];
  16.  
  17. void main(void)
  18. {
  19.     WindowPtr    window;
  20.     Rect            BGrect;
  21.     short        p;
  22.  
  23.     ToolboxInit();
  24.     ColorCheck();
  25.     HideMenuBar();
  26.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  27.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  28.      Open_Resource_File(128,1,&Data_Rsrc);
  29.     N_Sp_Make(640,480);                                                //initialize sprite offscreen
  30.     N_Cel_Make2(640,480);                                                //keep cel plane work area
  31.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  32.     N_Sprite_Set(129,0,48,48,0,1,1,1);                                    //Sp 0(rotation mode)
  33.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //Sp 1
  34.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //Sp 2
  35.     Delay(60,&wait);
  36.     Close_Resource_File(&Data_Rsrc);
  37.  
  38.     for (i=0;i!=128;i++)
  39.     {
  40.         x[i] = GetRandom(0,640-48);
  41.         y[i] = GetRandom(0,640-48);
  42.         sp[i] = GetRandom(1,5)*2;
  43.         rt[i] = 0;
  44.     }
  45.  
  46.     do
  47.     {
  48.         SetPort((GrafPtr)SP_off);
  49.         SetRect(&BGrect,0,0,640,480);
  50.         ScrollRect(&BGrect,-32,0,nil);
  51.  
  52.         for(i=0;i!=15;i++)
  53.         {
  54.             p = GetRandom(0,1);
  55.             if (p==0)
  56.             {
  57.                 N_Sp_Put(0x80000000+1,608,i*32);
  58.             }
  59.             else
  60.             {
  61.                 N_Sp_Put(0x80000000+2,608,i*32);
  62.             }
  63.         }
  64.  
  65.         if (total_step<128)
  66.         {
  67.             for (i=0;i!=48;i++)
  68.             {
  69.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+24,y[i]+24,rt[i]);    
  70.                 x[i] = x[i] + sp[i];
  71.                 if (x[i]>640)                                            
  72.                 {
  73.                     x[i] = -64;
  74.                 }
  75.             }
  76.         }
  77.  
  78.         if (total_step>=128 && total_step<256)                                
  79.         {
  80.             for (i=0;i!=48;i++)
  81.             {
  82.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);            
  83.             }
  84.             r+=8;                                                    
  85.         }
  86.  
  87.         if (total_step>=256 && total_step<384)                                
  88.         {
  89.             for (i=0;i!=48;i++)
  90.             {
  91.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],300,220,r);            
  92.                 x[i] = x[i] + sp[i];
  93.                 if (x[i]>640)                                            
  94.                 {
  95.                     x[i] = -64;
  96.                 }
  97.             }
  98.             r-=8;
  99.         }
  100.  
  101.         if (total_step>=384 && total_step<512)                                
  102.         {
  103.             for (i=0;i!=48;i++)
  104.             {
  105.                 rt[i] = x[i]*4;
  106.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+24,y[i]+24,rt[i]);    
  107.                 x[i] = x[i] + sp[i];
  108.                 if (x[i]>640)
  109.                 {
  110.                     x[i] = -64;
  111.                 }
  112.             }
  113.         }
  114.  
  115.         if (total_step == 511)
  116.         {
  117.             total_step =0;
  118.             r = 0;
  119.         }
  120.         N_Cel_Loop2(0,0);                                    
  121.         total_step++;
  122.     }
  123.     while (!Button());
  124.     ShowMenuBar();
  125.     ShowCursor();
  126.     FlushEvents( everyEvent, 0 ); 
  127.     ColorRevert();
  128. }
  129.  
  130.  
  131.  
  132.