Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Level1.h
- #import "CCNode.h"
- #import "cocos2d.h"
- @interface Level1 : CCScene {
- }
- @end
- @interface Level1layer : CCLayer {
- }
- @end
- //---------------------------------
- //
- // Level1.m
- // tarkim
- //
- // Created by Ignas on 12/11/12.
- //
- //
- #import "Level1.h"
- #import "play2.h"
- #import "HelloWorldLayer.h"
- #import "SimpleAudioEngine.h"
- #import "CDAudioManager.h"
- #import "CocosDenshion.h"
- #import "play2.h"
- #import "yo.h"
- @implementation Level1
- - (id)init
- {
- if ((self = [super init]))
- {
- // All this scene does upon initialization is init & add the layer class
- Level1layer *layer = [Level1layer node];
- [self addChild:layer];
- }
- return self;
- }
- - (void)dealloc
- {
- // Nothing else to deallocate
- [super dealloc];
- }
- @end
- int skaiciuok = 0;
- @implementation Level1layer
- CCSprite *debb;
- CCSprite *tree1;
- CCSprite *tree2;
- CCSprite *tree3;
- CCSprite *grass;
- CCSprite *lasas;
- CCSprite *hero;
- CCSprite *deb1_lyn;
- CCSprite *laistytuvas;
- CCSprite * selSprite;
- NSMutableArray * movableSprites;
- - (id)init
- {
- if ((self = [super init]))
- {
- [hero removeFromParentAndCleanup:YES];
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
- background.position = ccp(winSize.width/2, winSize.height/2);
- [self addChild:background];
- CGSize size = [[CCDirector sharedDirector] winSize];
- CCLabelTTF *label = [CCLabelTTF labelWithString:@"Back" fontName:@"Helvetica" fontSize:20.0];
- CCMenuItem *button = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(switchScene)];
- CCMenu *menu = [CCMenu menuWithItems:button, nil];
- [menu setPosition:ccp(size.width-40, size.height / 8)];
- [self addChild:menu];
- movableSprites = [[NSMutableArray alloc] init];
- NSArray *images = [NSArray arrayWithObjects:@"deb.png", @"deb2.png", nil];
- for(int i = 0; i < images.count; ++i) {
- NSString *image = [images objectAtIndex:i];
- CCSprite *sprite = [CCSprite spriteWithFile:image];
- float offsetFraction = ((float)(i+1))/(images.count+1);
- sprite.position = ccp(winSize.width*offsetFraction, winSize.height-40);
- [self addChild:sprite];
- [movableSprites addObject:sprite];
- }
- laistytuvas = [CCSprite spriteWithFile: @"laistytuvas.png"];
- laistytuvas.position = ccp( 800, 400 );
- [self addChild:laistytuvas];
- id act1 = [CCMoveBy actionWithDuration:0.7 position:ccp(-60, 0)];
- [laistytuvas runAction: [CCRepeat actionWithAction:act1 times:4]];
- [[CCEventDispatcher sharedDispatcher] addMouseDelegate:self priority:0];
- id seq = [CCSequence actions:
- [CCRotateTo actionWithDuration:1.0f angle:-10],
- [CCRotateTo actionWithDuration:1.0f angle:10],
- nil];
- deb1_lyn = [CCSprite spriteWithFile: @"deb_lyn_1.png"];
- deb1_lyn.position = ccp( 130, 800 );
- deb1_lyn.anchorPoint = ccp(0.5,0.9);
- [self addChild:deb1_lyn];
- id act2 = [CCMoveBy actionWithDuration:0.9 position:ccp(0, -65)];
- [deb1_lyn runAction: [CCRepeat actionWithAction:act2 times:4]];
- [self krutam];
- grass = [CCSprite spriteWithFile: @"grass2.png"];
- grass.position = ccp( 330, 10 );
- [self addChild:grass z:3];
- tree1 = [CCSprite spriteWithFile: @"tree_1.png"];
- tree1.position = ccp( 510, 100 );
- [self addChild:tree1 z:1];
- [laistytuvas runAction:[CCRepeatForever actionWithAction:seq]];
- }
- return self;
- }
- - (void)selectSpriteForTouch:(CGPoint)location {
- CCSprite * newSprite = nil;
- for (CCSprite *sprite in movableSprites) {
- if (CGRectContainsPoint(sprite.boundingBox, location)) {
- newSprite = sprite;
- [selSprite stopAllActions];
- [[SimpleAudioEngine sharedEngine]playEffect:@"pew.caf"];
- [selSprite runAction:[CCRotateTo actionWithDuration:0.1 angle:0]];
- CCRotateTo * rotLeft = [CCRotateBy actionWithDuration:0.1 angle:-4.0];
- CCRotateTo * rotCenter = [CCRotateBy actionWithDuration:0.1 angle:0.0];
- CCRotateTo * rotRight = [CCRotateBy actionWithDuration:0.1 angle:4.0];
- CCSequence * rotSeq = [CCSequence actions:rotLeft, rotCenter, rotRight, rotCenter, nil];
- [newSprite runAction:[CCRepeatForever actionWithAction:rotSeq]];
- selSprite = newSprite;
- }
- }
- }
- - (BOOL)ccMouseUp:(NSEvent*)event {
- CGPoint clickLocation = [[CCDirector sharedDirector] convertEventToGL:event];
- if (CGRectContainsPoint(laistytuvas.boundingBox, clickLocation)) {
- id seq = [CCSequence actions:
- [CCRotateTo actionWithDuration:1.0f angle:-10],
- [CCRotateTo actionWithDuration:1.0f angle:10],
- nil];
- [laistytuvas runAction:[CCRepeatForever actionWithAction:seq]];
- [self unschedule:@selector(tick2:)];
- }
- return 0;
- }
- -(void) nykstam {
- id suk = [CCSequence actions:
- [CCRotateTo actionWithDuration:1.0f angle:30], nil];
- id pranyk = [CCMoveBy actionWithDuration:1.2f position:ccp(500, -20)];
- [[SimpleAudioEngine sharedEngine]playEffect:@"hero_got_umbrella.caf"];
- id remove = [CCCallFunc actionWithTarget:self selector:@selector(ChangeScene:)];
- // id okk = [CCCallFuncND actionWithTarget:hero selector:@selector(removeFromParentAndCleanup:) data:(void*)YES];
- [hero stopAllActions];
- [hero runAction:
- [CCSequence actions:
- suk, pranyk,remove,
- nil]];
- NSLog(@"Nykstam");
- }
- -(void) ChangeScene:(id)sender {
- CCTransitionPageTurn *transition = [CCTransitionFade transitionWithDuration:1.0 scene:[yo node]];
- // Tell the director to run the transition
- [[CCDirector sharedDirector] replaceScene:transition];
- // Tell the director to run the transition
- // [[CCDirector sharedDirector] replaceScene:transition];
- }
- - (BOOL)ccMouseDown:(NSEvent*)event {
- CGPoint clickLocation = [[CCDirector sharedDirector] convertEventToGL:event];
- NSLog(@"paspaustas");
- if (CGRectContainsPoint(deb1_lyn.boundingBox, clickLocation)) {
- [self krutam];
- }
- if (CGRectContainsPoint(hero.boundingBox, clickLocation)) {
- [self nykstam];
- }
- if (CGRectContainsPoint(laistytuvas.boundingBox, clickLocation)) {
- NSLog(@"pot'as");
- [laistytuvas stopAllActions];
- id suk = [CCSequence actions:
- [CCRotateTo actionWithDuration:1.0f angle:-30], nil];
- [laistytuvas runAction:suk];
- [self schedule: @selector(tick2:) interval:0.9];
- [self lyn];
- }
- [self selectSpriteForTouch:clickLocation];
- return 0;
- }
- - (void)switchScene
- {
- [[SimpleAudioEngine sharedEngine]playEffect:@"pew.caf"];
- skaiciuok = 0;
- [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
- }
- -(void) onExit {
- [[CCTextureCache sharedTextureCache] removeUnusedTextures];
- }
- - (void)dealloc
- {
- // Nothing else to deallocate
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment