Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. SKAction *shoot = [SKAction moveTo:CGPointMake(2000*cosf(enemy.zRotation),2000*sinf(enemy.zRotation)) duration:5];
  2. SKAction *remove = [SKAction removeFromParent];
  3.  
  4. [bullet runAction:[SKAction sequence:@[shoot,remove]]];
  5.  
  6. @implementation MyScene
  7. {
  8. SKSpriteNode *ship1;
  9. SKShapeNode *beam1;
  10. }
  11.  
  12. -(id)initWithSize:(CGSize)size
  13. {
  14. if (self = [super initWithSize:size])
  15. {
  16. //self.physicsWorld.contactDelegate = self;
  17. [self createSpaceships];
  18. }
  19. return self;
  20. }
  21.  
  22.  
  23. -(void)createSpaceships
  24. {
  25. ship1 = [SKSpriteNode spriteNodeWithColor:[SKColor blueColor] size:CGSizeMake(50, 50)];
  26. ship1.position = CGPointMake(300, 150);
  27. ship1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:ship1.size];
  28. ship1.physicsBody.dynamic = NO;
  29. [self addChild:ship1];
  30.  
  31. SKSpriteNode *frontOfShip = [SKSpriteNode spriteNodeWithColor:[SKColor grayColor] size:CGSizeMake(2, 50)];
  32. frontOfShip.position = CGPointMake(25, 0);
  33. [ship1 addChild:frontOfShip];
  34. }
  35.  
  36. // touch the left side of the screen to rotate the ship by +0.0785398 radians
  37. // touch the right hand side of the screen to fire laser
  38.  
  39. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  40. {
  41. UITouch *touch = [touches anyObject];
  42. CGPoint touchLocation = [touch locationInNode:self.scene];
  43.  
  44. if(touchLocation.x < self.size.width/2) // left side of screen
  45. {
  46. SKAction *block0 = [SKAction runBlock:^{
  47. ship1.zRotation = ship1.zRotation +0.0785398;
  48. }];
  49. [self runAction:block0];
  50. } else // right side of screen
  51. {
  52. int x = ship1.position.x + 1000 * cos(ship1.zRotation);
  53. int y = ship1.position.y + 1000 * sin(ship1.zRotation);
  54.  
  55. beam1 = [SKShapeNode node];
  56. CGMutablePathRef pathToDraw = CGPathCreateMutable();
  57. CGPathMoveToPoint(pathToDraw, NULL, ship1.position.x, ship1.position.y);
  58. CGPathAddLineToPoint(pathToDraw, NULL, x, y);
  59. beam1.path = pathToDraw;
  60. [beam1 setStrokeColor:[UIColor redColor]];
  61. [self addChild:beam1];
  62. }
  63. }
  64.  
  65. -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  66. {
  67. //[beam1 removeFromParent];
  68. }
  69.  
  70. -(void)update:(CFTimeInterval)currentTime
  71. {
  72. //
  73. }
  74.  
  75. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement