Advertisement
Guest User

Untitled

a guest
Mar 19th, 2013
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)checkForCollision {
  2.     float panImageSize =[panSprite texture].contentSize.width;
  3.     float eggImageSize = [[eggArray lastObject] texture].contentSize.width;
  4.     float panCollisionRadius = panImageSize*0.3f;
  5.     float eggCollisionRadius = eggImageSize *0.3f;
  6.     float maxCollisionDistance = panCollisionRadius + eggCollisionRadius;
  7.    //CCLOG(@"Egg Array count %d",eggArray.count);
  8.     //Assumption: both pan and spider images are squares
  9.     NSMutableArray *eggsToDelete = [[NSMutableArray alloc] init];
  10.     for (CCSprite *egg in eggArray){
  11.          float actualDistance =  ccpDistance(panSprite.position, egg.position);
  12.         if ((actualDistance < maxCollisionDistance)) {
  13.             [halfFry runAction:[CCFadeOut actionWithDuration:0.2f]];
  14.            NSLog(@" Collision ");
  15.             NSLog(@" pan frame %@",NSStringFromCGRect(panSprite.boundingBox));
  16.             NSLog(@" egge frame %@",NSStringFromCGRect(egg.boundingBox));
  17.            halfFry.position = ccp(panSprite.position.x, panSprite.position.y);
  18.            [eggsToDelete addObject:egg];
  19.             score+=10;
  20.            }
  21.        
  22.    
  23.     }
  24.  
  25.         for (CCSprite *egg  in eggsToDelete ) {
  26.             [eggArray removeObject:egg];
  27.             [self removeChild:egg cleanup:YES];
  28.             if (eggArray.count==0) {
  29.                 [self initEggs];
  30.                }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement