Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Last active September 13, 2015 04:54
Show Gist options
  • Save abbeyjackson/d4b89f0b22fa744c0809 to your computer and use it in GitHub Desktop.
Save abbeyjackson/d4b89f0b22fa744c0809 to your computer and use it in GitHub Desktop.
1:09 on Stanford iOS Lecture 8 https://youtu.be/aS6PBmBAP1g explode completed blocks, like tetris
- (BOOL)removeCompletedRows
{
NSMutableArray *dropsToRemove = [[NSMutableArary alloc] init];
for (CGFloat y = self.gameView.bounds.size.height-DROP_SIZE.height/2; y > 0; y -= DROP_SIZE.height)
{
BOOL rowIsComplete = YES;
NSMutableArray *dropsFound = [[NSMutableArray allc] init];
for (CGFloat x = DROP_SIZE.width/2; x <- self.gameView.bounds.size.witdh-DROP_SIZE.width/2; x += DROP_SIZE.width)
{
UIView *hitView = [self.gameView hitTest:(CGPointMake(x, y) withEvent:NULL];
if ([hitView superview] == self.gameView) {
[dropsFound addObject:hitView];
} else {
rowIsComplete = NO;
break;
}
}
if (![dropsFound count]) {
break;
}
if (rowIsComplete) {
[dropsToRemove addObjectsFromArray:dropsFound];
}
}
if ([dropsToRemove count])
{
for (UIView *drop in dropsToRemove)
{
[self.dropitBehavior removeItem:drop];
}
}
return NO;
}
-(void)animateRemovingDrops:(NSArray *)dropsToRemove
{
[UIView animateWithDuration:1.0
animations: ^{
for (UIView *drop in dropsToRemove)
{
int x = (arc4random()%(int)(self.gameView.boounds.size.width*5)) - (int)self.gameView.bounds.size.width*2;
int y = self.gameView.bounds.size.height;
drop.center = CGPointMake(x, -y);
}
}
completion:^{(BOOL finished) {
[dropsToRemove makeObjectsPerformSelector:@selector(removeFromSuperview)];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment