diff options
-rw-r--r-- | Classes/JumpGameMode.h | 2 | ||||
-rw-r--r-- | Classes/JumpGameMode.m | 11 |
2 files changed, 6 insertions, 7 deletions
diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index 7b7dff4..9753720 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h | |||
@@ -15,7 +15,7 @@ | |||
15 | CGPoint gestureStartPoint; | 15 | CGPoint gestureStartPoint; |
16 | int jumpTick; | 16 | int jumpTick; |
17 | BOOL jump; | 17 | BOOL jump; |
18 | float swipeVarianceModifer; | 18 | float expectedAngle; |
19 | } | 19 | } |
20 | 20 | ||
21 | @end | 21 | @end |
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 |