这是在 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];
}
}
这是在 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];
}
}
}
}
我无法弄清楚我写“这里发生了什么”的地方发生了什么?我想要这样,如果一只鸟被困在形状内,那么 [doDie] 就会发生。如果鸟没有被困在形状中,它会被填充。任何想法都非常感谢。