Thanks for the info, I made some changes but I'm still stuck. Here's my complete update method:
-(void)update:(ccTime)dt {
//set playerboundingboxes
CGRect player1Rect = CGRectMake(p1shark.position.x,p1shark.position.y,130,100);
CGRect player2Rect = CGRectMake(p2shark.position.x,p2shark.position.y,130,100);
CGRect player3Rect = CGRectMake(p3shark.position.x,p3shark.position.y,130,100);
CGRect player4Rect = CGRectMake(p4shark.position.x,p4shark.position.y,130,100);
//alloc targets to delete array
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
//set targetboundingboxes
for (CCSprite *target in _targets)
{
CGRect targetRect = CGRectMake(target.position.x - (target.contentSize.width/2),
target.position.y - (target.contentSize.height/2),
target.contentSize.width,
target.contentSize.height);
//check if target boxes intercept with player bounding boxes
if (CGRectIntersectsRect(player1Rect, targetRect))
{
//add target to delete array
[targetsToDelete addObject:target];
Food *target = [Food alloc];
P1Score = P1Score + target.foodScore; //try to increment score by food value, not working
NSLog(@"P1Score is %d", P1Score);
NSLog(@"Food Value was %d", target.foodScore);
//test score label
//CCLabel *labelp1score = [CCLabel labelWithString:[NSString stringWithFormat:@"%d",foodScore] fontName:@"Marker Felt" fontSize:30];
//show score of food
CCLabel *labelp1score = [CCLabel labelWithString:[NSString stringWithFormat:@"+1"] fontName:@"Marker Felt" fontSize:30];
labelp1score.color = ccc3(0x00, 0x00, 0xff);
labelp1score.position = ccp(300,300);
labelp1score.rotation = 45;
[self addChild:labelp1score];
id actionLabelP1 = [CCFadeOut actionWithDuration:0.5f];
[labelp1score runAction:actionLabelP1];
}
for (CCSprite *target in targetsToDelete)
{
[_targets removeObject:target];
[self removeChild:target cleanup:YES];
_targetsDestroyed++;
NSLog(@"Targets Destroyed, %d", _targetsDestroyed);
}
if (targetsToDelete.count > 0)
{
[targetsToDelete release];
}
}
And here's my method to create the object.
-(void)addFood {
//Create Food object
//Food *target = nil;
Food *target = [[Food alloc]init];
//randomize food spawn
int foodselection = (arc4random() % 4);
if ((foodselection) == 0) {
target = [Redfish food];
} else if ((foodselection) == 1) {
target = [Greenfish food];
} else if ((foodselection) == 2) {
target = [YellowSquid food];
} else if ((foodselection) == 3) {
target = [WhiteSquid food];
}
//NSLog(@"Food selection is %d", foodselection);
//randomize spawn location
int spawnLoc = (arc4random() % 4) + 1;
// 1 = top
// 2 = bottom
// 3 = left
// 4 = right
// Determine speed of the target
int minDuration = target.minMoveDuration;
int maxDuration = target.maxMoveDuration;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// init food score
int foodScoreValue = target.foodScore;
NSLog(@"Food Score Value is, %d", foodScoreValue);
// Determine size of the target
int minFoodSize = target.minFoodSize;
int maxFoodSize = target.maxFoodSize;
int randomFoodSize = (arc4random() % maxFoodSize) + minFoodSize;
float actualFoodSize = randomFoodSize * .10 + 1;
target.scale = actualFoodSize;
if ((spawnLoc) == 1) { //set location for top spawn
int minX = 100;
int maxX = 924;
//int originalrotation = -90;
int rangeX = maxX - minX;
int spawnactualX = (arc4random() % rangeX) + minX;
//NSLog(@"Spawn Actual X is %d", spawnactualX);
int destactualX = (arc4random() % rangeX) + minX;
//NSLog(@"Destination Actual X is %d", destactualX);
//rotate the target to match the destination point
int angle = -180 + (atan2(768 - 0, destactualX - spawnactualX) * (180/3.14));
NSLog(@"Angle is %d", angle);
target.rotation = angle;
//position and add target
target.position = ccp(spawnactualX, 1000);
[self addChild:target z:-1];
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(destactualX, -target.contentSize.height/2)]; // destination
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
// Add to targets array
target.tag = 1;
[_targets addObject:target];
}
I can verify that each instance of 'food' being added is being assigned a score value (in the addfood method), but the update method is not pulling in the score value.