diff options
Diffstat (limited to 'Classes')
-rw-r--r-- | Classes/JumpGameMode.h | 1 | ||||
-rw-r--r-- | 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 @@ | |||
14 | CCSprite* water; | 14 | CCSprite* water; |
15 | int waterTick; | 15 | int waterTick; |
16 | BOOL wave; | 16 | BOOL wave; |
17 | BOOL isGesturing; | ||
17 | CGPoint gestureStartPoint; | 18 | CGPoint gestureStartPoint; |
18 | int jumpTick; | 19 | int jumpTick; |
19 | BOOL jump; | 20 | 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 @@ | |||
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]; |