0
我正在嘗試爲我正在嘗試開發的遊戲創建3個不同的難度級別(簡單,中等和難度)。我用一個標誌來區分3(easy = 1,medium = 2,hard = 3)。現在,我試圖弄清楚如何將速度設置爲常量,然後在中等程度的20次碰撞後增加它,然後在選擇硬件後在10次後增加。這是我正在努力實現它:在box2d中爲精靈設置常量和提高速度
-(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;
}}
計數器的工作,但速度似乎並沒有增加,每當計數器是整除20或10,我不能得到一個恆定的速度輕鬆水平了。它起步非常快,然後逐漸變慢。我在這裏做錯了什麼?請幫忙。