Guest User

Untitled

a guest
Dec 12th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  Level1.h
  3.  
  4. #import "CCNode.h"
  5. #import "cocos2d.h"
  6. @interface Level1 : CCScene {
  7. }
  8. @end
  9.  
  10. @interface Level1layer : CCLayer {
  11. }
  12. @end
  13.  
  14. //---------------------------------
  15.  
  16. //
  17. //  Level1.m
  18. //  tarkim
  19. //
  20. //  Created by Ignas on 12/11/12.
  21. //
  22. //
  23.  
  24. #import "Level1.h"
  25. #import "play2.h"
  26. #import "HelloWorldLayer.h"
  27. #import "SimpleAudioEngine.h"
  28. #import "CDAudioManager.h"
  29. #import "CocosDenshion.h"
  30. #import "play2.h"
  31. #import "yo.h"
  32. @implementation Level1
  33.  
  34. - (id)init
  35. {
  36.     if ((self = [super init]))
  37.     {
  38.         // All this scene does upon initialization is init & add the layer class
  39.         Level1layer *layer = [Level1layer node];
  40.         [self addChild:layer];
  41.     }
  42.     return self;
  43. }
  44.  
  45. - (void)dealloc
  46. {
  47.     // Nothing else to deallocate
  48.     [super dealloc];
  49. }
  50.  
  51.  
  52. @end
  53.  
  54. int skaiciuok = 0;
  55.  
  56. @implementation Level1layer
  57. CCSprite *debb;
  58. CCSprite *tree1;
  59. CCSprite *tree2;
  60. CCSprite *tree3;
  61. CCSprite *grass;
  62. CCSprite *lasas;
  63. CCSprite *hero;
  64. CCSprite *deb1_lyn;
  65. CCSprite *laistytuvas;
  66. CCSprite * selSprite;
  67. NSMutableArray * movableSprites;
  68. - (id)init
  69. {
  70.     if ((self = [super init]))
  71.     {
  72.  
  73.         [hero removeFromParentAndCleanup:YES];
  74.        
  75.         CGSize winSize = [[CCDirector sharedDirector] winSize];
  76.        
  77.         CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
  78.         background.position = ccp(winSize.width/2, winSize.height/2);
  79.         [self addChild:background];
  80.        
  81.         CGSize size = [[CCDirector sharedDirector] winSize];
  82.        
  83.        
  84.         CCLabelTTF *label = [CCLabelTTF labelWithString:@"Back" fontName:@"Helvetica" fontSize:20.0];
  85.        
  86.        
  87.         CCMenuItem *button = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(switchScene)];
  88.        
  89.        
  90.         CCMenu *menu = [CCMenu menuWithItems:button, nil];
  91.        
  92.        
  93.         [menu setPosition:ccp(size.width-40, size.height / 8)];
  94.         [self addChild:menu];
  95.        
  96.         movableSprites = [[NSMutableArray alloc] init];
  97.        
  98.        
  99.         NSArray *images = [NSArray arrayWithObjects:@"deb.png", @"deb2.png", nil];
  100.         for(int i = 0; i < images.count; ++i) {
  101.             NSString *image = [images objectAtIndex:i];
  102.             CCSprite *sprite = [CCSprite spriteWithFile:image];
  103.             float offsetFraction = ((float)(i+1))/(images.count+1);
  104.             sprite.position = ccp(winSize.width*offsetFraction, winSize.height-40);
  105.             [self addChild:sprite];
  106.             [movableSprites addObject:sprite];
  107.         }
  108.        
  109.        
  110.        
  111.         laistytuvas = [CCSprite spriteWithFile: @"laistytuvas.png"];
  112.         laistytuvas.position = ccp( 800, 400 );
  113.         [self addChild:laistytuvas];
  114.        
  115.         id act1 = [CCMoveBy actionWithDuration:0.7 position:ccp(-60, 0)];
  116.         [laistytuvas runAction: [CCRepeat actionWithAction:act1 times:4]];
  117.        
  118.        
  119.         [[CCEventDispatcher sharedDispatcher] addMouseDelegate:self priority:0];
  120.        
  121.         id seq = [CCSequence actions:
  122.                   [CCRotateTo actionWithDuration:1.0f angle:-10],
  123.                   [CCRotateTo actionWithDuration:1.0f angle:10],
  124.                   nil];
  125.        
  126.         deb1_lyn = [CCSprite spriteWithFile: @"deb_lyn_1.png"];
  127.         deb1_lyn.position = ccp( 130, 800 );
  128.         deb1_lyn.anchorPoint = ccp(0.5,0.9);
  129.         [self addChild:deb1_lyn];
  130.        
  131.         id act2 = [CCMoveBy actionWithDuration:0.9 position:ccp(0, -65)];
  132.         [deb1_lyn runAction: [CCRepeat actionWithAction:act2 times:4]];
  133.        
  134.         [self krutam];
  135.        
  136.         grass = [CCSprite spriteWithFile: @"grass2.png"];
  137.         grass.position = ccp( 330, 10 );
  138.         [self addChild:grass z:3];
  139.        
  140.         tree1 = [CCSprite spriteWithFile: @"tree_1.png"];
  141.         tree1.position = ccp( 510, 100 );
  142.         [self addChild:tree1 z:1];
  143.        
  144.         [laistytuvas runAction:[CCRepeatForever actionWithAction:seq]];
  145.        
  146.     }
  147.    
  148.     return self;
  149. }
  150.  
  151. - (void)selectSpriteForTouch:(CGPoint)location {
  152.     CCSprite * newSprite = nil;
  153.     for (CCSprite *sprite in movableSprites) {
  154.         if (CGRectContainsPoint(sprite.boundingBox, location)) {
  155.             newSprite = sprite;
  156.             [selSprite stopAllActions];
  157.             [[SimpleAudioEngine sharedEngine]playEffect:@"pew.caf"];
  158.             [selSprite runAction:[CCRotateTo actionWithDuration:0.1 angle:0]];
  159.             CCRotateTo * rotLeft = [CCRotateBy actionWithDuration:0.1 angle:-4.0];
  160.             CCRotateTo * rotCenter = [CCRotateBy actionWithDuration:0.1 angle:0.0];
  161.             CCRotateTo * rotRight = [CCRotateBy actionWithDuration:0.1 angle:4.0];
  162.             CCSequence * rotSeq = [CCSequence actions:rotLeft, rotCenter, rotRight, rotCenter, nil];
  163.             [newSprite runAction:[CCRepeatForever actionWithAction:rotSeq]];
  164.             selSprite = newSprite;
  165.         }
  166.     }
  167. }
  168.  
  169.  
  170. - (BOOL)ccMouseUp:(NSEvent*)event {
  171.     CGPoint clickLocation = [[CCDirector sharedDirector] convertEventToGL:event];
  172.     if (CGRectContainsPoint(laistytuvas.boundingBox, clickLocation)) {
  173.         id seq = [CCSequence actions:
  174.                   [CCRotateTo actionWithDuration:1.0f angle:-10],
  175.                   [CCRotateTo actionWithDuration:1.0f angle:10],
  176.                   nil];
  177.         [laistytuvas runAction:[CCRepeatForever actionWithAction:seq]];
  178.         [self unschedule:@selector(tick2:)];
  179.     }
  180.     return 0;
  181. }
  182.  
  183.  
  184. -(void) nykstam {
  185.     id suk = [CCSequence actions:
  186.               [CCRotateTo actionWithDuration:1.0f angle:30], nil];
  187.    
  188.     id pranyk = [CCMoveBy actionWithDuration:1.2f position:ccp(500, -20)];
  189.    
  190.    
  191.     [[SimpleAudioEngine sharedEngine]playEffect:@"hero_got_umbrella.caf"];
  192.    
  193.     id remove = [CCCallFunc actionWithTarget:self selector:@selector(ChangeScene:)];
  194.    
  195.     //  id okk =  [CCCallFuncND actionWithTarget:hero selector:@selector(removeFromParentAndCleanup:) data:(void*)YES];
  196.    
  197.     [hero stopAllActions];
  198.     [hero runAction:
  199.      [CCSequence actions:
  200.       suk, pranyk,remove,
  201.       nil]];
  202.    
  203.     NSLog(@"Nykstam");
  204. }
  205.  
  206. -(void) ChangeScene:(id)sender  {
  207.    
  208.     CCTransitionPageTurn *transition = [CCTransitionFade transitionWithDuration:1.0 scene:[yo node]];
  209.     // Tell the director to run the transition
  210.     [[CCDirector sharedDirector] replaceScene:transition];
  211.     // Tell the director to run the transition
  212.     //  [[CCDirector sharedDirector] replaceScene:transition];
  213.    
  214. }
  215.  
  216. - (BOOL)ccMouseDown:(NSEvent*)event {
  217.     CGPoint clickLocation = [[CCDirector sharedDirector] convertEventToGL:event];
  218.    
  219.     NSLog(@"paspaustas");
  220.    
  221.     if (CGRectContainsPoint(deb1_lyn.boundingBox, clickLocation)) {
  222.        
  223.         [self krutam];
  224.        
  225.     }
  226.     if (CGRectContainsPoint(hero.boundingBox, clickLocation)) {
  227.        
  228.         [self nykstam];
  229.        
  230.     }
  231.    
  232.     if (CGRectContainsPoint(laistytuvas.boundingBox, clickLocation)) {
  233.         NSLog(@"pot'as");
  234.        
  235.         [laistytuvas stopAllActions];
  236.         id suk = [CCSequence actions:
  237.                   [CCRotateTo actionWithDuration:1.0f angle:-30], nil];
  238.         [laistytuvas runAction:suk];
  239.         [self schedule: @selector(tick2:) interval:0.9];
  240.         [self lyn];
  241.     }
  242.    
  243.    
  244.     [self selectSpriteForTouch:clickLocation];
  245.     return 0;
  246. }
  247.  
  248. - (void)switchScene
  249. {
  250.     [[SimpleAudioEngine sharedEngine]playEffect:@"pew.caf"];
  251.     skaiciuok = 0;
  252.     [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
  253. }
  254.  
  255. -(void) onExit {
  256.     [[CCTextureCache sharedTextureCache] removeUnusedTextures];
  257. }
  258.  
  259. - (void)dealloc
  260. {
  261.     // Nothing else to deallocate
  262.     [super dealloc];
  263. }
  264.  
  265. @end
Advertisement
Add Comment
Please, Sign In to add comment