summary refs log tree commit diff stats
path: root/Classes/JumpGameMode.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r--Classes/JumpGameMode.m11
1 files changed, 5 insertions, 6 deletions
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index e8c8c7e..e30be6a 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m
@@ -8,8 +8,7 @@
8 8
9#import "JumpGameMode.h" 9#import "JumpGameMode.h"
10 10
11#define kMinimumGestureLength 25 11#define kMinimumGestureLength 50
12#define kMaximumVariance 5
13 12
14@implementation JumpGameMode 13@implementation JumpGameMode
15 14
@@ -91,10 +90,10 @@
91{ 90{
92 UITouch* touch = [touches anyObject]; 91 UITouch* touch = [touches anyObject];
93 CGPoint gestureCurrentPosition = [touch locationInView:nil]; 92 CGPoint gestureCurrentPosition = [touch locationInView:nil];
94 CGFloat deltaX = fabsf(gestureStartPoint.x - gestureCurrentPosition.x); 93 CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x);
95 CGFloat deltaY = fabsf(gestureStartPoint.y - gestureCurrentPosition.y); 94 CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2));
96 95
97 if ((deltaX >= kMinimumGestureLength) && (deltaY <= kMaximumVariance*swipeVarianceModifer) && (cart.sprite.position.y == 22)) 96 if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && (cart.sprite.position.y == 22))
98 { 97 {
99 jump = YES; 98 jump = YES;
100 } 99 }
@@ -104,7 +103,7 @@
104{ 103{
105 [super accelerometer:accelerometer didAccelerate:acceleration]; 104 [super accelerometer:accelerometer didAccelerate:acceleration];
106 105
107 swipeVarianceModifer = MAX(1,(fabsf(acceleration.y) * 480)/kMaximumVariance); 106 expectedAngle = acceleration.y*M_PI_2;
108} 107}
109 108
110@end 109@end