JS函数每100分

JS Function Every 100 Points

我试着自己写了这篇文章,但我失败了。现在我有一个脚本来检查我游戏中的分数。我每 100 分检查一次,并根据分数更改一个变量,但我这样做是错误且乏味的:

if(gameController.speed == 1) {

    if(score >= 200) {
        squishyController.gravity = -25;
    }

    if(score >= 300) {
        squishyController.gravity = -50;
    }

    if(score >= 400) {
        squishyController.gravity = -75;
    }

    if(score >= 500) {
        squishyController.gravity = -100;
        gamePause = true;
        // Spawn First Boss
    }

    if(score >= 600) {
        squishyController.gravity = -125;
    }

    if(score >= 700) {
        squishyController.gravity = -150;
    }
}

你明白了。我想以word形式做的是:

简而言之就是这样。这是我的想法,但不要杀了我。

for (var i = 0; i += pointValue) {

// Check if points are being added then add to score depending on point value
if(getPoints == true) {
  i++;
}


// For every 100 points change the gravity value
if(i >= incrementsOf100) {
  gravity = gravity -= 25;
}

// For every 500 points, spawn a boss more difficult than the last

if(i = incrementsOf500) {
  bossDifficulty = bossDifficulty += 100; // Just adding this because I will add more hitpoints to boss.
  spawnBoss = true;
}

}

如何使用 modus 运算符求出除以 100 的余数,然后将分数减去该余数以获得您需要改变重力的次数

var score = 550;
var extra = score % 100;
var gravityTimes = (score - extra) / 100;

gravity = gravity -= (25 * gravityTimes);