home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 19 / macformat_19.iso / Shareware / Developers / N Game Library1.1.0E(68k) / Cel & Rotate Sample / Cel & Rotate Sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-23  |  3.2 KB  |  170 lines  |  [TEXT/CWIE]

  1. /*============================================================
  2.  
  3.                     Cel & Rotate sample program
  4.                     
  5. ============================================================*/
  6.  
  7. #include            "N_Library.h"
  8.  
  9. void             DoEvent            (EventRecord *eventPtr);
  10. void             DoError            (Str255 errorString);
  11. WindowPtr     CreateWindow         (Str255 name);
  12.  
  13.  
  14. #define        WindowSizeX        640
  15. #define        WindowSizeY        480
  16.  
  17. short        NewWindowX;
  18. short        NewWindowY;
  19.  
  20. short        Data_Rsrc = 0;
  21.  
  22. long            total_step = 0;
  23. long            wait;
  24. short        i,r=0;
  25. short        x[80];
  26. short        y[80];
  27. short        sp[80];
  28.  
  29. void main(void)
  30. {
  31.     WindowPtr    window;
  32.  
  33.  
  34.     ToolboxInit();
  35.     ColorCheck();
  36.     HideMenuBar();
  37.     window = CreateWindow("\pN Game Library <Cel & Rotate Sample>");
  38.     N_Window_Set(window,NewWindowX,NewWindowY,WindowSizeX,WindowSizeY);
  39.     Open_Resource_File(128,1,&Data_Rsrc);
  40.     N_Sp_Make(640,480);                                                //setup for sprite
  41.     N_Cel_Make(200000);                                                //setup for cel
  42.     HideCursor();
  43.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  44.     N_Sprite_Set(200,0,32,32,0,1,1,1);                                    //set Sprite 0(rotation mode)
  45.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //set Sprite 1
  46.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //set sprite 2
  47.     N_Pict_Draw(130,0,0,(GrafPtr)Main_Window,true);    
  48.     Close_Resource_File(&Data_Rsrc);
  49.  
  50.     for (i=0;i!=50;i++)                                                    //make random position
  51.     {
  52.         x[i] = GetRandom(0,640);
  53.         y[i] = GetRandom(0,480+240)-120;
  54.         sp[i] = GetRandom(1,5)*2;
  55.     }
  56.  
  57.     do
  58.     {
  59.         total_step++;
  60.  
  61.         N_Sp_Put(0x80000000+1,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);    //draw background
  62.         N_Sp_Put(0x80000000+2,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);
  63.  
  64.         if (total_step<128)                                                //move
  65.         {
  66.             for (i=0;i!=50;i++)
  67.             {
  68.     
  69.     
  70.                 N_Cel_Put(i,0x80000000,x[i],y[i]);
  71.     
  72.                 x[i] = x[i] + sp[i];
  73.  
  74.                 if (x[i]>640)
  75.                 {
  76.                     x[i] = -32;
  77.                     y[i] = GetRandom(0,480+240)-120;
  78.                 }
  79.             }
  80.         }
  81.  
  82.         if (total_step>=128 && total_step<256)                                //rotation
  83.         {
  84.             for (i=0;i!=50;i++)
  85.             {
  86.     
  87.  
  88.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);
  89.             }
  90.             r-=8;
  91.         }
  92.  
  93.         if (total_step>=256 && total_step<384)                                //rotation & move 1
  94.         {
  95.             for (i=0;i!=50;i++)
  96.             {
  97.     
  98.  
  99.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);
  100.  
  101.                 x[i] = x[i] + sp[i];
  102.  
  103.                 if (x[i]>640)
  104.                 {
  105.                     x[i] = -32;
  106.                     y[i] = GetRandom(0,480+240)-120;
  107.                 }
  108.     
  109.             }
  110.             r+=8;
  111.         }
  112.  
  113.         if (total_step>=384 && total_step<512)                                //rotation & move 2
  114.         {
  115.             for (i=0;i!=50;i++)
  116.             {
  117.     
  118.     
  119.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,r);
  120.                 x[i] = x[i] + sp[i];
  121.                 
  122.                 if (x[i]>640)
  123.                 {
  124.                     x[i] = -32;
  125.                     y[i] = GetRandom(0,480+240)-120;
  126.                 }
  127.             }
  128.  
  129.             r-=16;
  130.         }
  131.  
  132.  
  133.         if (total_step == 511)
  134.         {
  135.             total_step =0;
  136.             r = 0;
  137.         }
  138.         
  139.         N_Cel_Loop(0,0);
  140.     }
  141.         while (!Button());
  142.  
  143.         ShowMenuBar();
  144.         ShowCursor();
  145.         ColorRevert();
  146. }
  147.  
  148.  
  149.  
  150. WindowPtr CreateWindow (Str255 name)
  151. {
  152.     WindowPtr    window;
  153.     short        centerX,centerY;
  154.     short        windowWidth,windowHeight;
  155.  
  156.  
  157.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  158.     centerX  = (qd.screenBits.bounds.right -qd.screenBits.bounds.left)/2;
  159.     centerY  = (qd.screenBits.bounds.bottom -qd.screenBits.bounds.top)/2;
  160.     SetWTitle(window,name);
  161.     MoveWindow(window,NewWindowX=centerX-(WindowSizeX/2),NewWindowY=centerY-(WindowSizeY/2),false);
  162.     SizeWindow(window,WindowSizeX,WindowSizeY,TRUE);
  163.  
  164.     ShowWindow(window);
  165.     SetPort((GrafPtr)window );
  166.     return (WindowPtr)window;
  167. }
  168.     
  169.  
  170.