summary refs log tree commit diff stats
path: root/Classes/GameLayer.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-07 10:04:54 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-07 10:04:54 -0400
commit1d9ed882de4e2e3a53cdd5e90edc25e8ae10af1b (patch)
tree4a8f7445cf57b4de4295f81ff0a70c6b5f49c978 /Classes/GameLayer.m
parent0a8fed12704bf343ad9604f964b71b3f50495382 (diff)
downloadcartcollect-1d9ed882de4e2e3a53cdd5e90edc25e8ae10af1b.tar.gz
cartcollect-1d9ed882de4e2e3a53cdd5e90edc25e8ae10af1b.tar.bz2
cartcollect-1d9ed882de4e2e3a53cdd5e90edc25e8ae10af1b.zip
Implemented tutorial bubbles
GameLayer now has support for pausing game flow and displaying a tutorial bubble that the user can tap to dismiss. No code has been written, however, to make use of this, because I think it may be simpler to abstract GameLayer out somewhat and create a separate game mode for the tutorial. Deliberation required.

PauseLayer has also been removed and the behavior has been brought into GameLayer.

Refs #193
Diffstat (limited to 'Classes/GameLayer.m')
-rwxr-xr-xClasses/GameLayer.m84
1 files changed, 79 insertions, 5 deletions
diff --git a/Classes/GameLayer.m b/Classes/GameLayer.m index 32ca483..2ec8ef5 100755 --- a/Classes/GameLayer.m +++ b/Classes/GameLayer.m
@@ -11,6 +11,8 @@
11 11
12@implementation GameLayer 12@implementation GameLayer
13 13
14@synthesize currentTutorial;
15
14+ (CCScene*)scene 16+ (CCScene*)scene
15{ 17{
16 CCScene* scene = [CCScene node]; 18 CCScene* scene = [CCScene node];
@@ -19,9 +21,10 @@
19 [scene addChild:backgroundLayer]; 21 [scene addChild:backgroundLayer];
20 22
21 GameLayer* layer = [GameLayer node]; 23 GameLayer* layer = [GameLayer node];
24 layer.tag = GAME_LAYER;
22 [scene addChild:layer]; 25 [scene addChild:layer];
23 26
24 scene.tag = 436; 27 scene.tag = GAME_SCENE;
25 28
26 return scene; 29 return scene;
27} 30}
@@ -266,13 +269,13 @@
266 return self; 269 return self;
267} 270}
268 271
269-(void) onEnter 272- (void)onEnter
270{ 273{
271 [super onEnter]; 274 [super onEnter];
272 275
273 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; 276 [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)];
274 [self schedule:@selector(tick:) interval:1.0f/60.0f]; 277 [self schedule:@selector(tick:) interval:1.0f/60.0f];
275 [self schedule:@selector(randomlyAddObject:) interval:addSpeed]; 278 [self schedule:@selector(randomlyAddObject:) interval:addSpeed];
276} 279}
277 280
278- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration 281- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
@@ -295,7 +298,78 @@
295 298
296- (void)pause 299- (void)pause
297{ 300{
298 [[CCDirector sharedDirector] replaceScene:[PauseLayer sceneWithScene:[[CCDirector sharedDirector] runningScene]]]; 301 if (self.currentTutorial != nil)
302 {
303 [self.currentTutorial removeFromSuperview];
304 }
305
306 [self pauseSchedulerAndActions];
307
308 shadedLayer = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 127)];
309 [[[CCDirector sharedDirector] runningScene] addChild:shadedLayer];
310
311 pauseLayer = [CCLayer node];
312 CCLabelBMFont* scoreLabel2 = [CCLabelBMFont labelWithString:@"PAUSE" fntFile:@"helvetica.fnt"];
313 scoreLabel2.position = ccp(240,90);
314 [pauseLayer addChild:scoreLabel2];
315
316 CCMenuItemImage* pauseButton = [CCMenuItemImage itemFromNormalImage:@"pause2.png" selectedImage:@"pause.png" target:self selector:@selector(unpause)];
317 CCMenu* pauseMenu = [CCMenu menuWithItems:pauseButton, nil];
318 [pauseMenu setPosition:ccp(480-8-16, 320-8-16)];
319 [pauseLayer addChild:pauseMenu];
320
321 CCMenuItemImage* newgameMenuItem = [CCMenuItemImage itemFromNormalImage:@"back.png" selectedImage:@"back2.png" target:self selector:@selector(mainmenu)];
322 CCMenu* myMenu = [CCMenu menuWithItems:newgameMenuItem, nil];
323 myMenu.position = ccp(240, 60);
324 [pauseLayer addChild:myMenu];
325
326 [[[CCDirector sharedDirector] runningScene] addChild:pauseLayer];
327}
328
329- (void)unpause
330{
331 [[[CCDirector sharedDirector] runningScene] removeChild:shadedLayer cleanup:YES];
332 [[[CCDirector sharedDirector] runningScene] removeChild:pauseLayer cleanup:YES];
333
334 shadedLayer = nil;
335 pauseLayer = nil;
336
337 if (self.currentTutorial != nil)
338 {
339 [[[CCDirector sharedDirector] openGLView] addSubview:self.currentTutorial];
340 } else {
341 [self resumeSchedulerAndActions];
342 }
343}
344
345- (void)mainmenu
346{
347 [[CCDirector sharedDirector] replaceScene:[MainMenuLayer scene]];
348}
349
350- (void)setCurrentTutorial:(TutorialBubble *)m_currentTutorial
351{
352 @synchronized(self)
353 {
354 if (currentTutorial != m_currentTutorial)
355 {
356 [currentTutorial release];
357 currentTutorial = [m_currentTutorial retain];
358 }
359 }
360
361 if (currentTutorial != nil)
362 {
363 [currentTutorial setTarget:self action:@selector(endTutorial)];
364 [[[CCDirector sharedDirector] openGLView] addSubview:currentTutorial];
365 [self pauseSchedulerAndActions];
366 }
367}
368
369- (void)endTutorial
370{
371 self.currentTutorial = nil;
372 [self resumeSchedulerAndActions];
299} 373}
300 374
301@end 375@end