我试着自己写这个,但我失败了。现在我有一个脚本检查我的游戏中的分数。我检查每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;
}
}
答案 0 :(得分:1)
如何使用modus运算符查找除以100的余数,然后将得分除以该余数以得到您需要更改重力的次数
var score = 550;
var extra = score % 100;
var gravityTimes = (score - extra) / 100;
gravity = gravity -= (25 * gravityTimes);