Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  MainMenuLayer.m
  3. //  BalanceIt
  4. //
  5. //  Created by SquirrelStudios on 16.05.10.
  6. //  Copyright 2010 Squirrel Studios. All rights reserved.
  7. //
  8.  
  9. #import "MainMenuLayer.h"
  10. #import "BalanceItAppDelegate.h"
  11. #import "SimpleAudioEngine.h"
  12. #import "TouchableSprite.h"
  13.  
  14. @interface MainMenuLayer (Private)
  15.  
  16. CCSprite *touchMeSprite_;
  17. CCSprite *logoSprite_;
  18. CCMenu *mnuMain_;
  19.  
  20. - (void) goItemSelected:(id) sender;
  21. - (void) highScoreItemSelected:(id) sender;
  22. - (void) creditsItemSelected:(id) sender;
  23. - (void) fadeTouchMeItem:(CCNode *)node;
  24.  
  25. @end
  26.  
  27. @implementation MainMenuLayer
  28.  
  29. + (CCScene *) scene {
  30.     MainMenuLayer *layer = [MainMenuLayer node];
  31.     CCScene *scene = [CCScene node];
  32.     [scene addChild:layer];
  33.    
  34.     return scene;  
  35. }
  36.  
  37. -(id) init {
  38.    
  39.     if(!(self=[super init] ))
  40.         return self;
  41.  
  42.     CGSize winSize = [[CCDirector sharedDirector] winSize];
  43.     self.isTouchEnabled = YES;
  44.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  45.  
  46.     // background sprite
  47.     CCSprite *bgSprite  = [CCSprite spriteWithFile:@"bg_1.png"];
  48.     bgSprite.position = ccp(0, 0);
  49.     bgSprite.anchorPoint = ccp(0, 0);
  50.     [self addChild:bgSprite];
  51.     // background sprite end
  52.    
  53.     // touchme sprite
  54.     if (app.splashed == NO) {
  55.         touchMeSprite_ = [CCSprite spriteWithFile:@"touchme.png"];
  56.         touchMeSprite_.position = ccp(winSize.width /2, 50);
  57.         touchMeSprite_.opacity = 0;
  58.         [self addChild:touchMeSprite_];
  59.         [touchMeSprite_ runAction:[CCSequence actions:
  60.                                [CCDelayTime actionWithDuration:3],
  61.                                [CCFadeTo actionWithDuration:1 opacity:255],
  62.                                [CCCallFuncN actionWithTarget:self selector:@selector(fadeTouchMeItem:)],
  63.                                nil]];
  64.     }
  65.     else {
  66.         touchMeSprite_ = nil;
  67.     }
  68.     // touchme sprite end
  69.    
  70.     // logo sprite 
  71.     logoSprite_ = [CCSprite spriteWithFile:@"logo.png"];
  72.     if (app.splashed == NO)
  73.         [logoSprite_ setPosition:ccp(winSize.width /2 , winSize.height /2 )];
  74.     else
  75.         [logoSprite_ setPosition:ccp(winSize.width /2 , winSize.height /2 + 70 )];
  76.    
  77.     [self addChild:logoSprite_];
  78.     // logo sprite end
  79.    
  80.     // menu
  81.     CCMenuItem *goItem = [CCMenuItemImage
  82.                                 itemFromNormalImage:@"go.png"
  83.                                 selectedImage:@"go.png"
  84.                                 target:self
  85.                                 selector:@selector(goItemSelected:)];
  86.     goItem.position = ccp(0,0);    
  87.    
  88.     CCMenuItem *highscoreItem = [CCMenuItemImage
  89.                                itemFromNormalImage:@"highscore.png"
  90.                                selectedImage:@"highscore.png"
  91.                                target:self selector:@selector(highScoreItemSelected:)];
  92.     highscoreItem.position = ccp(-100,-90);
  93.  
  94.    
  95.     CCMenuItem *creditsItem = [CCMenuItemImage
  96.                                 itemFromNormalImage:@"credits.png"
  97.                                 selectedImage:@"credits.png"
  98.                                 target:self selector:@selector(creditsItemSelected:)];
  99.     creditsItem.position = ccp(130,-85);
  100.        
  101.     mnuMain_ = [CCMenu menuWithItems:goItem, highscoreItem, creditsItem, nil];
  102.     if (app.splashed == NO)
  103.         mnuMain_.position = ccp(winSize.width /2 , -40);
  104.     else
  105.         mnuMain_.position = ccp(winSize.width /2 , 130);
  106.    
  107.     [self addChild:mnuMain_];
  108.     // menu end
  109.    
  110.    
  111.     NSLog(@"MainMenuLayer allocated");
  112.    
  113.     return self;
  114. }
  115.  
  116. - (void) fadeTouchMeItem:(CCNode *)node
  117. {
  118.     [node runAction:[CCRepeatForever actionWithAction:
  119.                       [CCSequence actions:
  120.                        [CCFadeTo actionWithDuration:0.5 opacity:100],
  121.                        [CCFadeTo actionWithDuration:0.5 opacity:255],
  122.                        nil]]];
  123. }
  124.  
  125. - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  126.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  127.  
  128.     if (app.splashed == NO) {
  129.         [logoSprite_ runAction:[CCMoveBy actionWithDuration:0.2 position:ccp(0, -5)]];
  130.         [touchMeSprite_ stopAllActions];    
  131.         [touchMeSprite_ runAction:[CCFadeTo actionWithDuration:0.2 opacity:0]];
  132.     }  
  133.    
  134.     /*
  135.     UITouch *touch = [touches anyObject];
  136.     CGPoint location = [touch locationInView:[touch view]];
  137.     location = [[CCDirector sharedDirector] convertToGL:location];
  138.      */
  139. }
  140.  
  141. - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  142.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  143.  
  144.     if (app.splashed == NO) {
  145.         self.isTouchEnabled = NO;
  146.         [logoSprite_ runAction:[CCMoveTo actionWithDuration:0.5 position:ccp(logoSprite_.position.x, logoSprite_.position.y + 70)]];
  147.         [mnuMain_ runAction:[CCMoveTo actionWithDuration:0.5 position:ccp(mnuMain_.position.x, 130)]];
  148.         app.splashed = YES;
  149.     }
  150. }
  151.  
  152. - (void) goItemSelected:(id) sender {
  153.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  154.     [app runCharacterSelectionScene];
  155. }
  156.  
  157. - (void) creditsItemSelected:(id) sender {
  158.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  159.     [app runCreditsScene];  
  160. }
  161.  
  162. - (void) highScoreItemSelected:(id) sender {
  163.     BalanceItAppDelegate *app = [[UIApplication sharedApplication] delegate];
  164.     [app runCreditsScene];  
  165. }
  166.  
  167. - (void) dealloc {
  168.     [super dealloc];
  169.    
  170.     NSLog(@"MainMenuLayer deallocated");
  171. }
  172.  
  173. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement