From f39ff64d51952d8af896daf8b556178abc01d47a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 5 Sep 2011 00:30:05 -0400 Subject: Fixed jumping while paused in Jump mode Refs #204 and fixes #214 --- Classes/JumpGameMode.h | 1 + Classes/JumpGameMode.m | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index 0d23317..0b6c5d2 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h @@ -14,6 +14,7 @@ CCSprite* water; int waterTick; BOOL wave; + BOOL isGesturing; CGPoint gestureStartPoint; int jumpTick; BOOL jump; diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index f03eae0..79c87bc 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m @@ -189,24 +189,36 @@ - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch* touch = [touches anyObject]; - gestureStartPoint = [touch locationInView:nil]; + if ((!isPaused) && (!isGesturing)) + { + UITouch* touch = [touches anyObject]; + gestureStartPoint = [touch locationInView:nil]; + isGesturing = YES; + } } - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - UITouch* touch = [touches anyObject]; - CGPoint gestureCurrentPosition = [touch locationInView:nil]; - CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); - CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); - - if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && ((cart.sprite.position.y >= 80) && (cart.sprite.position.y <= 90))) + if (isGesturing) { - jump = YES; - cart.falling = NO; + UITouch* touch = [touches anyObject]; + CGPoint gestureCurrentPosition = [touch locationInView:nil]; + CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); + CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); + + if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && ((cart.sprite.position.y >= 80) && (cart.sprite.position.y <= 90))) + { + jump = YES; + cart.falling = NO; + } } } +- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event +{ + isGesturing = NO; +} + - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { [super accelerometer:accelerometer didAccelerate:acceleration]; -- cgit 1.4.1