home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 Extra Demos / Brian's Demos / Extended Sprite Test / Extended SpriteTest.c < prev    next >
Encoding:
Text File  |  1999-01-14  |  31.3 KB  |  1,147 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. // SpriteTest.c
  3. //
  4. // By: Tony Myles
  5. //
  6. // Extensive modifications by Karl Bunker
  7. //
  8. // Modified by Brian Roddy to show extensions: 
  9. //         - PPC All Bit Blitters
  10. //        - Translucency
  11. //        - Scaling
  12. //         - Lighting
  13. //
  14. ///--------------------------------------------------------------------------------------
  15.  
  16. #include <Timer.h>
  17.  
  18. #include <SWIncludes.h>            // Automatically include all SpriteWorld.h files
  19.  
  20. #include <SWGameUtils.h>
  21. #include <SWDitherDown.h>
  22. #include <SWDialogUtils.h>
  23. #include "Extended SpriteTest.h"
  24. #include "SWLightingSquares.h"
  25. #include "BlitPixieScaled.h"
  26. #include "BlitPixieRotated.h"
  27.  
  28. #if __MWERKS__
  29. #include <profiler.h>
  30. #endif
  31.  
  32. #define kBlitterTest false
  33. #define kNumberOfTranslucencyLevels 1
  34.  
  35. #define kWorldRectInset 0        // modify to test SpriteWorld rect less than window size
  36.  
  37. Boolean            gGlobesVisible;
  38. Boolean            gTitleVisible;
  39. Boolean            gCollisionDetection;
  40. ProcType        gWhichSpriteProc;
  41. ProcType        gWhichOffscreenProc;
  42. ProcType        gWhichScreenProc;
  43. short             gMoveDelta;
  44. SpritePtr        gMasterGlobeSprite = NULL;
  45.  
  46. /******************** SetupSWStuff ********************/
  47. OSErr SetupSWStuff(
  48.     SpriteTestPtr* spriteTestP,
  49.     CWindowPtr srcWindowP)
  50. {
  51.     OSErr                 err = noErr;
  52.     SpriteTestPtr         tempSpriteTestP;
  53.     SpriteWorldPtr         spriteWorldP = NULL;
  54.     SpriteLayerPtr         globeSpriteLayerP;
  55.     SpritePtr             globeSpriteArray[kNumberOfGlobeSprites];
  56.     SpritePtr             titleSpriteP;
  57.     SpritePtr             twoSpriteP;
  58.     PixPatHandle         pixPatH = NULL;
  59.     short                 spriteNum;
  60.     short                 oldResRefNum, curResRefNum;
  61.     Rect                 windowRect, worldRect;
  62.  
  63.     
  64.     *spriteTestP = NULL;
  65.  
  66.     SetPort((GrafPtr)srcWindowP);
  67.     
  68.     
  69.     windowRect = srcWindowP->portRect; 
  70.     worldRect = windowRect;
  71.     InsetRect( &worldRect, kWorldRectInset, kWorldRectInset );
  72.     
  73.     ShowWindow( (WindowPtr)srcWindowP );
  74.     TextFont( systemFont );
  75.     TextSize( 12 );
  76.     MoveTo( 40, 80 );
  77.     DrawString( "\pLoading Sprites... please wait" );
  78.     
  79.     InitializeRotationTables();
  80.     
  81.     tempSpriteTestP = (SpriteTestPtr)NewPtrClear((Size)sizeof(SpriteTestRec));
  82.     
  83.     {
  84.             // create the sprite world
  85.         (void)SWCreateSpriteWorldFromWindow(&spriteWorldP, srcWindowP, &worldRect, NULL, 0);
  86.     }
  87.  
  88.  
  89.     if (SWStickyError() == noErr)
  90.     {
  91.         tempSpriteTestP->spriteWorldP = spriteWorldP;
  92.         
  93.             // create the sprite layer
  94.         (void)SWCreateSpriteLayer(&globeSpriteLayerP);
  95.         tempSpriteTestP->globeSpriteLayerP = globeSpriteLayerP;
  96.     }
  97.  
  98.     if (SWStickyError() == noErr)
  99.     {
  100.         oldResRefNum = CurResFile();
  101.         curResRefNum = OpenResFile("\pSpriteTest Frames");
  102.         SWSetStickyIfError( ResError() );
  103.     }
  104.  
  105.     if (SWStickyError() == noErr)
  106.     {
  107.         UseResFile(curResRefNum);
  108.  
  109.         (void)SWCreateSpriteFromSinglePict(
  110.             spriteWorldP,
  111.             &gMasterGlobeSprite,
  112.             NULL,
  113.             kBaseResID,
  114.             kBaseResID+1,
  115.             kGlobeHeight,
  116.             kGlobeBorderWidth,
  117.             kFatMask);
  118.  
  119.         (void)SWCreateSpriteFromSinglePict(
  120.             spriteWorldP,
  121.             &twoSpriteP,
  122.             NULL,
  123.             kBaseResID+2,
  124.             kBaseResID+2,
  125.             kTwoHeight,
  126.             kTwoBorderWidth,
  127.             kFatMask);
  128.         
  129.         if (SWStickyError() == noErr)
  130.         {
  131.             if ( spriteWorldP->pixelDepth < 8 )
  132.             {
  133.                 DitherDownPict( kBaseResID+2, twoSpriteP->sharedPictGWorld );
  134.                 LowerMaskDepth( kBaseResID+2, twoSpriteP->sharedMaskGWorld );
  135.             }
  136.             SWSetSpriteFrameTime( twoSpriteP, kGlobeSpriteFrameTime*4 );
  137.             SWSetSpriteFrameRange( twoSpriteP, 0, kNumberOfTwoFrames - 1 );
  138.             SWSetSpriteFrameAdvanceMode( twoSpriteP, kSWPatrollingMode );
  139.         }
  140.         UseResFile(oldResRefNum);
  141.         CloseResFile(curResRefNum);
  142.     }
  143.  
  144.     if (SWStickyError() == noErr)
  145.     {
  146.         if ( spriteWorldP->pixelDepth == 8 )
  147.             (void)SWCompileSprite( gMasterGlobeSprite );
  148.             // master globe sprite isn't added to any layer, so we have to lock it separately
  149.         SWLockSprite( gMasterGlobeSprite);
  150.     }
  151.  
  152.     if (SWStickyError() == noErr)
  153.     {
  154.             
  155.         for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
  156.         {
  157.             (void)SWCloneSprite(gMasterGlobeSprite, globeSpriteArray + spriteNum, NULL);
  158.             tempSpriteTestP->globeSpriteArray[spriteNum] = globeSpriteArray[spriteNum];
  159.         }
  160.     
  161.     }
  162.     
  163.     if (SWStickyError() == noErr)
  164.     {
  165.         (void)SWCreateSpriteFromPictResource( 
  166.             spriteWorldP,
  167.             &titleSpriteP, 
  168.             NULL, 
  169.             kBaseResID, 
  170.             kBaseResID, 
  171.             1, 
  172.             kFatMask);
  173.         
  174.         if ( spriteWorldP->pixelDepth < 8 )
  175.         {
  176.             DitherDownPict( kBaseResID, titleSpriteP->frameArray[0]->framePort );
  177.             LowerMaskDepth( kBaseResID, titleSpriteP->frameArray[0]->maskPort );
  178.         }
  179.         tempSpriteTestP->titleSpriteP = titleSpriteP;
  180.         tempSpriteTestP->twoSpriteP = twoSpriteP;
  181.         
  182.         *spriteTestP = tempSpriteTestP;
  183.         
  184.         for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
  185.         {
  186.             if (spriteNum == (kNumberOfGlobeSprites / 2))
  187.             {
  188.                 SWAddSprite(globeSpriteLayerP, titleSpriteP);
  189.                 SWAddSprite(globeSpriteLayerP, twoSpriteP);
  190.             }
  191.             SWAddSprite(globeSpriteLayerP, globeSpriteArray[spriteNum]);
  192.         }
  193.         
  194.  
  195.         SWAddSpriteLayer(spriteWorldP, globeSpriteLayerP);
  196.  
  197.  
  198.         SWLockSpriteWorld(spriteWorldP);
  199.     
  200.         SWSetPortToBackground(spriteWorldP);
  201.         EraseRect( &spriteWorldP->backRect );
  202.         
  203.         if ( spriteWorldP->pixelDepth >= 8 )
  204.         {
  205.             pixPatH = GetPixPat(kBackDropPixPatID);
  206.             if ( pixPatH != NULL )
  207.             {
  208.                 FillCRect(&spriteWorldP->backRect, pixPatH);
  209.                 DisposePixPat(pixPatH);
  210.             }
  211.         }
  212.         else
  213.             FillRect(&spriteWorldP->backRect, &qd.ltGray);
  214.         
  215.         SWSetPortToWindow(spriteWorldP);
  216.         
  217.         SetupSpriteWorldElements(tempSpriteTestP);
  218.     }
  219.     if ( SWStickyError() != noErr)
  220.     {
  221.         DisposeSWStuff(tempSpriteTestP);
  222.     }
  223.  
  224.     return SWStickyError();
  225. }
  226.         
  227.  
  228. /******************** DisposeSWStuff ********************/
  229. void DisposeSWStuff(
  230.     SpriteTestPtr spriteTestP)
  231. {    
  232.     if (spriteTestP != NULL)
  233.     {
  234.         if (spriteTestP->spriteWorldP != NULL)
  235.         {
  236.             SWExitLightingSquares();
  237.             SWDisposeSpriteWorld(&spriteTestP->spriteWorldP);
  238.         }
  239.             // gMasterGlobeSprite is not added to any layer, 
  240.             // so SWDisposeSpriteWorld won't dispose of it
  241.         if ( gMasterGlobeSprite != NULL )
  242.         {
  243.             SWDisposeSprite( &gMasterGlobeSprite );
  244.         }
  245.         DisposePtr((Ptr)spriteTestP);
  246.         
  247.         SWDispose8BitTranslucencyTable();
  248.         SWDispose16BitTranslucencyTable();
  249.         
  250.     }
  251. }
  252.  
  253.  
  254. /******************** SetupSpriteWorldElements ********************/
  255. void SetupSpriteWorldElements(
  256.     SpriteTestPtr spriteTestP)
  257. {
  258.     register         long spriteNum;
  259.     Rect             moveBoundsRect;
  260.     Rect            titleDestRect;
  261.     
  262.  
  263.     moveBoundsRect = spriteTestP->spriteWorldP->backRect;
  264.     
  265.         // set up the globe sprites
  266.     gMoveDelta = 0;
  267.     for (spriteNum = 0; spriteNum < kNumberOfGlobeSprites; spriteNum++)
  268.     {
  269.         SetupGlobeSprite(spriteTestP->globeSpriteArray[spriteNum], &moveBoundsRect,
  270.                 GetRandom(moveBoundsRect.left, moveBoundsRect.right),
  271.                 GetRandom(moveBoundsRect.top, moveBoundsRect.bottom));
  272.     }
  273.  
  274.         // set up the title sprites
  275.     titleDestRect = spriteTestP->titleSpriteP->destFrameRect;
  276.  
  277.     CenterRect( &titleDestRect, &moveBoundsRect );
  278.     OffsetRect( &titleDestRect, -(kTwoHeight + 2 ), 0 );
  279.     SWSetSpriteLocation(spriteTestP->titleSpriteP, titleDestRect.left, titleDestRect.top );
  280.     
  281.     SWSetSpriteLocation(spriteTestP->twoSpriteP, titleDestRect.right, titleDestRect.top-7 );
  282.     
  283.     SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 30 );
  284. //    SWSyncSpriteWorldToVBL( spriteTestP->spriteWorldP, true );]
  285.     
  286.     gGlobesVisible = true;
  287.     gTitleVisible = true;
  288.     gCollisionDetection = true;
  289.     gWhichSpriteProc = kCopyBitsProc;
  290.     gWhichOffscreenProc = kCopyBitsProc;
  291.     gWhichScreenProc = kCopyBitsProc;
  292. }
  293.  
  294.  
  295. /******************** SetupGlobeSprite ********************/
  296.  
  297. void SetupGlobeSprite(
  298.     SpritePtr globeSpriteP,
  299.     Rect *moveBoundsRect,
  300.     short horizLocation,
  301.     short vertLocation)
  302. {
  303.     Rect tempBoundsRect;
  304.     short horizMoveDelta;
  305.     short vertMoveDelta;
  306.  
  307.     gMoveDelta++;
  308.     if ( gMoveDelta > 17 )
  309.         gMoveDelta = 1;
  310.  
  311.     tempBoundsRect = *moveBoundsRect;
  312.  
  313.     horizMoveDelta = GetRandom(1, 6);    //gMoveDelta;
  314.     vertMoveDelta =    GetRandom(1, 6);    //gMoveDelta;
  315.  
  316.     if (GetRandom(0, 1) == 0)
  317.     {
  318.         horizMoveDelta = -horizMoveDelta;
  319.     }
  320.  
  321.     if (GetRandom(0, 1) == 0)
  322.     {
  323.         vertMoveDelta = -vertMoveDelta;
  324.     }
  325.  
  326.         // set the sprite’s movement characteristics
  327.     SWSetSpriteMoveBounds(globeSpriteP, &tempBoundsRect);
  328.     SWSetSpriteMoveDelta(globeSpriteP, horizMoveDelta, vertMoveDelta);
  329.     SWSetSpriteMoveProc(globeSpriteP, GlobeSpriteMoveProc);
  330.     SWSetSpriteMoveTime(globeSpriteP, kGlobeSpriteMoveTime);
  331.  
  332.     SWSetSpriteFrameTime(globeSpriteP, kGlobeSpriteFrameTime);
  333.     SWSetSpriteFrameRange(globeSpriteP, 0, kNumberOfGlobeFrames - 1);
  334.     SWSetSpriteFrameAdvance(globeSpriteP, GetRandom(0, 1) ? -1 : 1);
  335.  
  336.         // three to try:
  337.         // PixelBounceCollideProc, -- 8 bits only!
  338.         // RegionBounceCollideProc,
  339.         // RadiusBounceCollideProc
  340.     SWSetSpriteCollideProc(globeSpriteP, RegionBounceCollideProc);
  341.  
  342.         // set the sprite’s initial location
  343.     SWSetSpriteLocation(globeSpriteP, horizLocation, vertLocation);
  344. }
  345.  
  346.  
  347. /******************** SpriteTestIdle ********************/
  348. void SpriteTestIdle(
  349.     SpriteTestPtr spriteTestP )
  350. {
  351.     GDHandle        windowGDH;
  352.     WindowPtr        theWindow = FrontWindow();
  353.     
  354.         // Make sure the depth hasn't changed
  355.     windowGDH = GetMaxDevice( &theWindow->portRect );
  356.     if ( GetGDeviceDepth(windowGDH) == spriteTestP->spriteWorldP->pixelDepth )
  357.     {
  358.         if (gCollisionDetection)
  359.         {
  360.             SWCollideSpriteLayer(spriteTestP->spriteWorldP, 
  361.                 spriteTestP->globeSpriteLayerP, spriteTestP->globeSpriteLayerP);
  362.         }
  363.         SWProcessSpriteWorld( spriteTestP->spriteWorldP );
  364.         SWAnimateSpriteWorld( spriteTestP->spriteWorldP );
  365.     }
  366. }
  367.  
  368.  
  369. /******************** UpdateSpriteTest ********************/
  370. void UpdateSpriteTest(
  371.     SpriteTestPtr spriteTestP,
  372.     WindowPtr updateWindowP)
  373. {
  374.     SetPort( updateWindowP );
  375.     if ( updateWindowP->portRect.right - updateWindowP->portRect.left > 
  376.         spriteTestP->spriteWorldP->backRect.right - 
  377.         spriteTestP->spriteWorldP->backRect.left )
  378.     {
  379.         ForeColor( blueColor );
  380.         PaintRect( &updateWindowP->portRect );
  381.     }
  382.     ForeColor( blackColor );
  383.     SWUpdateSpriteWorld(spriteTestP->spriteWorldP, true);
  384. }
  385.  
  386.  
  387. /******************** HandleCreateSpriteCommand ********************/
  388. void HandleCreateSpriteCommand(
  389.     SpriteTestPtr spriteTestP)
  390. {
  391.     OSErr err;
  392.     SpritePtr globeSpriteP;
  393.     Rect moveBoundsRect;
  394.     Point mouseLocation;
  395.  
  396.  
  397.     err = SWCloneSprite(gMasterGlobeSprite, &globeSpriteP, NULL);
  398.  
  399.     if (err == noErr)
  400.     {
  401.         moveBoundsRect = spriteTestP->spriteWorldP->backRect;
  402.         GetMouse(&mouseLocation);
  403.         mouseLocation.h -= spriteTestP->spriteWorldP->windRect.left;
  404.         mouseLocation.v -= spriteTestP->spriteWorldP->windRect.top;
  405.         
  406.         SetupGlobeSprite(globeSpriteP, &moveBoundsRect, mouseLocation.h, mouseLocation.v);
  407.  
  408.             // Add sprite in front of or behind the title sprite
  409.         if ( GetRandom(0,1) )
  410.             SWAddSprite(spriteTestP->globeSpriteLayerP, globeSpriteP);
  411.         else
  412.             SWInsertSpriteBeforeSprite(globeSpriteP, spriteTestP->titleSpriteP);
  413.     }
  414. }
  415.  
  416.  
  417. /******************** HandleSpriteTestTitleCommand ********************/
  418. void HandleSpriteTestTitleCommand(
  419.     SpriteTestPtr spriteTestP)
  420. {
  421.     gTitleVisible = !gTitleVisible;
  422.  
  423.     SWSetSpriteVisible(spriteTestP->titleSpriteP, gTitleVisible);
  424.     SWSetSpriteVisible(spriteTestP->twoSpriteP, gTitleVisible);
  425. }
  426.  
  427.  
  428. /******************** HandleBouncingBallsCommand ********************/
  429. void HandleBouncingBallsCommand(
  430.     SpriteTestPtr spriteTestP)
  431. {
  432.     SpritePtr globeSpriteP;
  433.     
  434.     
  435.     gGlobesVisible = !gGlobesVisible;
  436.  
  437.     globeSpriteP = NULL;
  438.     while ((globeSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, globeSpriteP)) != NULL)
  439.     {
  440.         if (globeSpriteP != spriteTestP->titleSpriteP && globeSpriteP != spriteTestP->twoSpriteP)
  441.         {
  442.             SWSetSpriteVisible(globeSpriteP, gGlobesVisible);
  443.         }
  444.     }
  445. }
  446.  
  447.  
  448. /******************** RemoveClickedSprite ********************/
  449. void RemoveClickedSprite(
  450.     SpriteTestPtr spriteTestP)
  451. {
  452.     Point         mouseLocation;
  453.     SpritePtr    spriteToRemove;
  454.     
  455.     
  456.     if ( spriteTestP != NULL )
  457.     {
  458.         GetMouse(&mouseLocation);
  459.         
  460.         mouseLocation.h -= spriteTestP->spriteWorldP->windRect.left;
  461.         mouseLocation.v -= spriteTestP->spriteWorldP->windRect.top;
  462.             // if a sprite has been clicked on, and it isn't the title sprite,
  463.             // then remove it and dispose of it
  464.         spriteToRemove = SWFindSpriteByPoint(spriteTestP->globeSpriteLayerP, NULL, mouseLocation);
  465.         if ( spriteToRemove != NULL &&
  466.             spriteToRemove != spriteTestP->titleSpriteP &&
  467.             spriteToRemove != spriteTestP->twoSpriteP)
  468.         {
  469.             SWRemoveSpriteFromAnimation( spriteTestP->spriteWorldP, spriteToRemove, true );
  470.         }
  471.     }
  472. }
  473.  
  474.  
  475. /******************** SetUpTestDialog ********************/
  476. void SetUpTestDialog(
  477.     SpriteTestPtr spriteTestP)
  478. {
  479.     GrafPtr            savePort;
  480.     DialogPtr        theDialog;
  481.     short            itemHit;
  482.     ProcType        originalSpriteProc, 
  483.                     originalOffscreenProc,
  484.                     originalScreenProc;
  485.     Boolean            runNow;
  486.     Boolean            done = false;
  487.     OSErr            err = noErr;
  488.     
  489.  
  490.     GetPort( &savePort );
  491.         
  492.     theDialog = GetNewDialog(kSetUpTestResID, nil, (WindowPtr)-1L);
  493.         
  494.     SetDialogDefaultItem( theDialog, ok );
  495.     SetDialogCancelItem( theDialog, cancel );
  496.     
  497.     originalSpriteProc = gWhichSpriteProc;
  498.     originalOffscreenProc = gWhichOffscreenProc;
  499.     originalScreenProc = gWhichScreenProc;
  500.                 
  501.         // Check if we can do 8-bit-specific tests 
  502.     SetDItemHilite( theDialog, kCompiledSpriteButton, 
  503.             (spriteTestP->spriteWorldP->pixelDepth==8) );
  504. #if SW_PPC    
  505.     SetDItemHilite( theDialog, kCompiledSpriteButton, false );
  506. #endif
  507.  
  508.     SetDItemHilite( theDialog, kTranslucentSpriteButton, 
  509.             ((spriteTestP->spriteWorldP->pixelDepth==8) || (spriteTestP->spriteWorldP->pixelDepth==16)) );
  510.             
  511.     SetDItemHilite( theDialog, kScaledSpriteButton, 
  512.             ((spriteTestP->spriteWorldP->pixelDepth==8) || (spriteTestP->spriteWorldP->pixelDepth==16)) );
  513.             
  514.     SetDItemHilite( theDialog, kRotatedSpriteButton, 
  515.             ((spriteTestP->spriteWorldP->pixelDepth==8) || (spriteTestP->spriteWorldP->pixelDepth==16)) );
  516.             
  517.     SetDItemHilite( theDialog, kLitDrawScreenButton, 
  518.             ((spriteTestP->spriteWorldP->pixelDepth==8) || (spriteTestP->spriteWorldP->pixelDepth==16)) );
  519.  
  520.  
  521.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kRunTestNowCheckBox), true );
  522.     
  523.     SetSetUpTestButtons( theDialog );
  524.     
  525.     ShowWindow( theDialog );
  526.     
  527.     while ( !done )
  528.     {    
  529.         ModalDialog( nil, &itemHit );
  530.         switch( itemHit )
  531.         {
  532.             case kCopyBitsSpriteButton:
  533.                 gWhichSpriteProc = kCopyBitsProc;
  534.                 SetSetUpTestButtons( theDialog );
  535.             break;
  536.             case kBlitPixieSpriteButton:
  537.                 gWhichSpriteProc = kBlitPixieProc;
  538.                 SetSetUpTestButtons( theDialog );
  539.             break;
  540.             case kTranslucentSpriteButton:
  541.                 gWhichSpriteProc = kTranslucentDrawProc;
  542.                 SetSetUpTestButtons( theDialog );
  543.             break;
  544.             case kScaledSpriteButton:
  545.                 gWhichSpriteProc = kScaledDrawProc;
  546.                 SetSetUpTestButtons( theDialog );
  547.             break;
  548.             case kRotatedSpriteButton:
  549.                 gWhichSpriteProc = kRotatedDrawProc;
  550.                 SetSetUpTestButtons( theDialog );
  551.             break;
  552.             case kCompiledSpriteButton:
  553.                 gWhichSpriteProc = kCompiledProc;
  554.                 SetSetUpTestButtons( theDialog );
  555.             break;
  556.             case kCopyBitsOffscreenButton:
  557.                 gWhichOffscreenProc = kCopyBitsProc;
  558.                 SetSetUpTestButtons( theDialog );
  559.             break;
  560.             case kBlitPixieOffscreenButton:
  561.                 gWhichOffscreenProc = kBlitPixieProc;
  562.                 SetSetUpTestButtons( theDialog );
  563.             break;
  564.             case kCopyBitsScreenButton:
  565.                 gWhichScreenProc = kCopyBitsProc;
  566.                 SetSetUpTestButtons( theDialog );
  567.             break;
  568.             case kBlitPixieScreenButton:
  569.                 gWhichScreenProc = kBlitPixieProc;
  570.                 SetSetUpTestButtons( theDialog );
  571.             break;
  572.             case kLitDrawScreenButton:
  573.                 gWhichScreenProc = kLitDrawProc;
  574.                 SetSetUpTestButtons( theDialog );
  575.             break;
  576.             case kRunTestNowCheckBox:
  577.                 ToggleDItemValue(theDialog, kRunTestNowCheckBox);
  578.             break;
  579.             case ok:
  580.                 runNow = GetControlValue( (ControlHandle)GetDItemHandle(theDialog, kRunTestNowCheckBox));
  581.             case cancel:
  582.                 done = true;
  583.             break;
  584.         }
  585.     }
  586.     DisposeDialog( theDialog );
  587.     SetPort( savePort );
  588.     
  589.     if ( itemHit == ok )
  590.     {
  591.         if ( runNow )
  592.             RunTheTest( spriteTestP );
  593.     }
  594.     if ( itemHit == cancel )
  595.     {
  596.         gWhichSpriteProc = originalSpriteProc;
  597.         gWhichOffscreenProc = originalOffscreenProc;
  598.         gWhichScreenProc = originalScreenProc;
  599.     }
  600. }
  601.  
  602.  
  603.  
  604. /******************** SetSetUpTestButtons ********************/
  605. void SetSetUpTestButtons(
  606.     DialogPtr theDialog)
  607. {
  608.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsSpriteButton), 
  609.         (gWhichSpriteProc == kCopyBitsProc) );
  610.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieSpriteButton), 
  611.         (gWhichSpriteProc == kBlitPixieProc) );
  612.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCompiledSpriteButton), 
  613.         (gWhichSpriteProc == kCompiledProc) );
  614.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kTranslucentSpriteButton), 
  615.         (gWhichSpriteProc == kTranslucentDrawProc) );
  616.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kScaledSpriteButton), 
  617.         (gWhichSpriteProc == kScaledDrawProc) );
  618.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kRotatedSpriteButton), 
  619.         (gWhichSpriteProc == kRotatedDrawProc) );
  620.     
  621.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsOffscreenButton), 
  622.         (gWhichOffscreenProc == kCopyBitsProc) );
  623.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieOffscreenButton), 
  624.         (gWhichOffscreenProc == kBlitPixieProc) );
  625.     
  626.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kCopyBitsScreenButton), 
  627.         (gWhichScreenProc == kCopyBitsProc) );
  628.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kBlitPixieScreenButton), 
  629.         (gWhichScreenProc == kBlitPixieProc) );
  630.     SetControlValue( (ControlHandle)GetDItemHandle(theDialog, kLitDrawScreenButton), 
  631.         (gWhichScreenProc == kLitDrawProc) );
  632.         
  633.         
  634. }
  635.  
  636. // Initialize lighting and fill the squares up with some color
  637. void SetupLightingForTest(SpriteTestPtr spriteTestP) {
  638.     int xx, yy;
  639.  
  640.     SWInitializeLightingSquares(spriteTestP->spriteWorldP, 8);
  641.     if (spriteTestP->spriteWorldP->pixelDepth == 8) {
  642.         int curColor = 0;
  643.         for (yy = 0; yy < gLightingSquareRows; yy++) {
  644.             for (xx = 0; xx < gLightingSquareColumns; xx++) {
  645.                 SWSetLightingSquare(spriteTestP->spriteWorldP, xx, yy, 
  646.                                     ((curColor + xx) % 256), 
  647.                                     (yy % 8), 
  648.                                     false, false);
  649.             }
  650.             if ((yy % 8) == 7) curColor += gLightingSquareColumns;
  651.         }
  652.     } else if (spriteTestP->spriteWorldP->pixelDepth == 16) {
  653.         int curColor = 0;
  654.         for (yy = 0; yy < gLightingSquareRows; yy++) {
  655.             for (xx = 0; xx < gLightingSquareColumns; xx++) {
  656.                 SWSetLightingSquare(spriteTestP->spriteWorldP, xx, yy, 
  657.                                     ((curColor + (xx * 44)) % 65536), 
  658.                                     ((yy % 8) * 4) + 1, 
  659.                                     false, false);
  660.             }
  661.             if ((yy % 8) == 7) curColor += (gLightingSquareColumns * 44);
  662.         }
  663.     }
  664. }
  665.  
  666. /******************** RunTheTest ********************/
  667. void RunTheTest(
  668.     SpriteTestPtr spriteTestP)
  669. {
  670.     WindowPtr         testWindowP = FrontWindow();
  671.     SpritePtr         curSpriteP;
  672.     unsigned long     frames, seconds;
  673.     long             ticks;
  674.     Rect            shieldRect;
  675.     Point            shieldRectOffset;
  676.     Rect            srcRect,
  677.                     destRect;
  678.     UnsignedWide    startMicroseconds,
  679.                     endMicroseconds;
  680.     int             count = 0;
  681.     OSErr            err = noErr;
  682.  
  683.  
  684.         // set up for the test
  685.     
  686.     shieldRect = spriteTestP->spriteWorldP->windowFrameP->frameRect;
  687.     LocalToGlobal( &topLeft(shieldRect) );
  688.     LocalToGlobal( &botRight(shieldRect) );
  689.     shieldRectOffset.h = shieldRectOffset.v = 0;
  690.     ShieldCursor( &shieldRect, shieldRectOffset );
  691.     
  692.     SWHideMenuBar(testWindowP);
  693.     
  694.     UpdateSpriteTest( spriteTestP, testWindowP );
  695.     
  696.     curSpriteP = NULL;
  697.     while ((curSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, curSpriteP)) != NULL)
  698.     {
  699.         if (curSpriteP != spriteTestP->titleSpriteP && curSpriteP != spriteTestP->twoSpriteP)
  700.         {
  701.             SWSetSpriteFrameTime(curSpriteP, 0);
  702.             SWSetSpriteMoveTime(curSpriteP, 0);
  703.             switch ( gWhichSpriteProc )
  704.             {
  705.                 case kBlitPixieProc:
  706.                     if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  707.                         (void)SWSetSpriteDrawProc(curSpriteP, BlitPixie8BitMaskDrawProc);
  708.                     else
  709.                     {
  710.                         (void)SWSetSpriteDrawProc(curSpriteP, BlitPixieAllBitMaskDrawProc);
  711.                     }
  712.                 break;
  713.                 case kTranslucentDrawProc:
  714.                     if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  715.                     {
  716.                         if (g8BitTranslucencyTable == NULL)
  717.                             err = SWLoadOrCreate8BitTranslucencyTable (kNumberOfTranslucencyLevels);
  718.                         (void)SWSetSpriteTranslucencyLevel(curSpriteP, 1);
  719.                     } 
  720.                     else if ( spriteTestP->spriteWorldP->pixelDepth == 16 )
  721.                     {
  722.                         if (g16BitTranslucencyTable == NULL)
  723.                             err = SWCreate16BitTranslucencyTable();
  724.                         (void)SWSetSpriteTranslucencyLevel(curSpriteP, 16);
  725.                     } 
  726.                     else 
  727.                     {
  728.                         (void)SWSetSpriteDrawProc(curSpriteP, BlitPixieAllBitMaskDrawProc);
  729.                     }
  730.                 break;
  731.                 case kScaledDrawProc:
  732.                     if ((spriteTestP->spriteWorldP->pixelDepth == 8) ||
  733.                         (spriteTestP->spriteWorldP->pixelDepth == 16)) {
  734.                         if (count & 1)
  735.                             SWSetSpriteScaledSize(curSpriteP, 75, 75);
  736.                         else
  737.                         {
  738.                             SWSetSpriteScaledSize(curSpriteP, 20, 20);
  739.                         }
  740.                         count++;
  741.                     } else {
  742.                         (void)SWSetSpriteDrawProc(curSpriteP, BlitPixieAllBitMaskDrawProc);
  743.                     }
  744.                 break;
  745.                 case kRotatedDrawProc:
  746.                     if (( spriteTestP->spriteWorldP->pixelDepth == 8 ) ||
  747.                          ( spriteTestP->spriteWorldP->pixelDepth == 16 )) {
  748.                         (void)SWSetSpriteRotation(curSpriteP, 3);
  749.                     } else {
  750.                         (void)SWSetSpriteDrawProc(curSpriteP, BlitPixieAllBitMaskDrawProc);
  751.                     }
  752.                 break;
  753.                 case kCompiledProc:
  754.                     (void)SWSetSpriteDrawProc(curSpriteP, CompiledSprite8BitDrawProc);
  755.                 break;
  756.             }
  757.         }
  758.     }
  759.     
  760.     if ( gWhichSpriteProc == kBlitPixieProc || gWhichSpriteProc == kCompiledProc || gWhichSpriteProc == kTranslucentDrawProc)
  761.     {
  762.         if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  763.         {
  764.             (void)SWSetSpriteDrawProc(spriteTestP->titleSpriteP, BlitPixie8BitMaskDrawProc);
  765.             (void)SWSetSpriteDrawProc(spriteTestP->twoSpriteP, BlitPixie8BitMaskDrawProc);
  766.         }
  767.         else
  768.         {
  769.             (void)SWSetSpriteDrawProc(spriteTestP->titleSpriteP, BlitPixieAllBitMaskDrawProc);
  770.             (void)SWSetSpriteDrawProc(spriteTestP->twoSpriteP, BlitPixieAllBitMaskDrawProc);    
  771.         }
  772.     }
  773.     if ( gWhichOffscreenProc == kBlitPixieProc )
  774.     { 
  775.         if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  776.         {
  777.             (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP, 
  778.                 BlitPixie8BitRectDrawProc);
  779.         }
  780.         else
  781.         {
  782.             (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP, 
  783.                 BlitPixieAllBitRectDrawProc);    
  784.         }
  785.     }
  786.     if ( gWhichScreenProc == kBlitPixieProc )
  787.     {
  788.         if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  789.         {
  790.             (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, 
  791.                 BlitPixie8BitRectDrawProc);
  792.         }
  793.         else
  794.         {
  795.             (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, 
  796.                 BlitPixieAllBitRectDrawProc);    
  797.         }        
  798.     }
  799.  
  800.     if ( gWhichScreenProc == kLitDrawProc )
  801.     {
  802.         if ( spriteTestP->spriteWorldP->pixelDepth == 8 )
  803.         {
  804.             if (g8BitTranslucencyTable == NULL)
  805.                 err = SWLoadOrCreate8BitTranslucencyTable(kNumberOfTranslucencyLevels);
  806.             SetupLightingForTest(spriteTestP);
  807.             (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, 
  808.                 BlitPixie8BitLitRectDrawProc);
  809.             //Draw it once to light the whole screen nicely
  810.             SWUpdateSpriteWorld(spriteTestP->spriteWorldP, true);
  811.         }
  812.         else if ( spriteTestP->spriteWorldP->pixelDepth == 16 )
  813.         {
  814.             if (g16BitTranslucencyTable == NULL)
  815.                 err = SWCreate16BitTranslucencyTable();
  816.             SetupLightingForTest(spriteTestP);
  817.             (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, 
  818.                 BlitPixie16BitLitRectDrawProc);
  819.             //Draw it once to light the whole screen nicely
  820.             SWUpdateSpriteWorld(spriteTestP->spriteWorldP, true);
  821.         } else {
  822.             (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP, 
  823.                 BlitPixieAllBitRectDrawProc);    
  824.         }
  825.     }
  826.  
  827.     if (err != noErr)
  828.     {
  829.         SysBeep(1);
  830.         RestoreFromTest( testWindowP, spriteTestP );
  831.         return;
  832.     }
  833.  
  834.  
  835.         // Floor it!!!
  836.     SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 0 );
  837.     
  838.     ticks = TickCount();
  839.  
  840.  
  841.         // the actual tests...
  842.         
  843.         // a straight blitter test -- no animation to screen
  844.  
  845.     if ( kBlitterTest && spriteTestP->spriteWorldP->pixelDepth == 8 )
  846.     {
  847.         srcRect = gMasterGlobeSprite->frameArray[0]->frameRect;
  848.         destRect = srcRect;
  849.         OffsetRect( &destRect, 3, 0 );
  850.         Microseconds( &startMicroseconds );
  851.         for (frames = 0; frames < 10000; frames++ )
  852.         {
  853.             BlitPixie8BitRectDrawProc(
  854.                 gMasterGlobeSprite->frameArray[0],
  855.                 spriteTestP->spriteWorldP->workFrameP,
  856.                 &srcRect,
  857.                 &destRect);
  858.         }
  859.         Microseconds( &endMicroseconds );
  860.         seconds = endMicroseconds.lo - startMicroseconds.lo;
  861.         if ( endMicroseconds.hi != startMicroseconds.hi )
  862.             seconds = 0;        // do test over
  863.     }
  864.         // a test of animation to screen
  865.     else
  866.     {
  867. /*
  868.         ProfilerSetStatus( true );
  869. */
  870.         for (frames = 0; ((TickCount() - ticks) < kTestTime) && (!Button()); frames++)
  871.         {
  872.             if (gCollisionDetection)
  873.             {
  874.                 SWCollideSpriteLayer(spriteTestP->spriteWorldP, 
  875.                     spriteTestP->globeSpriteLayerP, spriteTestP->globeSpriteLayerP);
  876.             }
  877.  
  878.             SWProcessSpriteWorld( spriteTestP->spriteWorldP );
  879.             SWAnimateSpriteWorld( spriteTestP->spriteWorldP );
  880.         }
  881.         seconds = ((TickCount() - ticks) / 60);
  882.     }
  883. /*
  884.     ProfilerSetStatus( false );
  885.     ProfilerDump( "\pSWPPC Profile" );
  886.     ProfilerTerm();
  887. */
  888.  
  889.         // restore things to default state
  890.     RestoreFromTest( testWindowP, spriteTestP );
  891.     
  892.     DisplayPerformance(frames, seconds);
  893.  
  894.     // Redraw everything once to remove any lighting stuff. (after displaying performance so 
  895.     // we can look closely
  896.     SWUpdateSpriteWorld(spriteTestP->spriteWorldP, true);
  897. }
  898.  
  899.  
  900.  
  901. /******************** RestoreFromTest ********************/
  902. void RestoreFromTest(
  903.     WindowPtr testWindowP,
  904.     SpriteTestPtr spriteTestP)
  905. {
  906.     SpritePtr             curSpriteP;
  907.     
  908.     
  909.         // restore things to default state
  910.         
  911.     curSpriteP = NULL;
  912.  
  913.     while ((curSpriteP = SWGetNextSprite(spriteTestP->globeSpriteLayerP, curSpriteP)) != NULL)
  914.     {
  915.         SWSetSpriteScaledSize(curSpriteP, -1, -1);
  916.         (void)SWSetSpriteDrawProc(curSpriteP, SWStdSpriteDrawProc);
  917.         if (curSpriteP != spriteTestP->titleSpriteP && curSpriteP != spriteTestP->twoSpriteP)
  918.         {
  919.             SWSetSpriteFrameTime(curSpriteP, kGlobeSpriteFrameTime);
  920.         }
  921.     }
  922.     
  923.     (void)SWSetSpriteWorldOffscreenDrawProc(spriteTestP->spriteWorldP, SWStdWorldDrawProc);
  924.     (void)SWSetSpriteWorldScreenDrawProc(spriteTestP->spriteWorldP, SWStdWorldDrawProc);
  925.     
  926.     SWSetSpriteWorldMaxFPS( spriteTestP->spriteWorldP, 30 );
  927.         
  928.     ShowCursor();
  929.     SWShowMenuBar(testWindowP);
  930. }
  931.  
  932.  
  933. /******************** DisplayPerformance ********************/
  934. void DisplayPerformance(
  935.     long frames,
  936.     long seconds)
  937. {
  938.     Str255 framesString, secondsString, fpsString;
  939.     long fps;
  940.     
  941.     NumToString(frames, framesString);
  942.     NumToString(seconds, secondsString);
  943.  
  944.     fps = (seconds > 0) ? frames / seconds : frames;
  945.     
  946.     NumToString(fps, fpsString);
  947.     
  948.     ParamText(framesString, secondsString, fpsString, "\p");
  949.     NoteAlert(kPerformanceAlertID, NULL);
  950. }
  951.  
  952.  
  953. /******************** GlobeSpriteMoveProc ********************/
  954. SW_FUNC void GlobeSpriteMoveProc(SpritePtr globeSpriteP)
  955. {    
  956.     SWOffsetSprite(globeSpriteP, globeSpriteP->horizMoveDelta, globeSpriteP->vertMoveDelta);
  957.     (void)SWBounceSprite(globeSpriteP);
  958. }
  959.  
  960.  
  961. /******************** PixelBounceCollideProc ********************/
  962. SW_FUNC void PixelBounceCollideProc(
  963.     SpritePtr srcSpriteP,
  964.     SpritePtr dstSpriteP,
  965.     Rect* sectRect)
  966. {    
  967.  
  968.         // If both sprites use the same collision routine (this one),ignore the second collision.
  969.     if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
  970.         ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
  971.         (srcSpriteP > dstSpriteP)))
  972.     {
  973.         return;
  974.     }
  975.  
  976.     if ( SWPixelCollision(srcSpriteP, dstSpriteP) )
  977.     {
  978.             // if a stationary sprite (the title), just bounce off it
  979.         if ((dstSpriteP->horizMoveDelta == 0) && (dstSpriteP->vertMoveDelta == 0))
  980.         {
  981.             BounceGlobeOffTitle( dstSpriteP, srcSpriteP, sectRect );
  982.         }
  983.         else    
  984.             // globe to globe collision; swap movement delta's
  985.         {
  986.             BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
  987.         }
  988.     }
  989. }
  990.  
  991.  
  992. /******************** RegionBounceCollideProc ********************/
  993. SW_FUNC void RegionBounceCollideProc(
  994.     SpritePtr srcSpriteP,
  995.     SpritePtr dstSpriteP,
  996.     Rect* sectRect)
  997. {    
  998.  
  999.         // If both sprites use the same collision routine (this one),ignore the second collision.
  1000.     if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
  1001.         ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
  1002.         (srcSpriteP > dstSpriteP)))
  1003.     {
  1004.         return;
  1005.     }
  1006.  
  1007.  
  1008.     if ( SWRegionCollision(srcSpriteP, dstSpriteP) )
  1009.     {
  1010.             // if a stationary sprite (the title), just bounce off it
  1011.         if ((dstSpriteP->horizMoveDelta == 0) && (dstSpriteP->vertMoveDelta == 0))
  1012.         {
  1013.             BounceGlobeOffTitle( dstSpriteP, srcSpriteP, sectRect );
  1014.         }
  1015.         else    
  1016.             // globe to globe collision; swap movement delta's
  1017.         {
  1018.             BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
  1019.         }
  1020.     }
  1021. }
  1022.  
  1023.  
  1024. /******************** RadiusBounceCollideProc ********************/
  1025. SW_FUNC void RadiusBounceCollideProc(
  1026.     SpritePtr srcSpriteP,
  1027.     SpritePtr dstSpriteP,
  1028.     Rect* sectRect)
  1029. {
  1030.      #pragma        unused(sectRect)
  1031.  
  1032.         // If both sprites use the same collision routine (this one),ignore the second collision.
  1033.     if ((!srcSpriteP->isVisible || !dstSpriteP->isVisible) ||
  1034.         ((srcSpriteP->spriteCollideProc == dstSpriteP->spriteCollideProc) &&
  1035.         (srcSpriteP > dstSpriteP)))
  1036.         return;
  1037.  
  1038.         // ignore collision with title sprite
  1039.     if ( (srcSpriteP->destFrameRect.right-srcSpriteP->destFrameRect.left !=
  1040.          srcSpriteP->destFrameRect.bottom-srcSpriteP->destFrameRect.top) ||
  1041.          (dstSpriteP->destFrameRect.right-dstSpriteP->destFrameRect.left !=
  1042.          dstSpriteP->destFrameRect.bottom-dstSpriteP->destFrameRect.top))
  1043.         return;
  1044.  
  1045.     if ( SWRadiusCollision( srcSpriteP, dstSpriteP ) )
  1046.     {
  1047.         BounceGlobeOffGlobe( srcSpriteP, dstSpriteP );
  1048.     }
  1049. }
  1050.  
  1051.  
  1052. /******************** BounceGlobeOffGlobe ********************/
  1053. void BounceGlobeOffGlobe(
  1054.     SpritePtr srcSpriteP,
  1055.     SpritePtr dstSpriteP )
  1056. {
  1057.     short            tempDelta;
  1058.     short            nextHorizDistA, nextVertDistA,
  1059.                     nextHorizDistB, nextVertDistB;
  1060.  
  1061.     
  1062.         // reverse spins.
  1063.     srcSpriteP->frameAdvance = -srcSpriteP->frameAdvance;
  1064.     dstSpriteP->frameAdvance = -dstSpriteP->frameAdvance;
  1065.  
  1066.         // Calculate what the distance between sprites will be if we don't switch deltas
  1067.     nextHorizDistA = srcSpriteP->destFrameRect.left + srcSpriteP->horizMoveDelta - 
  1068.                 (dstSpriteP->destFrameRect.left + dstSpriteP->horizMoveDelta);
  1069.     if (nextHorizDistA < 0)
  1070.         nextHorizDistA = -nextHorizDistA;
  1071.     
  1072.     nextVertDistA = srcSpriteP->destFrameRect.top + srcSpriteP->vertMoveDelta - 
  1073.                 (dstSpriteP->destFrameRect.top + dstSpriteP->vertMoveDelta);
  1074.     if (nextVertDistA < 0)
  1075.         nextVertDistA = -nextVertDistA;
  1076.     
  1077.         // Calculate what the distance between sprites will be if we do switch deltas
  1078.     nextHorizDistB = srcSpriteP->destFrameRect.left + dstSpriteP->horizMoveDelta - 
  1079.                 (dstSpriteP->destFrameRect.left + srcSpriteP->horizMoveDelta);
  1080.     if (nextHorizDistB < 0)
  1081.         nextHorizDistB = -nextHorizDistB;
  1082.     
  1083.     nextVertDistB = srcSpriteP->destFrameRect.top + dstSpriteP->vertMoveDelta - 
  1084.                 (dstSpriteP->destFrameRect.top + srcSpriteP->vertMoveDelta);
  1085.     if (nextVertDistB < 0)
  1086.         nextVertDistB = -nextVertDistB;
  1087.     
  1088.     
  1089.         // Will swapping the horizontal deltas move the sprites farther apart?
  1090.     if (nextHorizDistB > nextHorizDistA)
  1091.     {
  1092.             // swap horizontal deltas
  1093.         tempDelta = srcSpriteP->horizMoveDelta;
  1094.         srcSpriteP->horizMoveDelta = dstSpriteP->horizMoveDelta;
  1095.         dstSpriteP->horizMoveDelta = tempDelta;
  1096.     }
  1097.     
  1098.         // Will swapping the vertical deltas move the sprites farther apart?
  1099.     if (nextVertDistB > nextVertDistA)
  1100.     {
  1101.             // swap vertical deltas
  1102.         tempDelta = srcSpriteP->vertMoveDelta;
  1103.         srcSpriteP->vertMoveDelta = dstSpriteP->vertMoveDelta;
  1104.         dstSpriteP->vertMoveDelta = tempDelta;
  1105.     }
  1106. }
  1107.  
  1108.  
  1109.  /******************** BounceGlobeOffTitle ********************/
  1110. void BounceGlobeOffTitle(
  1111.     SpritePtr titleSpriteP,
  1112.     SpritePtr globeSpriteP,
  1113.     Rect* sectRect )
  1114. {
  1115.     short        absHorizDelta,
  1116.                 absVertDelta;
  1117.                 
  1118.     absHorizDelta = globeSpriteP->horizMoveDelta;
  1119.     if ( absHorizDelta < 0 )
  1120.         absHorizDelta = -absHorizDelta;
  1121.     absVertDelta = globeSpriteP->vertMoveDelta;
  1122.     if ( absVertDelta < 0 )
  1123.         absVertDelta = -absVertDelta;
  1124.         
  1125.     // draw a picture and this test algorithm will become clear
  1126.     if ((sectRect->right - sectRect->left) < (sectRect->bottom - sectRect->top) )
  1127.     {
  1128.             // Hit left or right side
  1129.         if ( sectRect->left <= titleSpriteP->destFrameRect.left )
  1130.             // hit on left side
  1131.             globeSpriteP->horizMoveDelta = -absHorizDelta;
  1132.         else
  1133.             // hit on right side
  1134.             globeSpriteP->horizMoveDelta = absHorizDelta;
  1135.     }
  1136.     else
  1137.     {
  1138.             // Hit top or bottom
  1139.         if ( sectRect->top <= titleSpriteP->destFrameRect.top )
  1140.             // hit on top
  1141.             globeSpriteP->vertMoveDelta = -absVertDelta;
  1142.         else
  1143.             // hit on bottom
  1144.             globeSpriteP->vertMoveDelta = absVertDelta;
  1145.     }
  1146. }
  1147.