Created
November 4, 2013 21:54
-
-
Save gscalzo/7309811 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)setupInvaders { | |
NSMutableArray *start = [NSMutableArray array]; | |
for (int i = 0; i < kInvaderRowCount*kInvaderColCount; ++i) { | |
[start addObject:@(i)]; | |
} | |
CGPoint baseOrigin = CGPointMake(kInvaderSize.width / 2, 180); | |
RACSequence *aliens = [start.rac_sequence map:^(id value){ | |
NSUInteger row = [value integerValue]/kInvaderColCount; | |
NSUInteger col = [value integerValue]%kInvaderColCount; | |
CGPoint invaderPosition = CGPointMake(col * (kInvaderSize.width + kInvaderGridSpacing.width) + baseOrigin.x, | |
row * (kInvaderGridSpacing.height + kInvaderSize.height) + baseOrigin.y); | |
SKColor *invaderColor = @[[SKColor redColor], [SKColor greenColor], [SKColor blueColor]][row%3]; | |
SKSpriteNode* invader = [SKSpriteNode spriteNodeWithColor:invaderColor size:kInvaderSize]; | |
invader.name = kInvaderName; | |
invader.position = invaderPosition; | |
[self addChild:invader]; | |
return invader; | |
}]; | |
[aliens all:^BOOL(id value) { | |
return YES; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment