im really new to cocos2d and i downloaded this open source app.
what im trying to do is to put enemies on the app and hopefully add some other functions
i have successfully added the enemies however im stucked at this collision detection. as i said im new to cocos2d and i really dont know anything about
box2d and chipmunk.. i dont have knowledge in java or in c++
maybe there's some other way to detect collision??
here a sample of my code:
Code:
- (id)init {
// NSLog(@"Game::init");
if(![super init]) return nil;
gameSuspended = YES;
AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
[self initPlatforms];
AtlasSprite *bird = [AtlasSprite spriteWithRect:CGRectMake(608,16,44,32) spriteManager:spriteManager];
[spriteManager addChild:bird z:4 tag:kBird];
AtlasSprite *bonus;
for(int i=0; i<kNumBonuses; i++) {
bonus = [AtlasSprite spriteWithRect:CGRectMake(608+i*32,256,25,25) spriteManager:spriteManager];
[spriteManager addChild:bonus z:4 tag:kBonusStartTag+i];
bonus.visible = NO;
}
// LabelAtlas *scoreLabel = [LabelAtlas labelAtlasWithString:@"0" charMapFile:@"charmap.png" itemWidth:24 itemHeight:32 startCharMap:' '];
// [self addChild:scoreLabel z:5 tag:kScoreLabel];
BitmapFontAtlas *scoreLabel = [BitmapFontAtlas bitmapFontAtlasWithString:@"0" fntFile:@"bitmapFont.fnt"];
[self addChild:scoreLabel z:5 tag:kScoreLabel];
scoreLabel.position = ccp(160,430);
[self schedule:@selector(step:)];
isTouchEnabled = YES;
isAccelerometerEnabled = YES;
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kFPS)];
[self startGame];
[self schedule:@selector(gameLogic:) interval:5.0];
return self;
}
-(void)addTarget {
Sprite *target = [Sprite spriteWithFile:@"waa.gif"];
target.position = ccp(300,400);
[self addChild:target];
CGSize winSize = [[Director sharedDirector]winSize];
int minX = target.contentSize.height/2;
int maxX = winSize.height -target.contentSize.height/2;
int rangeX = maxX - minX;
int actualX = (arc4random() % rangeX) +minX;
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
id actionMove = [MoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2,actualX)];
id actionMoveDone = [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
[target runAction:[Sequence actions:actionMove, actionMoveDone,nil]];
}
-(void)spriteMoveFinished:(id)sender {
Sprite *sprite = (Sprite *)sender;
[self removeChild:sprite cleanup:YES];
}
-(void)gameLogic:(ccTime)dt {
[self addTarget];
}
i hope someone could help i really need it.. thanks