【发布时间】:2012-03-10 10:30:13
【问题描述】:
我设计了一个应用程序,用户可以在 30 秒内尽可能多地点击球,称为 iTapping。在游戏中,用户可以点击屏幕上的任意位置让球被点击。我想编辑应用程序,以便用户无法点击球的“死角”。例如,如果球在右上角(假设在大约 100 平方英尺的区域内),并且用户点击球没有任何反应。我将如何编码?如果这还不够清楚,请告诉我。
这是 .m 文件:
CGPoint Destination;
CGFloat xamt, yamt;
CGFloat speed21 = 40;
CGFloat xMin21 = 24;
CGFloat xMax21 = 297;
CGFloat yMin21 = 74;
CGFloat yMax21 = 454;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if ([self Intersecting:location :Ball]) {
number21++;
int xRange = xMax21 - xMin21;
int yRange = yMax21 - yMin21;
int xRand = (arc4random() % xRange) + xMin21;
int yRand = (arc4random() % yRange) + yMin21;
Destination = CGPointMake(xRand, yRand);
xamt = ((Destination.x - Ball.center.x) / speed21);
yamt = ((Destination.y - Ball.center.y) / speed21);
if (number21 == 65) {
[timer invalidate];
}
}
}
-(BOOL)Intersecting:(CGPoint)loctouch:(UIImageView *)enemyimg {
CGFloat x1 = loctouch.x;
CGFloat y1 = loctouch.y;
CGFloat x2 = enemyimg.frame.origin.x;
CGFloat y2 = enemyimg.frame.origin.y;
CGFloat w2 = enemyimg.frame.size.width;
CGFloat h2 = enemyimg.frame.size.height;
if ((x1>x2)&&(x1<x2+w2)&&(y1>y2)&&(y1<y2+h2))
return YES;
else
return NO;
}
【问题讨论】:
标签: iphone ios game-physics