Destroy enemies

This commit is contained in:
Yann Esposito (Yogsototh) 2012-02-06 00:05:34 +01:00
parent 37ef9d5617
commit ea3410f491
10 changed files with 44 additions and 12 deletions

View file

@ -154,6 +154,8 @@
F8D5DB11142DBB2E00C2A769 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F8D5DB10142DBB2E00C2A769 /* main.m */; };
F8D5DB14142DBB2E00C2A769 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F8D5DB13142DBB2E00C2A769 /* AppDelegate.m */; };
F8D5DB17142DBB2E00C2A769 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8D5DB16142DBB2E00C2A769 /* RootViewController.m */; };
F8DD4BC514DF38B900D83062 /* explode-hd.png in Resources */ = {isa = PBXBuildFile; fileRef = F8DD4BC314DF38B900D83062 /* explode-hd.png */; };
F8DD4BC614DF38B900D83062 /* explode.png in Resources */ = {isa = PBXBuildFile; fileRef = F8DD4BC414DF38B900D83062 /* explode.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -433,6 +435,8 @@
F8D5DB15142DBB2E00C2A769 /* RootViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = "<group>"; };
F8D5DB16142DBB2E00C2A769 /* RootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
F8D5DB1B142DBB2E00C2A769 /* GameConfig.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GameConfig.h; sourceTree = "<group>"; };
F8DD4BC314DF38B900D83062 /* explode-hd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "explode-hd.png"; path = "Resources/sprites/explode-hd.png"; sourceTree = "<group>"; };
F8DD4BC414DF38B900D83062 /* explode.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = explode.png; path = Resources/sprites/explode.png; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -475,6 +479,8 @@
F85DCC04142E0EEB00BB6491 /* Sprites */ = {
isa = PBXGroup;
children = (
F8DD4BC314DF38B900D83062 /* explode-hd.png */,
F8DD4BC414DF38B900D83062 /* explode.png */,
F844AAEA14D589D700FED535 /* pentacleOne-hd.png */,
F844AAED14D589DE00FED535 /* pentacleOne.png */,
F844AAEF14D58F4200FED535 /* pentacleOneBullet-hd.png */,
@ -994,6 +1000,8 @@
F844AAEE14D589DE00FED535 /* pentacleOne.png in Resources */,
F844AAF114D58F4200FED535 /* pentacleOneBullet-hd.png in Resources */,
F844AAF214D58F4200FED535 /* pentacleOneBullet.png in Resources */,
F8DD4BC514DF38B900D83062 /* explode-hd.png in Resources */,
F8DD4BC614DF38B900D83062 /* explode.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -42,6 +42,7 @@
-(void) addEnemy:(Enemy *)enemy;
-(void) removeEnemy:(Enemy *)enemy;
-(void) populate:(int)n;
-(void) autoPopulate:(ccTime)dt;
-(void) colisionOccured;
-(void) updateScoreLabel;

View file

@ -72,8 +72,10 @@
scoreLabel.position = ccp(winSize.width - 92,winSize.height - 12);
[self addChild:scoreLabel z:19];
lastNumber = 2;
[self populate:lastNumber];
lastNumber = 0;
[self autoPopulate:0];
[self setScore:0];
self.isTouchEnabled = YES;
@ -95,6 +97,20 @@
[self setScore:score + n * 5];
}
- (int) lastNumberIteration:(int)n {
return n + n/4 + 1;
}
- (void) autoPopulate:(ccTime)dt {
NSLog(@"autoPopulate");
lastNumber = (lastNumber<1)?1:[self lastNumberIteration: lastNumber ];
[self populate:lastNumber];
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:3.0],
[CCCallFunc actionWithTarget:self selector:@selector(autoPopulate:)],
nil]];
}
-(void) updateScoreLabel
{
[scoreLabel setString: [NSString stringWithFormat:@"%d", score]];
@ -111,10 +127,6 @@
[self removeChild:ysprite cleanup:YES];
}
[yspriteToRemove removeAllObjects];
if ([spriteSet count] == 0) {
lastNumber *= 2;
[self populate: lastNumber];
}
}
// Add / Remove bullet

View file

@ -38,6 +38,8 @@
}
- (void)update:(ccTime)dt {
if (!sprite) return;
// detect out of windows
sprite.position = ccpAdd(sprite.position, speed);

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View file

@ -21,7 +21,7 @@
CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"pentacleOneBullet.png"];
sprite = [[CCSprite alloc] initWithTexture:texture];
sprite.position = fromPosition;
collisionDistance=sprite.boundingBoxInPixels.size.width;
collisionDistance=sprite.boundingBoxInPixels.size.width + sprite.boundingBoxInPixels.size.height;
speed = initSpeed;
[self addChild:sprite];
}
@ -29,7 +29,11 @@
}
- (void)collisionOccured {
// Make bullet destruction animation
[CCCallFuncN actionWithTarget:father selector:@selector(removeSSBullet:)];
}
- (void)disapear
{
[self removeChild:sprite cleanup:YES];
}
- (void)cancelled {
@ -38,13 +42,16 @@
- (void)update:(ccTime)dt {
if (!sprite) return;
// update position
sprite.position = ccpAdd(sprite.position, ccpMult(speed,dt));
// detect collision
for (Enemy *enemy in father.enemis) {
CGPoint vectFromSpriteToEnemy = ccpSub(enemy.position, sprite.position);
if (ccpLength(vectFromSpriteToEnemy) < collisionDistance) {
CGFloat distance = ccpLength(ccpSub(enemy.sprite.position, sprite.position));
// NSLog(@"%f < %d",distance, collisionDistance);
if (distance < collisionDistance) {
[enemy collisionOccured];
[self collisionOccured];
}

View file

@ -38,8 +38,10 @@
- (void)update:(ccTime)dt {}
- (void)shoot {}
- (void)collisionOccured {}
- (void)collisionOccured {
// [sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"explode.png"]];
[CCCallFuncN actionWithTarget:father selector:@selector(removeEnemy:)];
}
- (void) dealloc
{
[sprite release];