diff options
Diffstat (limited to 'Classes/GameMode.m')
-rw-r--r-- | Classes/GameMode.m | 60 |
1 files changed, 52 insertions, 8 deletions
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]; |