Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  Digger.m
  3. //  TestCoco.s
  4. //
  5. //  Created by Developer on 18/05/09.
  6. //  Copyright 2009 Retina Softwares All rights reserved.
  7. //
  8.  
  9. #import "Digger.h"
  10. #import "LevelInfo.h"
  11. #import "GameScene.h"
  12. #import "MenuScene.h"
  13.  
  14. @implementation Digger
  15. //@synthesize audioPlayer;
  16. @synthesize bCollide;
  17. @synthesize heroScore;
  18. @synthesize backgroundMusic;
  19. @synthesize tilemap1;
  20. @synthesize tileInfo;
  21. @synthesize hasCarrot;
  22. @synthesize stopMoving;
  23. @synthesize heroPos;
  24. @synthesize mDir;
  25. @synthesize mPreDir;
  26. @synthesize level;
  27. @synthesize bag;
  28. @synthesize enemyCount;
  29. //@synthesize bLife;
  30. @synthesize bagCount;
  31. @synthesize gemCount;
  32. @synthesize carrotCount;
  33. @synthesize heroLife;
  34.  
  35. -(id)init
  36. {
  37.    
  38.     NSLog(@"digger init................");
  39.    
  40.     //heroLife=3;
  41.     if(self != nil)
  42.     {
  43.         NSLog(@"digger init................");
  44.     }
  45.     level=1;
  46.     self = [super init];
  47.     return self;
  48. }
  49. -(void)startMusic
  50. {
  51.     //return;
  52.    
  53.     backgroundMusic = [[Sound alloc] initWithSound:@"Dance_01" ofType:@"mp3"];
  54.     [backgroundMusic setRepeat:YES];
  55.     [backgroundMusic playIt];
  56.    
  57.     backgroundMusicWithCarrot = [[Sound alloc] initWithSound:@"Dance_04" ofType:@"mp3"];
  58.     [backgroundMusicWithCarrot setRepeat:YES];
  59.    
  60. //  ` = [[Sound alloc] initWithSound:@"Bell_07" ofType:@"mp3"];
  61. //  heroDeadSound = [[Sound alloc] initWithSound:@"hero_death" ofType:@"mp3"];
  62.    
  63.     path1=[[NSBundle mainBundle] pathForResource:@"hero_death" ofType:@"mp3"];
  64.     AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path1], &soundID2);
  65.    
  66.     /*NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@"Dance_01"  ofType:@"mp3"];
  67.      
  68.      audioPlayer =  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];
  69.      
  70.      [audioPlayer setDelegate:self];
  71.      
  72.      [audioPlayer prepareToPlay];
  73.      //[audioPlayer play];
  74.      [audioPlayer setNumberOfLoops:-1];
  75.      */
  76.    
  77.     // Some sound initialization is also done here
  78.    
  79.     path2=[[NSBundle mainBundle] pathForResource:@"Bell_07" ofType:@"mp3"];
  80.    
  81.     AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path2], &soundID1);
  82.    
  83.    
  84.    
  85. }
  86.  
  87.  
  88. -(void)startJoystick
  89. {
  90.     //Coding for the joystick
  91.    
  92. /*  MenuItem *item1 = [MenuItemImage itemFromNormalImage:@"arrowUP.png" selectedImage:@"arrowUP.png"
  93.                                                   target:self selector:@selector(willMoveUp:)];
  94.     item1.scale=0.4;
  95.     item1.position = ccp(-16, -190);
  96.    
  97.    
  98.     MenuItem *item2 = [MenuItemImage itemFromNormalImage:@"arrowDOWN.png" selectedImage:@"arrowDOWN.png"
  99.                                                   target:self selector:@selector(willMoveDown:)];
  100.     item2.scale=0.4;
  101.     item2.position = ccp(-16, -225);
  102.    
  103.    
  104.     MenuItem *item3 = [MenuItemImage itemFromNormalImage:@"arrowRIGHT.png" selectedImage:@"arrowRIGHT.png"
  105.                                                   target:self selector:@selector(willMoveRight:)];
  106.     item3.scale=0.4;
  107.     item3.position = ccp(16, -210);
  108.    
  109.    
  110.     MenuItem *item4 = [MenuItemImage itemFromNormalImage:@"arrowLEFT.png" selectedImage:@"arrowLEFT.png"
  111.                                                   target:self selector:@selector(willMoveLeft:)];
  112.     item4.scale=0.4;
  113.     item4.position = ccp(-48, -210);
  114.    
  115.     Menu *menu = [Menu menuWithItems: item1, item2, item3, item4, nil];
  116.    
  117.     [[self parent] addChild: menu z:2];
  118.     */
  119.    
  120.  
  121. }
  122.  
  123. //It will check if the digger can move from frompos to topos
  124.  
  125. -(BOOL)canMoveFrom:(CGPoint)frompos to:(CGPoint)topos inMap:(TileMapAtlas*)map
  126. {
  127.     /*For both cordinates divisible by 32,the position of digger is at the orgin of the tile. So we
  128.      have to shift it to make the digger move.*/
  129.     tileInfo = [[NSString alloc] init];
  130.    
  131.     if ([[NSNumber numberWithFloat: topos.x] intValue ]% 32==0 && [[NSNumber numberWithFloat: topos.y] intValue ]% 32==0)
  132.     {
  133.         if([mDir isEqualToString:@"UP"])
  134.         {
  135.             if([mPreDir isEqualToString:@"LEFT"])
  136.             {
  137.                 int e = (topos.x-32)/32;
  138.                 int f = (topos.y-32)/32-2;
  139.                 topos.x=topos.x-16;
  140.                 topos.y=topos.y-16;
  141.                 ccRGBB s=[map tileAt:ccg(e,f)];
  142.                 if(s.r==15 || s.r==5 || s.r == 6)
  143.                 {
  144.                     s.r=24;
  145.                 }
  146.                 else if(s.r==21)
  147.                 {
  148.                     s.r=9;
  149.                 }
  150.                 else
  151.                 {
  152.                     s.r=3;
  153.                 }
  154.                 [map setTile:s at:ccg(e,f)];
  155.                 //[self emitParticles:[self position]];
  156.             }
  157.             else if([mPreDir isEqualToString:@"RIGHT"])
  158.             {
  159.                 int e = (topos.x)/32;
  160.                 int f = (topos.y-32)/32-2;
  161.                 topos.x=topos.x+16;
  162.                 topos.y=topos.y-16;
  163.                 ccRGBB s=[map tileAt:ccg(e,f)];
  164.                 if(s.r==15 || s.r==7|| s.r==20)
  165.                 {
  166.                 s.r=25;
  167.                 }
  168.                 else if(s.r==21)
  169.                 {
  170.                     s.r=9;
  171.                
  172.                 }
  173.                 else
  174.                 {
  175.                     s.r=3;
  176.                 }
  177.                    
  178.                 //[self emitParticles:[self position]];
  179.                
  180.                 [map setTile:s at:ccg(e,f)];
  181.             }
  182.             //[self emitParticles:[self position]];
  183.            
  184.             [self runAction:[MoveTo actionWithDuration:0.3 position:ccp(topos.x,topos.y)]];
  185.             [self setHeroPos:ccp(topos.x,topos.y)];
  186.             [self checkingDiamond:topos];
  187.         }
  188.         else if([mDir isEqualToString:@"DOWN"])
  189.         {
  190.             if([mPreDir isEqualToString:@"LEFT"])
  191.             {
  192.                 int e = (topos.x-32)/32;
  193.                 int f = (topos.y)/32-2;
  194.                 ccRGBB s=[map tileAt:ccg(e,f)];
  195.                 if(s.r==15 || s.r== 5||s.r==6)
  196.                 {
  197.                     s.r=11;
  198.                 }
  199.                 else if( s.r==21)
  200.                 {
  201.                     s.r=23;
  202.                 }
  203.                 else
  204.                 {
  205.                     s.r=3;
  206.                 }
  207.                 [map setTile:s at:ccg(e,f)];
  208.                 //[self emitParticles:[self position]];
  209.                
  210.                 topos.x=topos.x-16;
  211.                 topos.y=topos.y+16;
  212.             }
  213.             else if([mPreDir isEqualToString:@"RIGHT"])
  214.             {
  215.                 int e = (topos.x)/32;
  216.                 int f = (topos.y)/32-2;
  217.                 ccRGBB s=[map tileAt:ccg(e,f)];
  218.                 if(s.r==15 || s.r==7 || s.r==20)
  219.                 {
  220.                 s.r=12;
  221.                 }
  222.                 else if(s.r==21)
  223.                 {
  224.                     s.r=23;
  225.                
  226.                 }
  227.                 else
  228.                 {
  229.                     s.r=3;
  230.                 }
  231.                 [map setTile:s at:ccg(e,f)];
  232.                 topos.x=topos.x+16;
  233.                 topos.y=topos.y+16;
  234.                 //              [self emitParticles:[self position]];
  235.                
  236.             }
  237.             //[self emitParticles:[self position]];
  238.            
  239.             [self runAction:[MoveTo actionWithDuration:0.3 position:ccp(topos.x,topos.y)]];
  240.             [self setHeroPos:ccp(topos.x,topos.y)];
  241.             [self checkingDiamond:topos];
  242.         }
  243.         else if([mDir isEqualToString:@"LEFT"])
  244.         {
  245.             if([mPreDir isEqualToString:@"UP"])
  246.             {
  247.                 int e = (topos.x)/32;
  248.                 int f = (topos.y)/32-2;
  249.                 ccRGBB s=[map tileAt:ccg(e,f)];
  250.                 if(s.r==15 || s.r==16||s.r==17)
  251.                 {
  252.                 s.r=12;
  253.                 }
  254.                 else if(s.r==4)
  255.                 {
  256.                     s.r=9;
  257.                 }
  258.                 else
  259.                 {
  260.                 s.r=3;
  261.                 }
  262.                 [map setTile:s at:ccg(e,f)];
  263.                 topos.x=topos.x+16;
  264.                 topos.y=topos.y+16;
  265.                 [self emitParticles:[self position]];
  266.                
  267.             }
  268.             else if([mPreDir isEqualToString:@"DOWN"])
  269.             {
  270.                 int e = (topos.x)/32;
  271.                 int f = (topos.y-32)/32-2;
  272.                 ccRGBB s=[map tileAt:ccg(e,f)];
  273.                 if(s.r==15 || s.r==18 ||s.r==19)
  274.                 {
  275.                 s.r=25;
  276.                 }
  277.                 else if(s.r==4)
  278.                 {
  279.                     s.r=9;
  280.                 }
  281.                 else
  282.                 {
  283.                     s.r=3;
  284.                 }
  285.                 [map setTile:s at:ccg(e,f)];
  286.                 topos.x=topos.x+16;
  287.                 topos.y=topos.y-16;
  288.                 //          [self emitParticles:[self position]];
  289.                
  290.             }
  291.            
  292.             [self runAction:[MoveTo actionWithDuration:0.3 position:ccp(topos.x,topos.y)]];
  293.             [self setHeroPos:ccp(topos.x,topos.y)];
  294.             [self checkingDiamond:topos];
  295.         }
  296.         else if([mDir isEqualToString:@"RIGHT"])
  297.         {
  298.             if([mPreDir isEqualToString:@"UP"])
  299.             {
  300.                 int e = (topos.x-32)/32;
  301.                 int f = (topos.y)/32-2;
  302.                 ccRGBB s=[map tileAt:ccg(e,f)];
  303.                 if(s.r==15 || s.r==16 || s.r==17)
  304.                 {
  305.                     s.r=11;
  306.                 }
  307.                 else if(s.r==4)
  308.                 {
  309.                     s.r=8;
  310.                 }
  311.                 else
  312.                 {
  313.                     s.r=3;
  314.                 }
  315.                 [map setTile:s at:ccg(e,f)];
  316.                 topos.x=topos.x-16;
  317.                 topos.y=topos.y+16;
  318.                 //      [self emitParticles:[self position]];
  319.                
  320.             }
  321.             else if([mPreDir isEqualToString:@"DOWN"])
  322.             {
  323.                 int e = (topos.x-32)/32;
  324.                 int f = (topos.y-32)/32-2;
  325.                 ccRGBB s=[map tileAt:ccg(e,f)];
  326.                 if(s.r==15 || s.r==18 || s.r==19)
  327.                 {
  328.                 s.r=24;
  329.                 }
  330.                 else if(s.r==4)
  331.                 {
  332.                     s.r=8;
  333.                 }
  334.                 else
  335.                 {
  336.                     s.r=3;
  337.                    
  338.                 }
  339.                 [map setTile:s at:ccg(e,f)];
  340.                 topos.x=topos.x-16;
  341.                 topos.y=topos.y-16;
  342.                 //      [self emitParticles:[self position]];
  343.                
  344.             }
  345.             [self runAction:[MoveTo actionWithDuration:0.3 position:ccp(topos.x,topos.y)]];
  346.             [self setHeroPos:ccp(topos.x,topos.y)];
  347.             [self checkingDiamond:topos];
  348.         }
  349.         return NO;
  350.     }
  351.    
  352.     // This is the case when the topos of digger is in the middle of the two tiles.
  353.     else if ([[NSNumber numberWithFloat: topos.x] intValue ]% 32==0 || [[NSNumber numberWithFloat: topos.y] intValue ]% 32==0 )
  354.     {
  355.        
  356.         ccRGBB t;
  357.        
  358.         //checking for not moving on bags
  359.        
  360.         for(int h=0;h<bagCount;h++)
  361.         {
  362.             Bagbomb *b1=(Bagbomb*)[[self parent] getChildByTag:200+h];
  363.             if(b1!=nil)
  364.             {
  365.                 if([mDir isEqualToString:@"LEFT"]==YES)
  366.                 {
  367.                     if((topos.x-16)==b1.bagPos.x && (topos.y)==b1.bagPos.y)
  368.                     {
  369.                         return NO;
  370.                     }
  371.                 }
  372.                 else if([mDir isEqualToString:@"RIGHT"]==YES)
  373.                 {
  374.                     if((topos.x+16)==b1.bagPos.x && (topos.y)==b1.bagPos.y)
  375.                     {
  376.                         return NO;
  377.                     }
  378.                 }
  379.                 else if([mDir isEqualToString:@"UP"]==YES)
  380.                 {
  381.                     if((topos.x)==b1.bagPos.x && (topos.y+16)==b1.bagPos.y)
  382.                     {
  383.                         return NO;
  384.                     }
  385.                 }
  386.                 else if([mDir isEqualToString:@"DOWN"]==YES)
  387.                 {
  388.                     if((topos.x)==b1.bagPos.x && (topos.y-16)==b1.bagPos.y)
  389.                     {
  390.                         return NO;
  391.                     }
  392.                 }
  393.             }
  394.         }
  395.        
  396.         //For digger movement.
  397.         if([mDir isEqualToString:@"LEFT"]==YES)
  398.         {
  399.            
  400.            
  401.             int a=((topos.x-32)/32);
  402.             int b1=((topos.y-16)/32)-2;
  403.             ccRGBB s= [map tileAt:ccg(a,b1)];
  404.             ccRGBB s1= [map tileAt:ccg(a+1,b1)];
  405.             if(s1.r==4 || s1.r==19 || s1.r==17)
  406.             {
  407.                 s1.r=9;
  408.                 NSLog(@"Tile changed");
  409.                 [map setTile:s1 at:ccg(a+1,b1)];
  410.             }
  411.             if(s.r==14)
  412.             {
  413.                 [self unschedule:@selector(animateAnt)];
  414.                 return NO;
  415.            
  416.             }
  417.            
  418.            
  419.             else if(s.r==15 )
  420.             {
  421.                 t.r=5;
  422.                 int x=(topos.x -32)/32;
  423.                 int y=((topos.y-16)/32)-2 ;
  424.                 [map  setTile:t at:ccg(x,y)];
  425.                 [self emitParticles:topos];
  426.                
  427.             }
  428.             else if( s.r==7 || s.r==16 || s.r==17 || s.r==18 || s.r==19 || s.r==20)
  429.             {
  430.                 t.r=21;
  431.                 //t.r=3;
  432.                 int x=(topos.x -32)/32;
  433.                 int y=((topos.y-16)/32)-2 ;
  434.                 [map  setTile:t at:ccg(x,y)];
  435.                 [self emitParticles:topos];
  436.             }
  437.             else if(s.r==4)
  438.             {
  439.                 t.r=8;
  440.                 int x=(topos.x -32)/32;
  441.                 int y=((topos.y-16)/32)-2 ;
  442.                 [map  setTile:t at:ccg(x,y)];
  443.                 [self emitParticles:topos];
  444.                
  445.             }
  446.             else if(s.r==9)
  447.             {
  448.                 t.r=3;
  449.                 int x=(topos.x -32)/32;
  450.                 int y=((topos.y-16)/32)-2 ;
  451.                 [map  setTile:t at:ccg(x,y)];
  452.                 [self emitParticles:topos];
  453.                
  454.             }
  455.             else if(s.r==11 || s.r==12)
  456.             {
  457.                 t.r=23;
  458.                 int x=(topos.x-32)/32;
  459.                 int y=((topos.y-16)/32)-2 ;
  460.                 [map  setTile:t at:ccg(x,y)];
  461.                 [self emitParticles:topos];
  462.            
  463.            
  464.             }
  465.             else if(s.r==24 || s.r==25)
  466.             {
  467.                 t.r=22;
  468.                 int x=(topos.x-32)/32;
  469.                 int y=((topos.y-16)/32)-2 ;
  470.                 [map  setTile:t at:ccg(x,y)];
  471.                 [self emitParticles:topos];
  472.                
  473.                
  474.             }
  475.            
  476.            
  477.         }
  478.         if([mDir isEqualToString:@"RIGHT"]==YES )
  479.         {
  480.             int a=(topos.x/32);
  481.             int b1=((topos.y-16)/32)-2;
  482.             ccRGBB s= [map tileAt:ccg(a,b1)];
  483.             ccRGBB s1= [map tileAt:ccg(a-1,b1)];
  484.             if(s1.r==4 || s1.r==19 ||s1.r==17)
  485.             {
  486.                 s1.r=8;
  487.                 NSLog(@"Tile chaned");
  488.                 [map setTile:s1 at:ccg(a-1,b1)];
  489.             }
  490.             if(s.r==14)
  491.             {
  492.                 [self unschedule:@selector(animateAnt)];
  493.                 return NO;
  494.                
  495.             }
  496.             else if(s.r==15)
  497.             {
  498.                 t.r=7;
  499.                 int x=(topos.x)/32;
  500.                 int y=((topos.y-16)/32)-2 ;
  501.                 [map  setTile:t at:ccg(x,y)];
  502.                 [self emitParticles:topos];
  503.                
  504.             }
  505.             else if( s.r==5 || s.r==6 || s.r==16 || s.r==17 || s.r==18 || s.r==19)
  506.             {
  507.                 t.r=21;
  508.                 //t.r=3;
  509.                 int x=(topos.x)/32;
  510.                 int y=((topos.y-16)/32)-2 ;
  511.                 [map  setTile:t at:ccg(x,y)];
  512.                 [self emitParticles:topos];
  513.                
  514.             }
  515.             else if(s.r==4)
  516.             {
  517.                 t.r=9;
  518.                 int x=(topos.x)/32;
  519.                 int y=((topos.y-16)/32)-2 ;
  520.                 [map  setTile:t at:ccg(x,y)];
  521.                 [self emitParticles:topos];
  522.                
  523.             }
  524.             else if(s.r==8)
  525.             {
  526.                 t.r=3;
  527.                 int x=(topos.x)/32;
  528.                 int y=((topos.y-16)/32)-2 ;
  529.                 [map  setTile:t at:ccg(x,y)];
  530.                 [self emitParticles:topos];
  531.                
  532.             }
  533.             else if(s.r==11 || s.r==12)
  534.             {
  535.                 t.r=23;
  536.                 int x=(topos.x)/32;
  537.                 int y=((topos.y-16)/32)-2 ;
  538.                 [map  setTile:t at:ccg(x,y)];
  539.                 [self emitParticles:topos];
  540.                
  541.                
  542.             }
  543.             else if(s.r==24 || s.r==25)
  544.             {
  545.                 t.r=22;
  546.                 int x=(topos.x)/32;
  547.                 int y=((topos.y-16)/32)-2 ;
  548.                 [map  setTile:t at:ccg(x,y)];
  549.                 [self emitParticles:topos];
  550.                
  551.                
  552.             }
  553.         }
  554.         if([mDir isEqualToString:@"UP"]==YES)
  555.         {
  556.             int a=((topos.x-16)/32);
  557.             int b1=(topos.y/32)-2;
  558.             ccRGBB s= [map tileAt:ccg(a,b1)];
  559.             ccRGBB s1= [map tileAt:ccg(a,b1-1)];
  560.             if(s1.r==21 || s1.r==6 || s1.r==20)
  561.             {
  562.                 s1.r=22;
  563.                 NSLog(@"Tile chaned");
  564.                 [map setTile:s1 at:ccg(a,b1-1)];
  565.             }
  566.             if(s.r==14)
  567.             {
  568.                 [self unschedule:@selector(animateAnt)];
  569.                 return NO;
  570.                
  571.             }
  572.             else if(s.r==15)
  573.             {
  574.                 t.r=16;
  575.                 int x=(topos.x -16)/32;
  576.                 int y=(topos.y)/32-2 ;
  577.                 [map  setTile:t at:ccg(x,y)];
  578.                 [self emitParticles:topos];
  579.                
  580.             }
  581.             else if( s.r==5 || s.r==7 || s.r==18 || s.r==19)
  582.             {
  583.                 t.r=4;
  584.                 int x=(topos.x -16)/32;
  585.                 int y=(topos.y)/32-2 ;
  586.                 [map  setTile:t at:ccg(x,y)];
  587.                 [self emitParticles:topos];
  588.                
  589.             }
  590.             else if(s.r==6)
  591.             {
  592.                 t.r=8;
  593.                 int x=(topos.x -16)/32;
  594.                 int y=(topos.y)/32-2 ;
  595.                 [map  setTile:t at:ccg(x,y)];
  596.                 [self emitParticles:topos];
  597.            
  598.             }
  599.            
  600.             else if(s.r==20)
  601.             {
  602.                 t.r=9;
  603.                 int x=(topos.x -16)/32;
  604.                 int y=(topos.y)/32-2 ;
  605.                 [map  setTile:t at:ccg(x,y)];
  606.                 [self emitParticles:topos];
  607.                
  608.             }
  609.             else if(s.r==21)
  610.             {
  611.                 t.r=23;
  612.                 int x=(topos.x -16)/32;
  613.                 int y=(topos.y)/32-2 ;
  614.                 [map  setTile:t at:ccg(x,y)];
  615.                 [self emitParticles:topos];
  616.                
  617.             }
  618.             else if(s.r==22)
  619.             {
  620.                 t.r=3;
  621.                 int x=(topos.x -16)/32;
  622.                 int y=(topos.y)/32-2 ;
  623.                 [map  setTile:t at:ccg(x,y)];
  624.                 [self emitParticles:topos];
  625.                
  626.             }
  627.             else if(s.r==11 || s.r==24)
  628.             {
  629.                 t.r=8;
  630.                 int x=(topos.x -16)/32;
  631.                 int y=(topos.y/32)-2 ;
  632.                 [map  setTile:t at:ccg(x,y)];
  633.                 [self emitParticles:topos];
  634.                
  635.                
  636.             }
  637.             else if(s.r==12 || s.r==25)
  638.             {
  639.                 t.r=9;
  640.                 int x=(topos.x -16)/32;
  641.                 int y=(topos.y/32)-2 ;
  642.                 [map  setTile:t at:ccg(x,y)];
  643.                 [self emitParticles:topos];
  644.                
  645.                
  646.             }
  647.             else if(s.r==3)
  648.             {
  649.            
  650.                 NSLog(@"10 no tiillllle");
  651.             }
  652.            
  653.         }
  654.         if([mDir isEqualToString:@"DOWN"]==YES )
  655.         {
  656.             int a=(topos.x-16)/32;
  657.             int b1=((topos.y-32)/32)-2;
  658.             ccRGBB s= [map tileAt:ccg(a,b1)];
  659.             ccRGBB s1= [map tileAt:ccg(a,b1+1)];
  660.             if(s1.r==21 || s1.r==6 || s1.r==20)
  661.             {
  662.                 s1.r=23;
  663.                 NSLog(@"Tile chaned");
  664.                 [map setTile:s1 at:ccg(a,b1+1)];
  665.             }
  666.             if(s.r==14)
  667.             {
  668.                 [self unschedule:@selector(animateAnt)];
  669.                 return NO;
  670.                
  671.             }
  672.             else if(s.r==15)
  673.             {
  674.                 t.r=18;
  675.                 int x=(topos.x- 16)/32;
  676.                 int y=((topos.y-32)/32)-2 ;
  677.                 [map  setTile:t at:ccg(x,y)];
  678.                 [self emitParticles:topos];
  679.                
  680.             }
  681.             else if( s.r==5 || s.r==6 || s.r==7 || s.r==16 || s.r==17 || s.r==20)
  682.             {
  683.                 t.r=4;
  684.                 int x=(topos.x- 16)/32;
  685.                 int y=((topos.y-32)/32)-2 ;
  686.                 [map  setTile:t at:ccg(x,y)];
  687.                 [self emitParticles:topos];
  688.                
  689.             }
  690.             else if(s.r==21)
  691.             {
  692.                 t.r=22;
  693.                 int x=(topos.x- 16)/32;
  694.                 int y=((topos.y-32)/32)-2 ;
  695.                 [map  setTile:t at:ccg(x,y)];
  696.                 [self emitParticles:topos];
  697.                
  698.             }
  699.             else if(s.r==23)
  700.             {
  701.                 t.r=3;
  702.                 int x=(topos.x- 16)/32;
  703.                 int y=((topos.y-32)/32)-2 ;
  704.                 [map  setTile:t at:ccg(x,y)];
  705.                 [self emitParticles:topos];
  706.                
  707.             }
  708.             else if(s.r==11 || s.r==24)
  709.             {
  710.                 t.r=8;
  711.                 int x=(topos.x-16)/32;
  712.                 int y=((topos.y-32)/32)-2 ;
  713.                 [map  setTile:t at:ccg(x,y)];
  714.                 [self emitParticles:topos];
  715.                
  716.                
  717.             }
  718.             else if(s.r==12 || s.r==25)
  719.             {
  720.                 t.r=9;
  721.                 int x=(topos.x-16)/32;
  722.                 int y=((topos.y-32)/32)-2 ;
  723.                 [map  setTile:t at:ccg(x,y)];
  724.                 [self emitParticles:topos];
  725.                
  726.                
  727.             }
  728.            
  729.         }
  730.        
  731.         return YES;
  732.        
  733.     }
  734.     // Position is on the center of the tile.
  735.     else
  736.     {
  737.        
  738.        
  739.         if([mDir isEqualToString:@"LEFT"]==YES )
  740.         {
  741.             ccRGBB t=[map tileAt:ccg((topos.x-16)/32,((topos.y-16)/32)-2)];
  742.             if(t.r==5)
  743.             {
  744.                 t.r=6;
  745.                 int x=(topos.x -16)/32;
  746.                 int y=(topos.y-16)/32-2;
  747.                
  748.                 [map  setTile:t at:ccg(x,y)];
  749.                 myX=x;
  750.                 myY=y;
  751.                 //tileInfo = [NSString stringWithFormat:@"#%d#%d#",x,y];
  752.                 //[self performSelector:@selector(lastTile:) withObject:tileInfo afterDelay:0.3];
  753.                 [self schedule:@selector(lastTile) interval:0.3];
  754.                
  755.             }
  756.             else if(t.r==8)
  757.             {
  758.                 t.r=3;
  759.                 int x=(topos.x -16)/32;
  760.                 int y=(topos.y-16)/32-2;
  761.                
  762.                 [map  setTile:t at:ccg(x,y)];
  763.                
  764.             }
  765.             else if(t.r==6)
  766.             {
  767.                 t.r=21;
  768.                 int x=(topos.x -16)/32;
  769.                 int y=(topos.y-16)/32-2;
  770.                
  771.                 [map  setTile:t at:ccg(x,y)];
  772.            
  773.             }
  774.         }
  775.         if([mDir isEqualToString:@"RIGHT"]==YES )
  776.         {
  777.             ccRGBB t=[map tileAt:ccg((topos.x-16)/32,((topos.y-16)/32)-2)];
  778.             if(t.r==7)
  779.             {
  780.                 t.r=20;
  781.                 int x=(topos.x -16)/32;
  782.                 int y=(topos.y-16)/32-2;
  783.                
  784.                 [map  setTile:t at:ccg(x,y)];
  785.                 myX=x;
  786.                 myY=y;
  787.                 //tileInfo = [NSString stringWithFormat:@"#%d#%d#",x,y];
  788.                 //[self performSelector:@selector(lastTile:) withObject:tileInfo afterDelay:0.3];
  789.                 [self schedule:@selector(lastTile) interval:0.3];
  790.             }
  791.             else if(t.r==9)
  792.             {
  793.                
  794.                 t.r=3;
  795.                 int x=(topos.x -16)/32;
  796.                 int y=(topos.y-16)/32-2;
  797.                 [map  setTile:t at:ccg(x,y)];
  798.             }
  799.            
  800.         }
  801.         if([mDir isEqualToString:@"UP"]==YES )
  802.         {
  803.            
  804.             ccRGBB t=[map tileAt:ccg((topos.x-16)/32,((topos.y-16)/32)-2)];
  805.         //  ccRGBB t1=[map tileAt:ccg((topos.x-16)/32,((topos.y-16)/32)-3)];
  806.         //  if(t1.r==21)
  807.         //  {
  808.         //      t1.r=22;
  809.         //      NSLog(@"Tile changed");
  810.         //      [map setTile:t1 at:ccg((topos.x-16)/32,((topos.y-16)/32)-3)];
  811.         //  }
  812.             if(t.r==16)
  813.             {
  814.                 t.r=17;
  815.                 int x=(topos.x -16)/32;
  816.                 int y=(topos.y-16)/32-2;
  817.                
  818.                 [map  setTile:t at:ccg(x,y)];
  819.                 myX=x;
  820.                 myY=y;
  821.                 //tileInfo = [NSString stringWithFormat:@"#%d#%d#",x,y];
  822.                 //[self performSelector:@selector(lastTile:) withObject:tileInfo afterDelay:0.3];
  823.                 [self schedule:@selector(lastTile) interval:0.3];
  824.             }
  825.             else if(t.r==23)
  826.             {
  827.                 t.r=3;
  828.                 int x=(topos.x -16)/32;
  829.                 int y=(topos.y-16)/32-2;
  830.                
  831.                 [map  setTile:t at:ccg(x,y)];
  832.             }
  833.            
  834.         }
  835.         if([mDir isEqualToString:@"DOWN"]==YES )
  836.         {
  837.             ccRGBB t=[map tileAt:ccg((topos.x-16)/32,((topos.y-16)/32)-2)];
  838.             if(t.r==18)
  839.             {
  840.                 t.r=19;
  841.                 int x=(topos.x -16)/32;
  842.                 int y=(topos.y-16)/32-2;
  843.                
  844.                 [map  setTile:t at:ccg(x,y)];
  845.                 myX=x;
  846.                 myY=y;
  847.                 //tileInfo = [NSString stringWithFormat:@"#%d#%d#",x,y];
  848.                 //[self performSelector:@selector(lastTile:) withObject:tileInfo afterDelay:0.3];
  849.                 [self schedule:@selector(lastTile) interval:0.3];
  850.             }
  851.             else if(t.r==22)
  852.             {
  853.                 t.r=3;
  854.                 int x=(topos.x -16)/32;
  855.                 int y=(topos.y-16)/32-2;
  856.                
  857.                 [map  setTile:t at:ccg(x,y)];
  858.             }
  859.            
  860.         }
  861.         return YES;
  862.     }
  863.    
  864.    
  865.    
  866. }
  867. -(void)lastTile
  868. {
  869.     [self emitParticles:[self position]];
  870.     [self unschedule:@selector(lastTile)];
  871.     //NSLog(@"%@",tileInfo);
  872.     //int j=[[(NSArray*)[tileInfo componentsSeparatedByString:@"#"] objectAtIndex:0] intValue];
  873.     //int k=[[(NSArray*)[tileInfo componentsSeparatedByString:@"#"] objectAtIndex:1] intValue];
  874.     int j = myX;
  875.     int k = myY;
  876.     ccRGBB t=[tilemap1 tileAt:ccg(j,k)];
  877.     if(t.r==3)
  878.     {;}
  879.     else
  880.     {
  881.         if([mDir isEqualToString:@"LEFT"])
  882.         {
  883.             if([mPreDir isEqualToString:@"LEFT"] || [mPreDir isEqualToString:@"RIGHT"])
  884.             {
  885.                 if(t.r==9)
  886.                 {}
  887.                 else
  888.                 {
  889.                     t.r=21;
  890.                 }
  891.             }
  892.             else if([mPreDir isEqualToString:@"UP"] || [mPreDir isEqualToString:@"DOWN"])
  893.             {
  894.                 if(t.r==4)
  895.                 {
  896.                 t.r=9;
  897.                 }
  898.                
  899.                 //t.r=3;
  900.             }
  901.             [tilemap1  setTile:t at:ccg(j,k)];
  902.         }
  903.         else if([mDir isEqualToString:@"RIGHT"])
  904.         {
  905.             if([mPreDir isEqualToString:@"LEFT"] || [mPreDir isEqualToString:@"RIGHT"])
  906.             {
  907.                 if(t.r==8)
  908.                 {}
  909.                 else
  910.                 {
  911.                     t.r=21;
  912.                 }
  913.             }
  914.             else if([mPreDir isEqualToString:@"UP"] || [mPreDir isEqualToString:@"DOWN"])
  915.             {
  916.                 if(t.r==4)
  917.                 {
  918.                     t.r=8;
  919.                 }
  920.                
  921.                 //t.r=3;
  922.             }
  923.         }
  924.         else if([mDir isEqualToString:@"UP"])
  925.         {
  926.             if([mPreDir isEqualToString:@"LEFT"] || [mPreDir isEqualToString:@"RIGHT"])
  927.             {
  928.                 if(t.r==21)
  929.                 {
  930.                 t.r=22;
  931.                 }
  932.                 else
  933.                 {
  934.                     //t.r=3;
  935.                 }
  936.                    
  937.                 //t.r=3;
  938.             }
  939.             else if([mPreDir isEqualToString:@"UP"] || [mPreDir isEqualToString:@"DOWN"])
  940.             {
  941.                 //t.r=4;
  942.                 //t.r=3;
  943.                 if(t.r==22)
  944.                 {}
  945.                 else
  946.                 {
  947.                     t.r=4;
  948.                 }
  949.             }
  950.         }
  951.          
  952.         else if( [mDir isEqualToString:@"DOWN"])
  953.         {
  954.             if([mPreDir isEqualToString:@"LEFT"] || [mPreDir isEqualToString:@"RIGHT"])
  955.             {
  956.                 if(t.r==21)
  957.                 {
  958.                     t.r=23;
  959.                 }
  960.                 //t.r=3;
  961.             }
  962.             else if([mPreDir isEqualToString:@"UP"] || [mPreDir isEqualToString:@"DOWN"])
  963.             {
  964.                 if(t.r==23)
  965.                 {}
  966.                 else
  967.                 {
  968.                     t.r=4;
  969.                 }
  970.             }
  971.         }
  972.        
  973.         else if([mDir isEqualToString:@""]==YES)
  974.             //t.r=3;
  975.         {
  976.             if([mPreDir isEqualToString:@"LEFT"] || [mPreDir isEqualToString:@"RIGHT"])
  977.             {
  978.                 t.r=21;
  979.             }
  980.             else if([mPreDir isEqualToString:@"DOWN"] || [mPreDir isEqualToString:@"UP"])
  981.             {
  982.                 t.r=4;
  983.             }
  984.                
  985.         }
  986.        
  987.         [tilemap1  setTile:t at:ccg(j,k)];
  988.     }
  989.    
  990. }
  991.  
  992. -(void)moveLeft
  993. {
  994.     CGPoint toPoint=CGPointMake(heroPos.x-16 ,heroPos.y);
  995.     //CGPoint goAt=CGPointMake(heroPos.x-16.heroPos.y);
  996.     NSLog(@"%f %f",toPoint.x,toPoint.y);
  997.    
  998.     if(toPoint.x>=16  && stopMoving==NO && [mDir isEqualToString:@"LEFT"]==YES)
  999.     {
  1000.         if([self checkIfBag:toPoint]==NO)
  1001.         {
  1002.             BOOL canMove=[self canMoveFrom:heroPos to:toPoint inMap:tilemap1];
  1003.             if (canMove==YES)
  1004.             {
  1005.                 [self runAction:[MoveTo actionWithDuration:0.4 position:ccp(toPoint.x,toPoint.y)]];
  1006.                 [self setHeroPos:toPoint];
  1007.                 //  NSLog(@"%f ***** %f  ",heroPos.x,heroPos.y);
  1008.                 [self checkingDiamond:toPoint];
  1009.                 mPreDir=@"LEFT";
  1010.                 //[self schedule:@selector(moveLeft) interval:0.5];    
  1011.             }
  1012.         }
  1013.     }
  1014. }
  1015. -(void)moveRight
  1016. {
  1017.     CGPoint toPoint=CGPointMake(heroPos.x+16 ,heroPos.y);
  1018.    
  1019.    
  1020.     //NSLog(@"%f %f",toPoint.x,toPoint.y);
  1021.     if(toPoint.x<=304  && stopMoving==NO && [mDir isEqualToString:@"RIGHT"]==YES)
  1022.     {
  1023.         if([self checkIfBag:toPoint]==NO)
  1024.         {
  1025.             BOOL canMove=[self canMoveFrom:heroPos to:toPoint inMap:tilemap1];
  1026.             if (canMove==YES)
  1027.             {
  1028.                 [self runAction:[MoveTo actionWithDuration:0.4 position:ccp(toPoint.x,toPoint.y)]];
  1029.                 [self setHeroPos:toPoint];
  1030.                 //NSLog(@"%f ***** %f  ",heroPos.x,heroPos.y);
  1031.                 [self checkingDiamond:toPoint];
  1032.                 mPreDir=@"RIGHT";
  1033.                 //[self schedule:@selector(moveRight) interval:0.5];       
  1034.             }
  1035.         }
  1036.     }
  1037. }
  1038.  
  1039. -(void)moveUP
  1040. {
  1041.     NSLog(@"In UP");
  1042.     CGPoint toPoint=CGPointMake(heroPos.x ,heroPos.y+16);
  1043.     if(toPoint.y<=432  && stopMoving==NO && [mDir isEqualToString:@"UP"]==YES)
  1044.     {
  1045.         if([self checkIfBag:toPoint]==NO)
  1046.         {
  1047.             BOOL canMove=[self canMoveFrom:heroPos to:toPoint inMap:tilemap1];
  1048.             if (canMove==YES)
  1049.             {
  1050.                
  1051.                 [self runAction:[MoveTo actionWithDuration:0.4 position:ccp(toPoint.x,toPoint.y)]];
  1052.                 [self setHeroPos:toPoint];
  1053.                 //NSLog(@"%f ***** %f  ",heroPos.x,heroPos.y);
  1054.                 [self checkingDiamond:toPoint];
  1055.                 mPreDir=@"UP";
  1056.                 //[self schedule:@selector(moveUP) interval:0.5];      
  1057.             }
  1058.         }
  1059.     }
  1060. }
  1061. -(void)moveDown
  1062. {
  1063.    
  1064.     CGPoint toPoint=CGPointMake(heroPos.x ,heroPos.y-16);
  1065.     if(toPoint.y>=80  && stopMoving==NO && [mDir isEqualToString:@"DOWN"]==YES)
  1066.     {
  1067.         if([self checkIfBag:toPoint]==NO)
  1068.         {
  1069.             BOOL canMove=[self canMoveFrom:heroPos to:toPoint inMap:tilemap1];
  1070.             if (canMove==YES)
  1071.             {
  1072.                 [self runAction:[MoveTo actionWithDuration:0.4 position:ccp(toPoint.x,toPoint.y)]];
  1073.                 [self setHeroPos:toPoint];
  1074.                 //NSLog(@"%f ***** %f  ",heroPos.x,heroPos.y);
  1075.                 [self checkingDiamond:toPoint];
  1076.                 mPreDir=@"DOWN";
  1077.                 //[self schedule:@selector(moveDown) interval:0.5];    
  1078.                
  1079.             }
  1080.            
  1081.         }
  1082.     }
  1083. }
  1084.  
  1085. -(void)willMoveUp:(TileMapAtlas*)myTileMap
  1086. {
  1087.     if([(GameLayer*)[self parent] canTouch])
  1088.     {
  1089.         [self unschedule:@selector(waitingAnimation)];
  1090.     self.mDir=@"UP";
  1091.    
  1092.     if([self.mPreDir isEqualToString:@"UP"]==NO)
  1093.     {
  1094.         //self.mPreDir = @"UP";
  1095.        
  1096.         if ([[NSNumber numberWithFloat: self.heroPos.x] intValue ]% 32!=0 && [[NSNumber numberWithFloat: self.heroPos.y] intValue ]% 32!=0)
  1097.         {
  1098.            
  1099.             //int e = (self.heroPos.x-16)/32;
  1100.             //int f = (self.heroPos.y-16)/32-2;
  1101.             //ccRGBB s=[tilemap1 tileAt:ccg(e,f)];
  1102.             //s.r=3;
  1103.             //[tilemap1 setTile:s at:ccg(e,f)];
  1104.         }
  1105.         //self.stopMoving=NO;
  1106.         [self turnLeftAnimation:0.5];
  1107.         //[self schedule:@selector(animateAnt) interval:0.4];
  1108.         [self schedule:@selector(moveUP) interval:0.4];
  1109.     }
  1110.     //[self setRotation:90];
  1111.     self.stopMoving=NO;
  1112.     //self.mPreDir=@"UP";
  1113.     }
  1114. }
  1115. -(void)willMoveDown:(TileMapAtlas*)myTileMap
  1116. {
  1117.     if([(GameLayer*)[self parent] canTouch])
  1118.     {
  1119.     [self unschedule:@selector(waitingAnimation)];
  1120.     self.mDir=@"DOWN";
  1121.     if([self.mPreDir isEqualToString:@"DOWN"]==NO)
  1122.     {
  1123.         //self.mPreDir = @"DOWN";
  1124.        
  1125.         if ([[NSNumber numberWithFloat: self.heroPos.x] intValue ]% 32!=0 && [[NSNumber numberWithFloat: self.heroPos.y] intValue ]% 32!=0)
  1126.         {
  1127.         /*  int e = (self.heroPos.x-16)/32;
  1128.             int f = (self.heroPos.y-16)/32-2;
  1129.             ccRGBB s=[tilemap1 tileAt:ccg(e,f)];
  1130.             s.r=3;
  1131.             [tilemap1 setTile:s at:ccg(e,f)];
  1132.          */
  1133.         }
  1134.  
  1135.         [self setRotation:90];
  1136.        
  1137.         [self turnRightAnimation:0.5];
  1138.         //[self schedule:@selector(animateAnt) interval:0.4];
  1139.         [self schedule:@selector(moveDown) interval:0.4];
  1140.     }
  1141.     self.stopMoving=NO;
  1142.     }
  1143. }
  1144. -(void)willMoveRight:(TileMapAtlas*)myTileMap
  1145. {
  1146.     if([(GameLayer*)[self parent] canTouch])
  1147.     {
  1148.                 [self unschedule:@selector(waitingAnimation)];
  1149.     self.mDir=@"RIGHT";
  1150.     if([self.mPreDir isEqualToString:@"RIGHT"]==NO)
  1151.     {
  1152.         //self.mPreDir = @"RIGHT";
  1153.        
  1154.         if ([[NSNumber numberWithFloat: self.heroPos.x] intValue ]% 32!=0 && [[NSNumber numberWithFloat: self.heroPos.y] intValue ]% 32!=0)
  1155.         {
  1156.            
  1157.             /*int e = (self.heroPos.x-16)/32;
  1158.             int f = (self.heroPos.y-16)/32-2;
  1159.             ccRGBB s=[tilemap1 tileAt:ccg(e,f)];
  1160.             s.r=3;
  1161.             [tilemap1 setTile:s at:ccg(e,f)];
  1162.              */
  1163.         }
  1164.         //
  1165.         //self.mPreDir=@"RIGHT";
  1166.         [self turnRightAnimation:0.5];
  1167.         //[self schedule:@selector(animateAnt) interval:0.4];
  1168.         [self schedule:@selector(moveRight) interval:0.4];
  1169.     }
  1170.    
  1171.     self.stopMoving=NO;
  1172.     }
  1173. }
  1174. -(void)willMoveLeft:(TileMapAtlas*)myTileMap
  1175. {
  1176.     if([(GameLayer*)[self parent] canTouch])
  1177.     {
  1178.                 [self unschedule:@selector(waitingAnimation)];
  1179.     self.mDir=@"LEFT";
  1180.     if([self.mPreDir isEqualToString:@"LEFT"]==NO)
  1181.     {
  1182.         //self.mPreDir = @"LEFT";
  1183.         if ([[NSNumber numberWithFloat: self.heroPos.x] intValue ]% 32!=0 && [[NSNumber numberWithFloat: self.heroPos.y] intValue ]% 32!=0)
  1184.         {
  1185.             /*int e = (self.heroPos.x-16)/32;
  1186.             int f = (self.heroPos.y-16)/32-2;
  1187.             ccRGBB s=[tilemap1 tileAt:ccg(e,f)];
  1188.             s.r=3;
  1189.             [tilemap1 setTile:s at:ccg(e,f)];
  1190.              */
  1191.         }
  1192.         [self setRotation:0];
  1193.         //self.stopMoving=NO;
  1194.         [self turnLeftAnimation:0.5];
  1195.         //[self schedule:@selector(animateAnt) interval:0.4];
  1196.         [self schedule:@selector(moveLeft) interval:0.4];
  1197.        
  1198.     }
  1199.     self.stopMoving=NO;
  1200.     }
  1201. }
  1202. //Mehod in a scheduler for checking bag fall.
  1203. -(void)checkBagFall
  1204. {
  1205.     for(int i=0;i<bagCount;i++)
  1206.     {
  1207.         bag=(Bagbomb*)[[self parent] getChildByTag:200+i];
  1208.         if(bag!=nil)
  1209.         {
  1210.             if(roundf(bag.bagPos.y) != 80)
  1211.             {
  1212.                 posx=roundf(bag.bagPos.x);
  1213.                 posy=roundf(bag.bagPos.y)-32.0f;
  1214.                
  1215.                 float p=(posx -16)/32;
  1216.                 float q=(posy-16)/32-2 ;
  1217.                 ccRGBB black=[tilemap1 tileAt:ccg(p,q)];
  1218.                
  1219.                 if (black.r==3 || black.r==4 || black.r==21 || black.r==23 || black.r==22 || black.r==9 || black.r==8|| black.r==11|| black.r==12|| black.r==24||black.r==25||black.r==3)
  1220.                 {
  1221.                     [self unschedule:@selector(checkBagFall)];
  1222.                     NSLog(@"Bag tag %d",[bag tag]);
  1223.                     [self performSelector:@selector(bagMovement) withObject:bag afterDelay:1.5];
  1224.                     break;
  1225.                 }
  1226.             }  
  1227.         }
  1228.     }
  1229. }
  1230. -(void)bagMovement
  1231. {
  1232.    
  1233.     if(roundf(bag.bagPos.y) != 48)
  1234.     {
  1235.         NSLog(@"Bag Position %f %f",bag.bagPos.x,bag.bagPos.y);
  1236.         posx=roundf(bag.bagPos.x);
  1237.         posy=roundf(bag.bagPos.y)-32.0f;
  1238.        
  1239.         int p=(posx-16)/32;
  1240.         int q=(posy-16)/32-2;
  1241.         ccRGBB black=[tilemap1 tileAt:ccg(p,q)];
  1242.        
  1243.         if (black.r==3 || black.r==4 || black.r==21 || black.r==23 || black.r==22 || black.r==9 || black.r==8|| black.r==11|| black.r==12|| black.r==24||black.r==25 || black.r==3)
  1244.         {
  1245.            
  1246.             [self schedule:@selector(bagMovement) interval:0.2];
  1247.            
  1248.             [bag runAction:[MoveTo actionWithDuration:0.5 position:ccp(posx,posy)]];
  1249.             [bag setBagPos:ccp(posx,posy)];
  1250.            
  1251.             int j=(posx -16)/32;
  1252.             int k=(posy-16)/32-2;
  1253.             if(black.r==21)
  1254.             {
  1255.                
  1256.                 ccRGBB t;
  1257.                 t.r=22;
  1258.                 [tilemap1 setTile:t at:ccg(j,k)];
  1259.                 NSString *str=[[NSString alloc] initWithFormat:@"%d#%d#",j,k];
  1260.                 [self performSelector:@selector(bagTileRemove:) withObject:str afterDelay:0.1];
  1261.                 [str release];
  1262.             }
  1263.             if(black.r==11 || black.r==24)
  1264.             {
  1265.                 ccRGBB t;
  1266.                 t.r=8;
  1267.                 [tilemap1 setTile:t at:ccg(j,k)];
  1268.                
  1269.             }
  1270.            
  1271.             if(black.r==12 || black.r==25)
  1272.             {
  1273.                 ccRGBB t;
  1274.                 t.r=9;
  1275.                 [tilemap1 setTile:t at:ccg(j,k)];
  1276.                
  1277.             }
  1278.             //[bag setBagPos:ccp(posx,posy)];
  1279.             CGRect bagFrame = CGRectMake(roundf([bag bagPos].x - 16+6), roundf([bag bagPos].y - 16+6),25,25);
  1280.             NSLog(@"bag frame %f %f",[bag bagPos].x,[bag bagPos].y);       
  1281.            
  1282.             for(int i=0;i<enemyCount ;i++) 
  1283.             {
  1284.                
  1285.                 Enemy *c = (Enemy*)[[self parent] getChildByTag:(300+i)];
  1286.                 CGRect enemyFrame = CGRectMake(roundf([c position].x - 16+6), roundf([c position].y - 16+6),25,25);
  1287.                 NSLog(@"enemy frame %f %f",enemyFrame.origin.x,enemyFrame.origin.y);       
  1288.                 if(CGRectIntersectsRect(enemyFrame, bagFrame)==YES)
  1289.                 {
  1290.                    
  1291.                     [c setReady:YES];
  1292.                     //[c setTransformAnchor:ccp([c transformAnchor].x,[c transformAnchor].y-)];
  1293.                     [c stopAllActions];
  1294.                     /*if([c rotation]==90 || [c rotation]==-90)
  1295.                     {
  1296.                     [c setTransformAnchor:ccp([c transformAnchor].x+30,[c transformAnchor].y)];
  1297.                     [c runAction:[ScaleTo actionWithDuration:2 scaleX:0 scaleY:[c scaleY]+1]];
  1298.                     }
  1299.                     else
  1300.                     {
  1301.                     [c setTransformAnchor:ccp([c transformAnchor].x,[c transformAnchor].y+15)];
  1302.                     [c runAction:[ScaleTo actionWithDuration:2 scaleX:[c scaleX]+1 scaleY:0]];
  1303.                     }*/
  1304.                    
  1305.                 //  [c runAction:[ScaleBy actionWithDuration:2 scaleX:0 scaleY:[c scaleY]+3]];
  1306.                 //  [c runAction:[FadeTo actionWithDuration:1.5 opacity:0]];
  1307.                 //  [(Enem)]
  1308.                     [c runAction:[Spawn actions:[JumpTo actionWithDuration:1.5 position:[c position] height:50 jumps:1],[RotateBy actionWithDuration:1.5 angle:360],[ScaleTo actionWithDuration:1.5 scale:0],nil]];
  1309.                     [self performSelector:@selector(removeEnemy:) withObject:c afterDelay:1.3];
  1310.                     heroScore=heroScore+150;
  1311.                     //[[c parent] removeChildByTag:[c tag] cleanup:YES];
  1312.                 }
  1313.                
  1314.                 Digger *c1 = (Digger*)[[self parent] getChildByTag:007];
  1315.                 CGRect heroFrame = CGRectMake(roundf([c1 position].x - 16+6), roundf([c1 position].y - 16+6),25,25);
  1316.                 if(!bCollide)
  1317.                 {
  1318.                     if(CGRectIntersectsRect(heroFrame, bagFrame)==YES)
  1319.                     {
  1320.                         AudioServicesPlaySystemSound(soundID2);
  1321.                         bCollide=YES;
  1322.                         [(GameLayer*)[self parent] setCanTouch:NO];
  1323.                         [self unschedule:@selector(checkingCoins)];
  1324.                         //[c stopAllActions];
  1325.                         //[c1 stopAllActions];
  1326.                         stopMoving=YES;
  1327.                         [self unschedule:@selector(animateAnt)];
  1328.                         [self unschedule:@selector(waitingAnimation)];
  1329.                         [Digger cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1330.                         [self stopAllActions];
  1331.                         [self heroDeathAnimation];
  1332.                         //[(GameLayer*)[self parent] setCanTouch:YES];
  1333.                         stopMoving=YES;
  1334.                        
  1335.                         mPreDir=@"";
  1336.                         [self performSelector:@selector(heroDied) withObject:nil afterDelay:1.7 ];
  1337.                         //                          [self heroDied];
  1338.                     }
  1339.                 }
  1340.             }
  1341.         }
  1342.         else
  1343.         {
  1344.            
  1345.             [self performSelector:@selector(bagDrop:) withObject:bag afterDelay:0.6];
  1346.             [self unschedule:@selector(bagMovement)];
  1347.             //[self schedule:@selector(checkBagFall) interval:0.2];
  1348.         }
  1349.     }
  1350.     else
  1351.     {
  1352.        
  1353.         [self performSelector:@selector(bagDrop:) withObject:bag afterDelay:0.6];
  1354.         [self unschedule:@selector(bagMovement)];
  1355.         //[self schedule:@selector(checkBagFall) interval:0.2];
  1356.        
  1357.     }
  1358.    
  1359. }
  1360.  
  1361. -(void)removeEnemy:(Enemy*)c
  1362. {
  1363. [[c parent] removeChildByTag:[c tag] cleanup:YES];
  1364. }
  1365. -(void)bagTileRemove:(NSString*)pos
  1366. {
  1367.     int xx=[[[pos componentsSeparatedByString:@"#"] objectAtIndex:0] intValue];
  1368.     int yy=[[[pos componentsSeparatedByString:@"#"] objectAtIndex:1] intValue];
  1369.     ccRGBB s=[tilemap1 tileAt:ccg(xx,yy)];
  1370.     if(s.r==22)
  1371.     {
  1372.         s.r=3;
  1373.         [tilemap1 setTile:s at:ccg(xx,yy)];
  1374.        
  1375.     }
  1376.    
  1377. }
  1378.  
  1379. //After the bag is droped, a coin is generated, which can be taken by digger or enemy.
  1380. -(void)bagDrop:(Bagbomb*)bag1
  1381. {
  1382.     NSLog(@"bag drop %d",[bag1 tag]);
  1383.    
  1384.     coinCount++;
  1385.     Coins *coin = [Coins spriteWithFile:@"money-t5.png"];
  1386.     [coin setCoinPos:ccp([bag1 bagPos].x,[bag1 bagPos].y)];
  1387.     [coin setPosition:ccp([bag1 bagPos].x,[bag1 bagPos].y)];
  1388.     //[coin setScale:0.4];
  1389.     [coin setIsUsed:YES];
  1390.     [[bag1 parent] removeChildByTag:[bag1 tag] cleanup:YES];
  1391.     [[self parent] addChild:coin z:0 tag:500 + coinCount];
  1392.     [coin animateCoins];
  1393.     //[coin schedule:@selector(animateCoins) interval:1.6];
  1394.    
  1395.    
  1396.     [self schedule:@selector(checkBagFall) interval:0.2];
  1397.    
  1398.    
  1399. }
  1400. //In a scheduler for checking coins.
  1401. -(void)checkingCoins
  1402. {
  1403.     for(int h=1;h <= coinCount;h++)
  1404.     {
  1405.         Coins *myCoin = (Coins*)[[self parent] getChildByTag:(500+h)];
  1406.         if(myCoin!=nil)
  1407.         {
  1408.             //NSLog(@"Coin position %f %f",[myCoin coinPos].x,[myCoin coinPos].y);
  1409.             CGRect coinFrame = CGRectMake([myCoin coinPos].x - 16,[myCoin coinPos].y - 16,20,20);
  1410.             CGRect heroFrame = CGRectMake(heroPos.x-16, heroPos.y-16,20,20);
  1411.             if(CGRectIntersectsRect(heroFrame,coinFrame)==YES && bCollide==NO)// && [myCoin isUsed]==YES)
  1412.             {
  1413.                 AudioServicesPlaySystemSound(soundID1);
  1414.                 //[myCoin setIsUsed:NO];
  1415.                 [(Coins*)myCoin flashCoins];
  1416.                 heroScore=heroScore+100;
  1417.                 Label *fs = (Label*)[[self parent] getChildByTag:79];
  1418.                 [fs setString:[NSString stringWithFormat:@"%d",100]];
  1419.                 [fs runAction:[FadeIn actionWithDuration:0.05]];
  1420.                 [fs setPosition:CGPointMake([myCoin coinPos].x,[myCoin coinPos].y)];
  1421.                 [fs runAction:[Sequence actions:[MoveBy actionWithDuration:0.4 position:ccp(0,15)],[FadeOut actionWithDuration:0.05],nil]];
  1422.                 //[[self parent] removeChildByTag:[myCoin tag] cleanup:YES];
  1423.                
  1424.             }
  1425.            
  1426.             for(int i=0;i<enemyCount ;i++)
  1427.             {
  1428.                 Enemy *c = (Enemy*)[[self parent] getChildByTag:(300+i)];
  1429.                 if(c!=nil)
  1430.                 {
  1431.                     CGRect enemyFrame = CGRectMake(roundf([c position].x-16), roundf([c position].y-16),20,20);
  1432.                     if(CGRectIntersectsRect(enemyFrame, coinFrame)==YES)
  1433.                     {
  1434.                         [[self parent] removeChildByTag:[myCoin tag] cleanup:YES];
  1435.                     }
  1436.                 }
  1437.             }
  1438.         }
  1439.     }
  1440. }
  1441. //In a scheduler for checking diamonds.
  1442. -(void)checkingDiamond:(CGPoint)toPoint
  1443. {
  1444.     for(int i=0;i<=gemCount ;i++)
  1445.     {
  1446.         CocosNode *c = [[self parent] getChildByTag:(100+i)];
  1447.         if(toPoint.x == roundf([c position].x) && toPoint.y == roundf([c position].y))
  1448.         {
  1449.            
  1450.             [(Diamond*)c flashGem];
  1451.            
  1452.             AudioServicesPlaySystemSound(soundID1);
  1453.            
  1454.             heroScore=heroScore+100;
  1455.             //nod=number of diamonds
  1456.             nod=nod+1;
  1457.             gemTaken=gemTaken+1;
  1458.             [(Label*)[[self parent] getChildByTag:75] setString:[NSString stringWithFormat:@"%d",heroScore]];
  1459.             [(Label*)[[self parent] getChildByTag:81] setString:[NSString stringWithFormat:@"%d",nod]];
  1460.            
  1461.            
  1462.             id myAction = [Sequence actions:[MoveBy actionWithDuration:0.4 position:ccp(0,15)],[FadeOut actionWithDuration:0.05],nil];
  1463.            
  1464.             if(nod==gemCount)
  1465.             {
  1466.                 NSLog(@"Gems complete");
  1467.                 [self stopAllActions];
  1468.                 [self levelCompletion];
  1469.                            
  1470.             }
  1471.             //[backgroundMusic stopIt];
  1472.             //[diamondTaking playIt];
  1473.             //[backgroundMusic playIt];
  1474.            
  1475.             //[[self parent] removeChildByTag:(100+i) cleanup:YES];
  1476.             //fading score
  1477.             if(!flag)
  1478.             {
  1479.                 Label *fs = (Label*)[[self parent] getChildByTag:79];
  1480.                 [fs setString:[NSString stringWithFormat:@"%d",100]];
  1481.                 [fs runAction:[FadeIn actionWithDuration:0.05]];
  1482.                 [fs setPosition:CGPointMake([c position].x,[c position].y)];
  1483.                 [fs runAction:myAction];
  1484.                 flag=YES;
  1485.             }
  1486.             else
  1487.             {
  1488.                 Label *fs1 = (Label*)[[self parent] getChildByTag:80];
  1489.                 [fs1 setString:[NSString stringWithFormat:@"%d",100]];
  1490.                 [fs1 runAction:[FadeIn actionWithDuration:0.05]];
  1491.                 [fs1 setPosition:CGPointMake([c position].x,[c position].y)];
  1492.                 [fs1 runAction:myAction];
  1493.                 flag=NO;
  1494.             }
  1495.            
  1496.         }
  1497.        
  1498.     }
  1499.     //[levelData release];
  1500. }
  1501. -(void)levelCompletion
  1502. {
  1503.    
  1504.    
  1505.         //[self unschedule:@selector(levelCompletion)];
  1506.         [self unschedule:@selector(checkingCollision)];
  1507.         //[self stopAllActions];
  1508.         [backgroundMusic stopIt];
  1509.         [backgroundMusicWithCarrot stopIt];
  1510.         UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Level Finished" message:@"Congratulation" delegate:self cancelButtonTitle:@"Next Level" otherButtonTitles:@"Quit",nil];
  1511.         [myAlert performSelector:@selector(show) withObject:nil afterDelay:0.5];
  1512.    
  1513.    
  1514. }
  1515. -(void)didPresentAlertView:(UIAlertView *)alertView
  1516. {
  1517.     [[Director sharedDirector] pause];
  1518.    
  1519. }
  1520. -(BOOL)checkIfBag:(CGPoint)toPoint
  1521. {
  1522.    
  1523.     for(int i=0;i<=bagCount;i++)
  1524.     {
  1525.         CocosNode *c = [[self parent] getChildByTag:(200+i)];
  1526.         if(toPoint.x == roundf([c position].x) && toPoint.y == roundf([c position].y))
  1527.         {
  1528.             return YES;
  1529.         }
  1530.        
  1531.     }
  1532.     return NO;
  1533. }
  1534. -(void)soundInitialization
  1535. {
  1536.     /*  NSString *path1=[[NSBundle mainBundle] pathForResource:@"Bell_07" ofType:@"mp3"];
  1537.      AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path1], &soundID1);
  1538.      NSString *path2=[[NSBundle mainBundle] pathForResource:@"Bell_09" ofType:@"mp3"];
  1539.      AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path2], &soundID2);
  1540.      */
  1541. }
  1542. -(void)heroDied
  1543. {
  1544.     [(GameLayer*)[self parent] setCanTouch:NO];
  1545.     //[heroDeadSound playIt];
  1546.    
  1547.    
  1548.     if(heroLife==0 && !flag5)
  1549.     {
  1550.         //[audioPlayer stop];
  1551.             [backgroundMusic stopIt];
  1552.         flag5=YES;
  1553.         int minHighScore1;
  1554.         //code for checking high score
  1555.         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1556.         NSString *documentsDirectory = [paths objectAtIndex:0];
  1557.         NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"HighScores.dat"];
  1558.         NSLog(@"%@",writablePath);
  1559.         NSData *patternData=[NSData dataWithContentsOfFile:writablePath];
  1560.         if(patternData == nil)
  1561.         {
  1562.             NSMutableArray *patternArray = [[NSMutableArray alloc] init];
  1563.             NSDictionary *score1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player 1",[NSNumber numberWithInt:0],nil] forKeys:[NSArray arrayWithObjects:@"Name",@"Score",nil]];
  1564.             NSDictionary *score2 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player 2",[NSNumber numberWithInt:0],nil] forKeys:[NSArray arrayWithObjects:@"Name",@"Score",nil]];
  1565.             NSDictionary *score3 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Player 3",[NSNumber numberWithInt:0],nil] forKeys:[NSArray arrayWithObjects:@"Name",@"Score",nil]];
  1566.             [patternArray addObject:score1];
  1567.             [patternArray addObject:score2];
  1568.             [patternArray addObject:score3];
  1569.             minHighScore1 = [[[patternArray objectAtIndex:2] valueForKey:@"Score"] intValue];
  1570.             [score1 release];
  1571.             [score2 release];
  1572.             [score3 release];
  1573.            
  1574.             NSData *patternData1 = [NSKeyedArchiver archivedDataWithRootObject:patternArray];
  1575.             [patternData1 writeToFile:writablePath atomically:YES];
  1576.             [patternArray release];
  1577.             [patternData release];
  1578.         }
  1579.         else
  1580.         {
  1581.             NSMutableArray *patternArray =  [[NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:patternData]] retain];
  1582.            
  1583.             minHighScore1 = [[[patternArray objectAtIndex:2] valueForKey:@"Score"] intValue];
  1584.         }
  1585.        
  1586.         //[hs setHighScore:score];
  1587.         //[hs displayHighScores];
  1588.         NSLog(@"heroScore %d",heroScore);
  1589.         [self setHeroScore:heroScore];
  1590.        
  1591.         if(heroScore>minHighScore1)
  1592.         {
  1593.             NSLog(@"hero score %d",heroScore);
  1594.             PlayerName *pn = [PlayerName node];
  1595.             [[self parent] addChild:pn z:2 tag:90];
  1596.             [[Director sharedDirector] pause];
  1597.         }
  1598.         //[[Director sharedDirector] replaceScene:hs];
  1599.         else
  1600.         {
  1601.            
  1602.             UIAlertView *myAlert1 = [[UIAlertView alloc] initWithTitle:@"Game Over" message:@"You are dead" delegate:self cancelButtonTitle:@"Play Again" otherButtonTitles:@"Quit",nil];
  1603.             [[Director sharedDirector] pause];
  1604.             [myAlert1 show];
  1605.         }
  1606.     }
  1607.     if(heroLife > 0)
  1608.     {
  1609.         heroLife--;
  1610.         [self setHeroPos:CGPointMake(144,80)];
  1611.         [self setPosition:ccp(144,80)];
  1612.         [self setRotation:0.0f];
  1613.         [self waitingAnimation];
  1614.  
  1615.         [self runAction:[Blink actionWithDuration:1 blinks:3]];
  1616.         [[[self parent] getChildByTag:(76+heroLife)] setVisible:NO];
  1617.         [(GameLayer*)[self parent] setCanTouch:YES];
  1618.         [self schedule:@selector(checkingCoins) interval:0.5];
  1619.         [(GameLayer*)[self parent] enemyMovementAfterHeroDeath];
  1620.     }
  1621.    
  1622. }
  1623.  
  1624. -(void)checkingCollision
  1625. {
  1626.     if(!bCollide){
  1627.         for(int i=0;i<enemyCount ;i++)
  1628.         {  
  1629.            
  1630.             CGRect heroFrame = CGRectMake([[[self parent] getChildByTag:007] position].x-16+3, [[[self parent] getChildByTag:007] position].y-16+3,26,26);
  1631.             //CGRect heroFrame = CGRectMake(heroPos.x - 16 + 3,heroPos.y)
  1632.             Enemy *c = (Enemy*)[[self parent] getChildByTag:(300+i)];
  1633.             //Here ready is opposite
  1634.             if(c!=nil && c.ready==NO)
  1635.             {
  1636.                 CGRect enemyFrame;
  1637.                 if([c isFiring]==YES)
  1638.                 {
  1639.                     NSLog(@"Enemy is firing");
  1640.                     if([c rotation]==0)
  1641.                     {
  1642.                         enemyFrame = CGRectMake(roundf([c position].x-50), roundf([c position].y-16),100,20);
  1643.                     }
  1644.                     else
  1645.                     {
  1646.                         enemyFrame = CGRectMake(roundf([c position].x-16), roundf([c position].y-50),20,100);
  1647.                     }
  1648.                 }
  1649.                 else
  1650.                 {
  1651.                     if([c rotation]==0)
  1652.                     {
  1653.                         enemyFrame = CGRectMake(roundf([c position].x-30+6), roundf([c position].y-16+6),48,20);
  1654.                     }else
  1655.                     {
  1656.                         enemyFrame = CGRectMake(roundf([c position].x-16+6), roundf([c position].y-30+6),20,48);
  1657.                     }
  1658.                 }
  1659.                 if(CGRectIntersectsRect(enemyFrame, heroFrame)==YES)
  1660.                 {
  1661.                    
  1662.                     if([(Digger*)[[self parent] getChildByTag:007] hasCarrot]==NO)
  1663.                     {
  1664.                         AudioServicesPlaySystemSound(soundID2);
  1665.                         bCollide=YES;
  1666.                         [(GameLayer*)[self parent] setCanTouch:NO];
  1667.                         [c stopAllActions];
  1668.                         [c unschedule:@selector(enemyMovement)];
  1669.                         [self stopAllActions];
  1670.                         stopMoving=YES;
  1671.                         [self unschedule:@selector(animateAnt)];
  1672.                         [self unschedule:@selector(waitingAnimation)];
  1673.                         [Digger cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1674.                         [self stopAllActions];
  1675.                         if([c type] == 1)
  1676.                         {
  1677.                             [c setRotation:0];
  1678.                             c.texture = [[TextureMgr sharedTextureMgr] addImage:@"monster1_waiting-1.png"];
  1679.                         }
  1680.                         else
  1681.                         {
  1682.                             [c setRotation:0];
  1683.                             c.texture = [[TextureMgr sharedTextureMgr] addImage:@"monster2_rotation-1.png"];
  1684.                         }
  1685.                         [self heroDeathAnimation];
  1686.                         stopMoving=YES;
  1687.                         //mPreDir=@"";
  1688.                         [self setMPreDir:@""];
  1689.                         //[(GameLayer*)[self parent] setCanTouch:YES];
  1690.                         [self performSelector:@selector(heroDied) withObject:nil afterDelay:1.7];
  1691.                     }
  1692.                     else
  1693.                     {
  1694.                         [c setReady:YES];
  1695.                         heroScore=heroScore+150;
  1696.                         [[c parent] removeChildByTag:[c tag] cleanup:YES];
  1697.                        
  1698.                     }
  1699.                 }
  1700.                            
  1701.             }
  1702.         }
  1703.        
  1704.     }
  1705. }
  1706.  
  1707. - (void)alertView:(UIAlertView *)action clickedButtonAtIndex:(NSInteger)buttonIndex
  1708. {
  1709.     if([[action buttonTitleAtIndex:buttonIndex] isEqualToString:@"Next Level"]==YES)
  1710.     {
  1711.         [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:[[[NSUserDefaults standardUserDefaults] valueForKey:@"current_stage"] intValue] +1] forKey:@"current_stage"];
  1712.         if([[[NSUserDefaults standardUserDefaults] valueForKey:@"stage"] intValue]<[[[NSUserDefaults standardUserDefaults] valueForKey:@"current_stage"] intValue])
  1713.         {
  1714.             [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:[[[NSUserDefaults standardUserDefaults] valueForKey:@"stage"] intValue] +1] forKey:@"stage"];
  1715.         }
  1716.         [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:heroScore] forKey:@"score"];
  1717.         [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:heroLife] forKey:@"life"];
  1718.        
  1719.         //NSLog(@"alert view stage == %d",[[[NSUserDefaults standardUserDefaults] valueForKey:@"stage"]intValue]);
  1720.        
  1721.         GameScene *gs=[GameScene node];
  1722.         [[Director sharedDirector] resume];
  1723.         [[Director sharedDirector] replaceScene:gs];
  1724.        
  1725.     }
  1726.     if([[action buttonTitleAtIndex:buttonIndex] isEqualToString:@"Play Again"]==YES)
  1727.     {
  1728.         GameScene *gs=[GameScene node];
  1729.         [[Director sharedDirector] resume];
  1730.         [[Director sharedDirector] replaceScene:gs];
  1731.     }
  1732.     if(buttonIndex==1)
  1733.     {
  1734.         /*MenuScene *ms=[MenuScene node];
  1735.          [[Director sharedDirector] resume];
  1736.          [[Director sharedDirector] replaceScene:ms];
  1737.          */
  1738.         if([[action message] isEqualToString:@"Congratulation"])
  1739.         {
  1740.         [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithInt:[[[NSUserDefaults standardUserDefaults] valueForKey:@"stage"] intValue] +1] forKey:@"stage"];  
  1741.         }
  1742.        
  1743.         [[Director sharedDirector] resume];
  1744.         NSLog(@"Hero score %d",heroScore);
  1745.         NSDictionary *score = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Prateek",[NSNumber numberWithInt:heroScore],nil] forKeys:[NSArray arrayWithObjects:@"Name",@"Score",nil]];
  1746.         HighScores *hs= [HighScores node];
  1747.         [hs setHighScore:score];
  1748.         [hs displayHighScores];
  1749.         [[Director sharedDirector] replaceScene:hs];
  1750.        
  1751.     }
  1752. }
  1753. -(void)checkingCarrots
  1754. {
  1755.     for(int h=0;h < carrotCount;h++)
  1756.     {
  1757.         Carrot *myCarrot = (Carrot*)[[self parent] getChildByTag:600+h];
  1758.        
  1759.         CGRect carrotFrame = CGRectMake([myCarrot carrotPos].x,[myCarrot carrotPos].y,20,20);
  1760.         CGRect heroFrame = CGRectMake(heroPos.x, heroPos.y,20,20);
  1761.        
  1762.         if(CGRectIntersectsRect(heroFrame,carrotFrame)==YES && !entered)
  1763.         {
  1764.             //id carrotAction=[Blink actionWithDuration:15 blinks:40];
  1765.             [(Digger*)[[self parent] getChildByTag:007] setHasCarrot:YES];
  1766.             [[self parent] removeChildByTag:600+h cleanup:YES];
  1767.             //[[[self parent] getChildByTag:007] runAction:carrotAction];
  1768.             [backgroundMusic stopIt];
  1769.             //backgroundMusicWithCarrot = [[Sound alloc] initWithSound:@"Dance_04" ofType:@"mp3"];
  1770.             //[backgroundMusicWithCarrot setRepeat:YES];
  1771.             [backgroundMusicWithCarrot playIt];
  1772.             [self schedule:@selector(powerOver) interval:10];
  1773.             for(int i=0;i<enemyCount ;i++)
  1774.             {
  1775.                 Enemy *c = (Enemy*)[[self parent] getChildByTag:(300+i)];
  1776.                 if(c!=nil)
  1777.                 {
  1778.                     [c setR:[c r]+30];
  1779.                 }
  1780.             }
  1781.         }
  1782.     }
  1783.    
  1784.    
  1785. }
  1786. -(void)powerOver
  1787. {
  1788.     [self unschedule:@selector(powerOver)];
  1789.     [backgroundMusicWithCarrot stopIt];
  1790.     [backgroundMusic playIt];
  1791.     [(Digger*)[[self parent] getChildByTag:007] setHasCarrot:NO];
  1792.     for(int i=0;i<enemyCount ;i++)
  1793.     {
  1794.         Enemy *c = (Enemy*)[[self parent] getChildByTag:(300+i)];
  1795.         if(c!=nil)
  1796.         {
  1797.             [c setR:[c r]-30];
  1798.         }
  1799.     }
  1800.    
  1801. }
  1802. -(void)animateAnt  
  1803. {
  1804.     id action1;
  1805.    
  1806.     if([[self mDir] isEqualToString:@"LEFT"]==YES)
  1807.     {
  1808.         if(heroPos.x > 32)
  1809.         {
  1810.             [self turnLeftAnimation:1];
  1811.             //[self unschedule:@selector(waitingAnimation)];
  1812.             //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1813.             [self setRotation:0];
  1814.            
  1815.             id animation = [Animation animationWithName:@"antAnimate" delay:0.15];
  1816.             for( int i=1;i<=10;i++)
  1817.             {
  1818.                 [animation addFrame: [NSString stringWithFormat:@"rabbit-go_left%d.png", i]];
  1819.             }
  1820.             action1 = [Animate actionWithAnimation: animation];
  1821.             [self runAction:action1];
  1822.             //[self runAction:[Sequence]]
  1823.         }
  1824.        
  1825.     }
  1826.     else if([[self mDir] isEqualToString:@"RIGHT"]==YES)
  1827.     {
  1828.         if(heroPos.x < 288)
  1829.         {
  1830.             [self unschedule:@selector(waitingAnimation)];
  1831.             //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1832.             [self setRotation:0];
  1833.             id animation1 = [Animation animationWithName:@"antAnimate1" delay:0.15];
  1834.             for( int i=1;i<=10;i++)
  1835.             {
  1836.                 [animation1 addFrame: [NSString stringWithFormat:@"rabbit-go_right%d.png", i]];
  1837.             }
  1838.             action1 = [Animate actionWithAnimation: animation1];
  1839.             [self runAction:action1];
  1840.         }
  1841.        
  1842.     }
  1843.     else if([[self mDir] isEqualToString:@"DOWN"]==YES )
  1844.        
  1845.     {
  1846.         if(heroPos.y > 80)
  1847.         {
  1848.             [self unschedule:@selector(waitingAnimation)];
  1849.             //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1850.             [self setRotation:90];
  1851.             id animation1 = [Animation animationWithName:@"antAnimate1" delay:0.15];
  1852.             for( int i=1;i<=10;i++)
  1853.             {
  1854.                 [animation1 addFrame: [NSString stringWithFormat:@"rabbit-go_right%d.png", i]];
  1855.             }
  1856.             action1 = [Animate actionWithAnimation: animation1];
  1857.             [self runAction:action1];
  1858.         }
  1859.        
  1860.        
  1861.     }
  1862.     else if([[self mDir] isEqualToString:@"UP"]==YES)
  1863.     {
  1864.  
  1865.         if(heroPos.y < 432)
  1866.             {
  1867.            
  1868.             [self unschedule:@selector(waitingAnimation)];
  1869.             //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(waitingAnimation) object:nil];
  1870.            
  1871.             [self setRotation:90];
  1872.             id animation1 = [Animation animationWithName:@"antAnimate1" delay:0.15];
  1873.             for( int i=1;i<=10;i++)
  1874.             {
  1875.                 [animation1 addFrame: [NSString stringWithFormat:@"rabbit-go_left%d.png", i]];
  1876.             }
  1877.             action1 = [Animate actionWithAnimation: animation1];
  1878.             [self runAction:action1];
  1879.            
  1880.         }
  1881.         //}
  1882.        
  1883.     }
  1884.     else if([[self mDir] isEqualToString:@""]==YES)
  1885.     {
  1886.         [self unschedule:@selector(waitingAnimation)];
  1887.  
  1888.         //[action1 step:1];
  1889.         //[self stopAction:action1];
  1890.         //[self stopAllActions];
  1891.         //[self setRotation:0];
  1892.         //[self performSelector:@selector(waitingAnimation) withObject:nil afterDelay:1];
  1893.         /*id animation = [Animation animationWithName:@"antAnimate" delay:0.1];
  1894.          for( int i=1;i<=10;i++)
  1895.          {
  1896.          [animation addFrame: [NSString stringWithFormat:@"rabbit-go_left%d.png", i]];
  1897.          }
  1898.          id action = [Animate actionWithAnimation: animation];
  1899.          [self runAction:action];
  1900.          */
  1901.     }
  1902.    
  1903. }
  1904. -(void) heroDeathAnimation
  1905. {
  1906.    
  1907.     [self setRotation:0];
  1908.     id animation = [Animation animationWithName:@"deathAnimate" delay:0.2];
  1909.    
  1910.    
  1911.     for( int i=1;i<=9;i++)
  1912.     {
  1913.         [animation addFrame: [NSString stringWithFormat:@"rabbit-death%d.png", i]];
  1914.     }
  1915. //  id action = [Animate actionWithAnimation: animation];
  1916.     //  bCollide=NO;
  1917.     //  [self runAction:[Sequence actions:action,[Blink actionWithDuration:0.1 blinks:1],nil]];
  1918.     [self runAction:[Animate actionWithAnimation: animation]];
  1919. }
  1920. -(void)waitingAnimation
  1921. {
  1922.    
  1923.     id animation = [Animation animationWithName:@"antAnimate" delay:0.2];
  1924.     for( int i=1;i<=4;i++)
  1925.     {
  1926.         [animation addFrame: [NSString stringWithFormat:@"rabbit-wait%d.png", i]];
  1927.     }
  1928.     id action = [Animate actionWithAnimation: animation];
  1929.     [self runAction:action];
  1930.    
  1931.     [self schedule:@selector(waitingAnimation) interval:0.7];
  1932. }
  1933. -(void)turnLeftAnimation:(float)duration
  1934. {
  1935.     [self unschedule:@selector(animateAnt)];
  1936.     id turnLeft = [Animation animationWithName:@"turnLeft" delay:duration/8];
  1937.     for(int i = 1 ;i<=8; i++)
  1938.     {
  1939.         [turnLeft addFrame:[NSString stringWithFormat:@"rabbit-turn_left%d.png",i]];
  1940.     }
  1941.     [self runAction:[Animate actionWithAnimation:turnLeft]];
  1942.    
  1943.     [self schedule:@selector(animateAnt) interval:0.4];
  1944. }
  1945. -(void)turnRightAnimation:(float)duration
  1946. {
  1947.     id turnRight = [Animation animationWithName:@"turnRight" delay:duration/7];
  1948.     for(int i = 1; i<=7; i++)
  1949.     {
  1950.         [turnRight addFrame:[NSString stringWithFormat:@"rabbit-turn_right%d.png",i]];
  1951.     }
  1952.     [self runAction:[Animate actionWithAnimation:turnRight]];
  1953.     [self schedule:@selector(animateAnt) interval:0.4];
  1954. }
  1955.  
  1956. -(void)emitParticles:(CGPoint)point
  1957. {
  1958.     ParticleFireworks *emitter = [ParticleFireworks node];
  1959.     emitter.angle=0;
  1960.     emitter.totalParticles =15;
  1961.     [emitter setDuration:0.5];
  1962.     [emitter setAngleVar:20];
  1963.     [emitter setRadialAccel:10];
  1964.     [emitter setSpeed:15];
  1965.     [emitter setSpeedVar:10];
  1966.     [emitter setGravity:ccp(0,-90)];
  1967.     [emitter setSize:5];
  1968.     [emitter setLife:0.5];
  1969.     [emitter setPosition:point];
  1970.     [[self parent] addChild:emitter z:3];
  1971. }
  1972.  
  1973. @end   
  1974.  
  1975.  
  1976.  
  1977. @implementation PlayerName
  1978.  
  1979. @synthesize textField;
  1980.  
  1981. -(id)init
  1982. {
  1983.     self=[super init];
  1984.     if(self != nil)
  1985.     {
  1986.         /*Sprite *background =[Sprite spriteWithFile:@"Black_Granite_Tile_320.png"];
  1987.          [background setPosition:ccp(160,240)];
  1988.          [self addChild:background];
  1989.          */
  1990.         isTouchEnabled=YES;
  1991.        
  1992.         Label *congs    = [Label labelWithString:@"Congratulations" dimensions:CGSizeMake(250, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:35];
  1993.         Label *mess     = [Label labelWithString:@"You create the high score" dimensions:CGSizeMake(300, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:20];
  1994.         Label *en       = [Label labelWithString:@"Enter your name" dimensions:CGSizeMake(250, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:20];
  1995.         Label *submit   = [Label labelWithString:@"Subsmit Scores" dimensions:CGSizeMake(250, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:30];
  1996.         Label *yes      = [Label labelWithString:@"YES" dimensions:CGSizeMake(150, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:30];
  1997.         Label *no       = [Label labelWithString:@"NO" dimensions:CGSizeMake(150, 50) alignment:UITextAlignmentCenter fontName:@"Helvetica" fontSize:30];
  1998.        
  1999.        
  2000.         [congs setPosition:ccp(160,380)];
  2001.         [congs setRGB:0 :255 :0];
  2002.        
  2003.         [mess setPosition:ccp(160,320)];
  2004.         [mess setRGB:255 :0 :0];
  2005.        
  2006.         [en setPosition:ccp(160,280)];
  2007.         [en setRGB:255 :0 :0];
  2008.        
  2009.         [submit setPosition:ccp(160,120)];
  2010.         [submit setRGB:255 :0 :0];
  2011.        
  2012.         [yes setPosition:ccp(130,70)];
  2013.         [yes setRGB:255 :0 :0];
  2014.        
  2015.         [no setPosition:ccp(210,70)];
  2016.         [no setRGB:255 :0 :0];
  2017.        
  2018.         [self addChild:congs];
  2019.         [self addChild:mess];
  2020.         [self addChild:en];
  2021.         [self addChild:submit];
  2022.         [self addChild:yes];
  2023.         [self addChild:no];
  2024.         // Putting text field
  2025.        
  2026.         textField=[[UITextField alloc] initWithFrame:CGRectMake(80,220,150,30)];
  2027.         [[[Director sharedDirector] openGLView] addSubview:textField];
  2028.         [[[Director sharedDirector] openGLView] bringSubviewToFront:textField];
  2029.         [textField becomeFirstResponder];
  2030.        
  2031.         [textField setDelegate:self];
  2032.         [textField setBorderStyle:UITextBorderStyleRoundedRect];
  2033.        
  2034.     }
  2035.     return self;
  2036.    
  2037. }
  2038. - (BOOL)textFieldShouldReturn:(UITextField *)textField1 {
  2039.     [textField1 resignFirstResponder];
  2040.     return NO;
  2041. }
  2042.  
  2043. - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  2044. {
  2045.     UITouch *touch = [touches anyObject];
  2046.     CGPoint gestureStartPoint1 = [touch locationInView:[touch view]];
  2047.     NSLog(@"gestuere1 %f %f",gestureStartPoint1.x,gestureStartPoint1.y);
  2048.     if(gestureStartPoint1.x >= 106 && gestureStartPoint1.y >= 391 && gestureStartPoint1.x <= 160 && gestureStartPoint1.y <= 413 )
  2049.     {
  2050.         NSDictionary *score1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[textField text],[NSNumber numberWithInt:[(Digger*)[(GameLayer*)[self parent] getChildByTag:007] heroScore]],nil] forKeys:[NSArray arrayWithObjects:@"Name",@"Score",nil]];
  2051.         HighScores *hs = [HighScores node];
  2052.         [hs setHighScore:score1];
  2053.         [hs displayHighScores];
  2054.        
  2055.         [textField removeFromSuperview];
  2056.         [[Director sharedDirector] replaceScene:hs];
  2057.     }
  2058.     else if(gestureStartPoint1.x >= 190 && gestureStartPoint1.y >= 391 && gestureStartPoint1.x <= 230 && gestureStartPoint1.y <= 413 )
  2059.     {
  2060.         HighScores *hs = [HighScores node];
  2061.         [hs displayHighScores];
  2062.         [textField removeFromSuperview];
  2063.         [[Director sharedDirector] replaceScene:hs];
  2064.     }
  2065.     return;
  2066. }
  2067. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement