Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)placeBomb
- {
- NSLog(@"Bomb placed");
- _circle = [[CCSprite alloc]initWithFile:@"Circle.png"];
- CGPoint circle0position = ccp(_cat.position.x , _cat.position.y);
- CGPoint c0TileCoordt = [self tileCoordForPosition:circle0position];
- CGPoint c0TileCoord = [self positionForTileCoord:c0TileCoordt];
- _circle.position = c0TileCoord;
- [self addChild:_circle];
- id fade = [CCScaleTo actionWithDuration:3.5 scale:0];
- [_circle runAction:fade];
- double delayInSeconds = 3.0;
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- [self explosionFromPoint:c0TileCoordt withSprite:_circle];
- });
- }
- - (BOOL)isLocationBombable:(CGPoint)tileCoord;
- {
- if ([self isValidTileCoord:tileCoord] && ![self isWallAtTileCoord:tileCoord])
- {
- NSLog(@"Location bombable");
- return YES;
- }
- else
- {
- return NO;
- NSLog(@"Location not bombable %@",CGPointCreateDictionaryRepresentation(tileCoord));//It works as supposed but this never returns so might be waste
- }
- }
- -(void)explosionFromPoint:(CGPoint)explosionPoint withSprite:(CCSprite*)sprite;
- {
- //int
- explosionLenght += 1;
- if (explosionLenght >= 7) //Just for testing purposes, obviously
- {
- explosionLenght = 1;
- }
- BOOL topB = YES;
- BOOL leftB = YES;
- BOOL bottomB = YES;
- BOOL rightB = YES;
- int bombX = (explosionPoint.x + 1);
- int bombY = (explosionPoint.y + 1);
- int bombNegX = (explosionPoint.x - 1);
- int bombNegY = (explosionPoint.y - 1);
- CGPoint top = ccp(explosionPoint.x, bombY);
- CGPoint left = ccp(bombNegX, explosionPoint.y);
- CGPoint bottom = ccp(explosionPoint.x, bombNegY);
- CGPoint right = ccp(bombX, explosionPoint.y);
- if (![self isLocationBombable:top])
- {topB = NO;}
- if (![self isLocationBombable:left])
- {leftB = NO;}
- if (![self isLocationBombable:bottom])
- {bottomB = NO;}
- if (![self isLocationBombable:right])
- {rightB = NO;}
- for (int i = 0; i <= explosionLenght; i++) {
- int bombX = (explosionPoint.x + i);
- int bombY = (explosionPoint.y + i);
- int bombNegX = (explosionPoint.x - i);
- int bombNegY = (explosionPoint.y - i);
- CGPoint top = ccp(explosionPoint.x, bombY);
- CGPoint left = ccp(bombNegX, explosionPoint.y);
- CGPoint bottom = ccp(explosionPoint.x, bombNegY);
- CGPoint right = ccp(bombX, explosionPoint.y);
- CCSprite *circleTop = [[CCSprite alloc]initWithFile:@"Circle.png"];
- CCSprite *circleLeft = [[CCSprite alloc]initWithFile:@"Circle.png"];
- CCSprite *circleBottom = [[CCSprite alloc]initWithFile:@"Circle.png"];
- CCSprite *circleRight = [[CCSprite alloc]initWithFile:@"Circle.png"];
- if ([self isLocationBombable:top] && topB == YES)
- {
- circleTop.position = [self positionForTileCoord:top];
- [self addChild:circleTop];
- id fadeTop = [CCSequence actionOne:[CCMoveTo actionWithDuration:1 position:circleTop.position] two:[CCScaleTo actionWithDuration:1 scale:0]];
- [circleTop runAction:fadeTop];
- }
- if ([self isLocationBombable:left] && leftB == YES)
- {
- circleLeft.position = [self positionForTileCoord:left];
- [self addChild:circleLeft];
- id fadeLeft = [CCSequence actionOne:[CCMoveTo actionWithDuration:1 position:circleLeft.position] two:[CCScaleTo actionWithDuration:1 scale:0]];
- [circleLeft runAction:fadeLeft];
- }
- if ([self isLocationBombable:bottom] && bottomB == YES)
- {
- circleBottom.position = [self positionForTileCoord:bottom];
- [self addChild:circleBottom];
- id fadeBottom = [CCSequence actionOne:[CCMoveTo actionWithDuration:1 position:circleBottom.position] two:[CCScaleTo actionWithDuration:1 scale:0]];
- [circleBottom runAction:fadeBottom];
- }
- if ([self isLocationBombable:right] && rightB == YES)
- {
- circleRight.position = [self positionForTileCoord:right];
- [self addChild:circleRight];
- id fadeRight = [CCSequence actionOne:[CCMoveTo actionWithDuration:1 position:circleRight.position] two:[CCScaleTo actionWithDuration:1 scale:0]];
- [circleRight runAction:fadeRight];
- }
- }
- NSLog(@"Explosion done, call checkdamage");
- [currentBombs addObject:sprite];
- int cBCount = [currentBombs count];
- NSLog(@"amount of bombs in array %i",cBCount);
- [self schedule:@selector(checkDamageForBomb)];
- }
- -(void)stopCheckDamage{
- NSLog(@"StopCheckDamage");
- [self unschedule:@selector(checkDamageForBomb)];
- }
- -(void)checkDamageForBomb{
- for (CCSprite* bomb in currentBombs)
- {
- CGPoint bombPos = [self tileCoordForPosition:bomb.position];
- for (int i = 0; i <= explosionLenght; i++) {
- CGPoint playerPos = [self tileCoordForPosition:_cat.position];
- int bombX = (bombPos.x + i);
- int bombY = (bombPos.y + i);
- int bombNegX = (bombPos.x - i);
- int bombNegY = (bombPos.y - i);
- CGPoint centre = bombPos;
- CGPoint top = ccp(centre.x, bombY);
- CGPoint left = ccp(bombNegX, centre.y);
- CGPoint bottom = ccp(centre.x, bombNegY);
- CGPoint right = ccp(bombX, centre.y);
- //pastebin.com/biuQBfnv
- if (CGPointEqualToPoint(top, playerPos) || CGPointEqualToPoint(left, playerPos) || CGPointEqualToPoint(bottom, playerPos) || CGPointEqualToPoint(right, playerPos))
- {
- NSLog(@"Player hit");
- [currentBombs removeObject:bomb];
- if ([currentBombs count] == 0)
- {
- [self stopCheckDamage];
- }
- break;
- }
- }
- }
- double delayInSeconds = 3.0;
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- [self stopCheckDamage];
- });
- // [self performSelector:@selector(stopCheckDamage) withObject:nil afterDelay:5];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement