[英]Flappy Bird: is there a way to find the spawn - rate of the poles?
I have made a working Flappy Bird game, but the green poles are spawning in a weird way. 我做了一个工作Flappy Bird游戏,但绿色的杆子以一种奇怪的方式产生。 I have done it like this: 我这样做了:
let game_speed = 1;
let max_speed = 1000;
let spawn_rate = Math.round(max_speed / game_speed);
function draw(){
if(frameCount % spawn_rate === 0)
generateNewPole();
game_speed += (game_speed < max_speed / 10)? 0.001 : 0;
spawn_rate = Math.round(max_speed / game_speed);
}
I have tried the following formulas for the spawn_rate : 我已经为spawn_rate尝试了以下公式:
Math.round(max_speed - game_speed) Math.round(max_speed - game_speed)
Math.round(max_speed / game_speed) Math.round(max_speed / game_speed)
Math.round((max_speed - game_speed) / game_speed) Math.round((max_speed - game_speed)/ game_speed)
Math.round((max_speed - game_speed) / (max.speed / game.speed)) Math.round((max_speed - game_speed)/(max.speed / game.speed))
Math.round(max_speed / Math.round(game_speed)) Math.round(max_speed / Math.round(game_speed))
if(Math.round(frameCount * game.speed) % max_speed === 0) if(Math.round(frameCount * game.speed)%max_speed === 0)
For the second and third things I tried (see above), I expected them to work, but there are still spaces. 对于我尝试过的第二件和第三件事(见上文),我希望它们可以工作,但仍有空间。 This might be because of JavaScript's way of handling decimal numbers (It sucks at it) or I am just dumb and doing something completely wrong 这可能是因为JavaScript处理十进制数字的方式(它很糟糕)或者我只是愚蠢而且做了一些完全错误的事情
Math.round(max_speed / game_speed)
I can hazard a guess that the big gaps you describe are caused by Math.round
when it switches from rounding down to rounding up (and vice versa). 我可以猜测,你描述的大差距是由Math.round
从四舍五入切换到四舍五入(反之亦然)引起的。 I suspect you'd get more consistant behaviour if you switched to Math.floor
or Math.ceil
. 如果您切换到Math.floor
或Math.ceil
我怀疑您会得到更多一致的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.