Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. @implementation MyScene {
  2. ///////// PLAYER VARIABLES ///////////////////
  3. SKSpriteNode *_Player;
  4. NSArray *_PlayerAnimation;
  5. SKSpriteNode *MyBackground;
  6. SKLabelNode *MyScoreLabel;
  7. SKSpriteNode *cannonbullet;
  8. SKSpriteNode *bullet;
  9. BOOL fireCannon;
  10. CGPoint destination;
  11. NSArray *_enemy;
  12. BOOL EnemyHit;
  13. }
  14.  
  15.  
  16.  
  17. - (id) initWithSize:(CGSize)size {
  18. if (self = [super initWithSize:size]) {
  19. Enemyhit = false;
  20. if (Enemyhit == true) {
  21. [self CollisionWithEnemy];
  22. }
  23. }
  24. return self;
  25. }
  26.  
  27. - (void) EnemyDyingAnimation {
  28. /////////// This section is only for enemy's dying animation //////////
  29. NSMutableArray *EnemyBlowingFrames = [NSMutableArray array];
  30. SKTextureAtlas *EnemyAnimatedAtlas = [SKTextureAtlas atlasNamed:@“enemyFolder"];
  31. int numFrames = EnemyAnimatedAtlas.textureNames.count;
  32. for (int i=1; i <= numFrames/2; i++) {
  33. NSString *textureName = [NSString stringWithFormat:@“enemy%d", i];
  34. SKTexture *temp = [EnemyAnimatedAtlas textureNamed:textureName];
  35. [EnemyBlowingFrames addObject:temp];
  36. }
  37. _enemy = EnemyBlowingFrames;
  38. SKTexture *temp2 = _enemy[0];
  39. Enemy = [SKSpriteNode spriteNodeWithTexture:temp2];
  40. Enemy.position = CGPointMake(self.size.width/2, self.size.height/2);
  41. Enemy.name = @"ForEnemy";
  42. [self addChild:Enemy];
  43. }
  44. - (void) CollisionWithEnemy {
  45. [self enumerateChildNodesWithName:@"ForEnemy" usingBlock:^(SKNode *node, BOOL *stop){
  46. bullet = (SKSpriteNode *)node;
  47. if (CGRectIntersectsRect(bullet.frame, Enemy.frame)) {
  48. Enemyhit = true;
  49. [Enemy runAction:[SKAction animateWithTextures:_enemy timePerFrame:0.1f resize:NO restore:NO] withKey:@“Ehit"]; return;
  50. }
  51. }];
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement