diff options
Diffstat (limited to 'Classes/JumpGameMode.m')
-rw-r--r-- | Classes/JumpGameMode.m | 32 |
1 files changed, 22 insertions, 10 deletions
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 @@ | |||
189 | 189 | ||
190 | - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | 190 | - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event |
191 | { | 191 | { |
192 | UITouch* touch = [touches anyObject]; | 192 | if ((!isPaused) && (!isGesturing)) |
193 | gestureStartPoint = [touch locationInView:nil]; | 193 | { |
194 | UITouch* touch = [touches anyObject]; | ||
195 | gestureStartPoint = [touch locationInView:nil]; | ||
196 | isGesturing = YES; | ||
197 | } | ||
194 | } | 198 | } |
195 | 199 | ||
196 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | 200 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event |
197 | { | 201 | { |
198 | UITouch* touch = [touches anyObject]; | 202 | if (isGesturing) |
199 | CGPoint gestureCurrentPosition = [touch locationInView:nil]; | ||
200 | CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); | ||
201 | CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); | ||
202 | |||
203 | if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && ((cart.sprite.position.y >= 80) && (cart.sprite.position.y <= 90))) | ||
204 | { | 203 | { |
205 | jump = YES; | 204 | UITouch* touch = [touches anyObject]; |
206 | cart.falling = NO; | 205 | CGPoint gestureCurrentPosition = [touch locationInView:nil]; |
206 | CGFloat angle = atan2f(gestureCurrentPosition.y - gestureStartPoint.y, gestureCurrentPosition.x - gestureStartPoint.x); | ||
207 | CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); | ||
208 | |||
209 | if ((distance >= kMinimumGestureLength) && (angle >= expectedAngle - M_PI_4) && (angle <= expectedAngle + M_PI_4) && ((cart.sprite.position.y >= 80) && (cart.sprite.position.y <= 90))) | ||
210 | { | ||
211 | jump = YES; | ||
212 | cart.falling = NO; | ||
213 | } | ||
207 | } | 214 | } |
208 | } | 215 | } |
209 | 216 | ||
217 | - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | ||
218 | { | ||
219 | isGesturing = NO; | ||
220 | } | ||
221 | |||
210 | - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration | 222 | - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration |
211 | { | 223 | { |
212 | [super accelerometer:accelerometer didAccelerate:acceleration]; | 224 | [super accelerometer:accelerometer didAccelerate:acceleration]; |