I'm trying to create 3 different difficulty levels (easy, medium and hard) for a game I'm trying to develop. I use a flag to differentiate the 3 (easy = 1, medium = 2, hard = 3). Now, I'm trying to figure out how to set the speed for easy as constant, then increase it after 20 collisions while medium, then increase after 10 when hard is selected. This is how I'm trying to implement it:
-(id)init)
{vel = 8;
counter = 0;}
-(void)update:(ccTime)dt{
_world->Step(dt, vel, 10);
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *sprite = (CCSprite *)b->GetUserData();
sprite.position = ccp(b->GetPosition().x * PTM_RATIO,
b->GetPosition().y * PTM_RATIO);
sprite.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
if((contact.fixtureA == _paddleFixture && contact.fixtureB == _ballFixture) || (contact.fixtureA == _ballFixture && contact.fixtureB == _paddleFixture))
{
counter++;
[self updateSpeed];
}
}
-(void)updateSpeed{
if(diffLevel == 2)
{
if(counter%20 == 0)
{
vel = vel + 5;
}
}
else if(diffLevel == 3)
{
if(counter%10 == 0)
{
vel = vel + 10;
}
}
else
{
vel = 8;
}}
The counter does work but the speed does not seem to increment whenever counter is divisible by 20 or 10 and I can't get a constant speed for the easy level too. It starts off quite fast then gradually slows down. What am I doing wrong here? Please help.