views:

227

answers:

1

this is in GameViewController.m

-(void)fillMutablePath{



    CGPoint movePoint = CGPointFromString([pointsToFillArray objectAtIndex:0]);

    CGPathMoveToPoint(fillPath, NULL, movePoint.x, movePoint.y);
    for (int i=0; i<[pointsToFillArray count]; i++) {
        CGPoint tempPoint = CGPointFromString([pointsToFillArray objectAtIndex:i]);
        CGPathAddLineToPoint(fillPath, NULL, tempPoint.x, tempPoint.y);
        CGContextAddPath(gameViewObj._myContext, fillPath);
        CGContextFillPath(gameViewObj._myContext);

        if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
            [self doDie];
        }
else {
  CGContextFillPath(gameViewObj._myContext);
}
        CGPathRelease(fillPath);
        [pointsToFillArray removeAllObjects];
    }


}

This is in GameView.m

-(CGPoint) GetBirdPosition:(CGPoint) PtPoint :(int) BirdNumber{
    CGPoint Temp=PtPoint;
    BOOL isTouch=TRUE;
    while (isTouch)
    {
        isTouch=FALSE;
        if(playField[(int) Temp.x][(int) Temp.y]==2)
        {
            isTouch=TRUE;
            if(playField[(int) Temp.x+1][(int) Temp.y] == 2 || playField[(int) Temp.x-1][(int) Temp.y] == 2)
            {
                pos[BirdNumber].y = -pos[BirdNumber].y;
                Temp.y+=pos[BirdNumber].y;

            }
            else if(playField[(int) Temp.x][(int) Temp.y+1] == 2 || playField[(int) Temp.x][(int) Temp.y-1] == 2)
            {
                pos[BirdNumber].x = -pos[BirdNumber].x;
                Temp.x+=pos[BirdNumber].x;
            }

        }
    }
    return Temp;
}

-(void)flyingBird:(NSTimer *)timer {

    if(appDelegate.gameStateRunning == YES){

        for (int i=0; i< [birdImageViewArray count];i++)
        {
            UIImageView* birdImageView=[birdImageViewArray objectAtIndex:i];

            CGPoint Temp=CGPointMake(birdImageView.center.x + pos[i].x , birdImageView.center.y + pos[i].y);
            birdImageView.center =[self GetBirdPosition:Temp:i];

            if(playField[(int) birdImageView.center.x][(int) birdImageView.center.y]==3){

                [[NSNotificationCenter defaultCenter] postNotificationName:@"LineCrossed" object:nil];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"PlayDieSound" object:nil];
            }
        }
    }
}

I can't figure out what goes in the place where I wrote "what goes here"?? I want it so that if a bird is trapped within the shape, then [doDie] takes place. If the bird is not trapped within the shape, it gets filled in. Any ideas are greatly appreciated.

A: 

I don't really understand your code, but I imagine this is basically what you want to do:

CGPoint Temp=CGPointMake(birdImageView.center.x + pos[birdNum].x , birdImageView.center.y + pos[birdNum].y);
if(CGPathContainsPoint(fillPath, nil, [myGameView GetBirdPosition:Temp:i], false)){
    [self doDie];
}

It looks like your path is initially just a line, and I don't think anything will be contained within it. If you explain the objective more thoroughly (how many birds are we checking? Is it the same path for each?) we can help further.

Edit:

Hmmmm, OK. First thing is simple enough. To prevent filling if any bird is in the path, don't use an else case. In the if, set a flag if the current bird is contained in the path. Then after the loop, if the flag is not set, fill the path. So something like:

BOOL pathContainsBird = NO;
for (int i=0; i<[pointsToFillArray count]; i++) {
    //bunch of stuff
    if(CGPathContainsPoint(fillPath, nil, "What goes here?", false)){
        pathContainsBird = YES;
        [self doDie];
    }
}
if(!pathContainsBird) {
    //fill path here
}

Second, I'm pretty sure you aren't looping through the right thing. It looks like you expand the path every iteration, but I think you should build the whole path first, then loop through all the birds, but I could be misunderstanding.

David Kanarek
There could be anywhere from 2-26 birds flying around depending on the level. If any one of them is contained within the shape that is formed, i want [doDie] to occur. It's driving me crazy. I can get the opposite of what I want to happen. I just can't figure out how I made it so that the area doesn't get filled in with color if a bird is contained in the shape. I will try your suggestion and see what I come up with.
NextRev