diff options
author | Starla Insigna <starla4444@gmail.com> | 2013-01-04 15:02:20 -0500 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2013-01-04 15:02:20 -0500 |
commit | 8123ad65be46e9b7243d3429dd083638eece0127 (patch) | |
tree | bf28c0bc7fad843dd124f75de951e5d165eb184e /Classes | |
parent | fe7ec5e55f609e628932c65d3f0bfe4948c9d023 (diff) | |
download | cartcollect-8123ad65be46e9b7243d3429dd083638eece0127.tar.gz cartcollect-8123ad65be46e9b7243d3429dd083638eece0127.tar.bz2 cartcollect-8123ad65be46e9b7243d3429dd083638eece0127.zip |
Made pausing easier
You can now pause by tapping in the top half of the screen in any mode that supports pausing. Closes #199
Diffstat (limited to 'Classes')
-rw-r--r-- | Classes/GameMode.h | 10 | ||||
-rw-r--r-- | Classes/GameMode.m | 60 | ||||
-rw-r--r-- | Classes/JumpGameMode.h | 4 | ||||
-rw-r--r-- | Classes/JumpGameMode.m | 19 |
4 files changed, 62 insertions, 31 deletions
diff --git a/Classes/GameMode.h b/Classes/GameMode.h index e208d49..ae3fbe5 100644 --- a/Classes/GameMode.h +++ b/Classes/GameMode.h | |||
@@ -15,7 +15,7 @@ | |||
15 | #define GAME_SCENE 436 | 15 | #define GAME_SCENE 436 |
16 | #define GAME_LAYER 437 | 16 | #define GAME_LAYER 437 |
17 | 17 | ||
18 | @interface GameMode : CCLayer <UIAlertViewDelegate, CartDelegate> { | 18 | @interface GameMode : CCLayer <UIAlertViewDelegate, CartDelegate, CCStandardTouchDelegate> { |
19 | NSMutableSet* objects; | 19 | NSMutableSet* objects; |
20 | int score; | 20 | int score; |
21 | int lives; | 21 | int lives; |
@@ -23,19 +23,23 @@ | |||
23 | Cart* cart; | 23 | Cart* cart; |
24 | FallingObjectFactory* objectFactory; | 24 | FallingObjectFactory* objectFactory; |
25 | 25 | ||
26 | CCLayerColor* willPauseLayer; | ||
26 | CCLayerColor* shadedLayer; | 27 | CCLayerColor* shadedLayer; |
27 | CCLayer* pauseLayer; | 28 | CCLayer* pauseLayer; |
29 | BOOL isPaused; | ||
30 | BOOL isPausing; | ||
28 | 31 | ||
29 | CCLabelBMFont* scoreLabel; | 32 | CCLabelBMFont* scoreLabel; |
30 | CCLabelBMFont* livesLabel; | 33 | CCLabelBMFont* livesLabel; |
31 | 34 | ||
32 | void (^delayedAction)(void); | 35 | void (^delayedAction)(void); |
33 | 36 | ||
34 | BOOL isPaused; | ||
35 | |||
36 | BOOL hasGyroscope; | 37 | BOOL hasGyroscope; |
37 | double pitch; | 38 | double pitch; |
38 | CMMotionManager* motionManager; | 39 | CMMotionManager* motionManager; |
40 | |||
41 | BOOL isGesturing; | ||
42 | CGPoint gestureStartPoint; | ||
39 | } | 43 | } |
40 | 44 | ||
41 | @property (readonly) Cart* cart; | 45 | @property (readonly) Cart* cart; |
diff --git a/Classes/GameMode.m b/Classes/GameMode.m index 49d0053..ca269cd 100644 --- a/Classes/GameMode.m +++ b/Classes/GameMode.m | |||
@@ -42,14 +42,6 @@ | |||
42 | 42 | ||
43 | objectFactory = [[FallingObjectFactory alloc] init]; | 43 | objectFactory = [[FallingObjectFactory alloc] init]; |
44 | 44 | ||
45 | if ([self canPause]) | ||
46 | { | ||
47 | CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(pause)]; | ||
48 | CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil]; | ||
49 | [pauseMenu setPosition:ccp(480-8-16, 320-8-16)]; | ||
50 | [self addChild:pauseMenu]; | ||
51 | } | ||
52 | |||
53 | isPaused = NO; | 45 | isPaused = NO; |
54 | 46 | ||
55 | Class cmClass = (NSClassFromString(@"CMMotionManager")); | 47 | Class cmClass = (NSClassFromString(@"CMMotionManager")); |
@@ -71,6 +63,8 @@ | |||
71 | isAccelerometerEnabled_ = YES; | 63 | isAccelerometerEnabled_ = YES; |
72 | hasGyroscope = NO; | 64 | hasGyroscope = NO; |
73 | } | 65 | } |
66 | |||
67 | self.isTouchEnabled = YES; | ||
74 | } | 68 | } |
75 | 69 | ||
76 | return self; | 70 | return self; |
@@ -262,6 +256,56 @@ | |||
262 | [cart deviceDidRotate:pitch]; | 256 | [cart deviceDidRotate:pitch]; |
263 | } | 257 | } |
264 | 258 | ||
259 | - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | ||
260 | { | ||
261 | if ((!isPaused) && (!isGesturing) && ([self canPause])) | ||
262 | { | ||
263 | UITouch* touch = [touches anyObject]; | ||
264 | gestureStartPoint = [touch locationInView:nil]; | ||
265 | isGesturing = YES; | ||
266 | |||
267 | if (gestureStartPoint.x > 160) | ||
268 | { | ||
269 | isPausing = YES; | ||
270 | |||
271 | willPauseLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 63) width:480 height:160]; | ||
272 | willPauseLayer.position = ccp(0, 160); | ||
273 | [[[CCDirector sharedDirector] runningScene] addChild:willPauseLayer]; | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | ||
279 | { | ||
280 | if (isGesturing && isPausing) | ||
281 | { | ||
282 | UITouch* touch = [touches anyObject]; | ||
283 | CGPoint gestureCurrentPosition = [touch locationInView:nil]; | ||
284 | CGFloat distance = sqrt(powf((gestureCurrentPosition.x - gestureStartPoint.x),2) + powf((gestureCurrentPosition.y - gestureStartPoint.y),2)); | ||
285 | |||
286 | if (distance > 2) | ||
287 | { | ||
288 | [[[CCDirector sharedDirector] runningScene] removeChild:willPauseLayer cleanup:YES]; | ||
289 | willPauseLayer = nil; | ||
290 | isPausing = NO; | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | ||
296 | { | ||
297 | if (isPausing) | ||
298 | { | ||
299 | [[[CCDirector sharedDirector] runningScene] removeChild:willPauseLayer cleanup:YES]; | ||
300 | willPauseLayer = nil; | ||
301 | isPausing = NO; | ||
302 | |||
303 | [self pause]; | ||
304 | } | ||
305 | |||
306 | isGesturing = NO; | ||
307 | } | ||
308 | |||
265 | - (void)dealloc | 309 | - (void)dealloc |
266 | { | 310 | { |
267 | [objects release]; | 311 | [objects release]; |
diff --git a/Classes/JumpGameMode.h b/Classes/JumpGameMode.h index b18fd5a..a09bbea 100644 --- a/Classes/JumpGameMode.h +++ b/Classes/JumpGameMode.h | |||
@@ -11,12 +11,10 @@ | |||
11 | 11 | ||
12 | @class LedgeFactory; | 12 | @class LedgeFactory; |
13 | 13 | ||
14 | @interface JumpGameMode : GameMode <CCStandardTouchDelegate, FallingObjectDelegate> { | 14 | @interface JumpGameMode : GameMode <FallingObjectDelegate> { |
15 | CCSprite* water; | 15 | CCSprite* water; |
16 | int waterTick; | 16 | int waterTick; |
17 | BOOL wave; | 17 | BOOL wave; |
18 | BOOL isGesturing; | ||
19 | CGPoint gestureStartPoint; | ||
20 | int jumpTick; | 18 | int jumpTick; |
21 | BOOL jump; | 19 | BOOL jump; |
22 | float expectedAngle; | 20 | float expectedAngle; |
diff --git a/Classes/JumpGameMode.m b/Classes/JumpGameMode.m index f3e690c..f0cb469 100644 --- a/Classes/JumpGameMode.m +++ b/Classes/JumpGameMode.m | |||
@@ -83,8 +83,6 @@ static GameModeInfo* info; | |||
83 | cart.falling = YES; | 83 | cart.falling = YES; |
84 | cart.delegate = self; | 84 | cart.delegate = self; |
85 | 85 | ||
86 | self.isTouchEnabled = YES; | ||
87 | |||
88 | waterTick = 0; | 86 | waterTick = 0; |
89 | wave = NO; | 87 | wave = NO; |
90 | 88 | ||
@@ -279,18 +277,10 @@ static GameModeInfo* info; | |||
279 | } | 277 | } |
280 | } | 278 | } |
281 | 279 | ||
282 | - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | ||
283 | { | ||
284 | if ((!isPaused) && (!isGesturing)) | ||
285 | { | ||
286 | UITouch* touch = [touches anyObject]; | ||
287 | gestureStartPoint = [touch locationInView:nil]; | ||
288 | isGesturing = YES; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event | 280 | - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event |
293 | { | 281 | { |
282 | [super ccTouchesMoved:touches withEvent:event]; | ||
283 | |||
294 | if (isGesturing) | 284 | if (isGesturing) |
295 | { | 285 | { |
296 | UITouch* touch = [touches anyObject]; | 286 | UITouch* touch = [touches anyObject]; |
@@ -306,11 +296,6 @@ static GameModeInfo* info; | |||
306 | } | 296 | } |
307 | } | 297 | } |
308 | 298 | ||
309 | - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | ||
310 | { | ||
311 | isGesturing = NO; | ||
312 | } | ||
313 | |||
314 | - (int)cartShouldFall:(Cart *)m_cart | 299 | - (int)cartShouldFall:(Cart *)m_cart |
315 | { | 300 | { |
316 | int bottom = 0-m_cart.sprite.boundingBox.size.height/2; | 301 | int bottom = 0-m_cart.sprite.boundingBox.size.height/2; |