I am trying to develop maze game using objective-c, I want to allow moving the pac-man using swipe method, the user can swipe his fingers on the iPhone to indicate where he want PAC-MAN to go but I'm stuck on moving pac_man. I used UIPanGesture but it can't indicate the collision of ghosts?
Please see the bellow code:
- (IBAction)pacmanmovement:(UIPanGestureRecognizer *)sender {
CGPoint netTranslation;
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.pacman];
sender.view.transform = CGAffineTransformMakeTranslation(
netTranslation.x + translatedPoint.x,
netTranslation.y += translatedPoint.y);
if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
netTranslation.x += translatedPoint.x;
netTranslation.y += translatedPoint.y;
}
[self collisionWithGhosts];
}
- (void)collisionWithGhosts {
CALayer *ghostLayer1 = [self.ghost1.layer presentationLayer];
CALayer *ghostLayer2 = [self.ghost2.layer presentationLayer];
CALayer *ghostLayer3 = [self.ghost3.layer presentationLayer];
CALayer *ghostLayer4 = [self.ghost4.layer presentationLayer];
if (CGRectIntersectsRect(self.pacman.frame, ghostLayer1.frame)
|| CGRectIntersectsRect(self.pacman.frame, ghostLayer2.frame)
|| CGRectIntersectsRect(self.pacman.frame, ghostLayer3.frame)
|| CGRectIntersectsRect(self.pacman.frame, ghostLayer4.frame) ) {
self.currentPoint = CGPointMake(0, 144);
}
Any help?