summary refs log tree commit diff stats
path: root/Classes/JumpGameMode.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-17 20:29:16 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-17 20:29:16 -0400
commit6b9c8afd0e4a49efffd504378f1db34264928250 (patch)
tree7a3a64517344406c56b174f04fb19e0374f13398 /Classes/JumpGameMode.m
parent4d94802036a53e6ec246ab0abac17fd76d17c885 (diff)
downloadcartcollect-6b9c8afd0e4a49efffd504378f1db34264928250.tar.gz
cartcollect-6b9c8afd0e4a49efffd504378f1db34264928250.tar.bz2
cartcollect-6b9c8afd0e4a49efffd504378f1db34264928250.zip
Improved jumping gesture detection
Previously, when determining if the player had swiped upward for a jump in the Jump game mode, the game checked that the player had touched and moved upward a certain amount, with less than a certain amount of variance in horizontal position. However, this did not work well with the deeply-ingrained rotation aspect of the game, so the game was programmed to widen this allowed horizontal variance when the device was rotated. This really did not work too well, so now the game calculates an "expected" angle from the bottom of the screen based on rotation that it determines to point upward and also the angle of the player's swipe from the bottom of the screen. If the swipe angle falls within 45 degrees (π/4 radians) of the expected angle, the cart jumps. Really quite awesome if you ask me. :P

Refs #204
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