简体   繁体   English

Flappy Bird:有没有办法找到产卵率 - 两极?

[英]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: 我这样做了:

  • frameCount is a p5.js variable counting the frames frameCount是一个计算帧数的p5.js变量
  • draw is a p5.js function that will be done every frame draw是一个p5.js函数,将在每一帧完成
    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)

    • This didn't work even close to good 这甚至不太好用
  • Math.round(max_speed / game_speed) Math.round(max_speed / game_speed)

    • This worked ok, but I have random big gaps everywhere 这工作正常,但我到处都有随机的大空白
  • Math.round((max_speed - game_speed) / game_speed) Math.round((max_speed - game_speed)/ game_speed)

    • This worked also quite well, except for random gaps here too 这也很有效,除了这里的随机差距
  • Math.round((max_speed - game_speed) / (max.speed / game.speed)) Math.round((max_speed - game_speed)/(max.speed / game.speed))

    • The poles spawned at a god-speed rate 两极以神速率产生
  • Math.round(max_speed / Math.round(game_speed)) Math.round(max_speed / Math.round(game_speed))

    • Also random gaps 也是随机的差距
  • if(Math.round(frameCount * game.speed) % max_speed === 0) if(Math.round(frameCount * game.speed)%max_speed === 0)

    • Yeah... not a single pole spawned at all 是的......根本没有产生任何一根杆子

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处理十进制数字的方式(它很糟糕)或者我只是愚蠢而且做了一些完全错误的事情

edit: here is a link to my code 编辑:这是我的代码的链接

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.floorMath.ceil我怀疑您会得到更多一致的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flappy Bird 代码不起作用 - JavaScript - Flappy bird code not working - JavaScript 我开始玩飞扬的小鸟游戏 - canvas 无法渲染/显示 - I have the beginnings of a flappy bird game - the canvas fails to render/display 屏幕上未显示的对象和 keyPressed 不起作用(Flappy Bird 代码挑战) - Objects not shown on screen & keyPressed not working (Flappy Bird Code Challenge) 如何在 html javascript 飞禽类游戏中添加重启按钮? - How do I add a restart button in html javascript flappy bird type game? 我的 Flappy Bird 游戏的 Javascript 代码未按预期显示角色 - My Javascript code for a flappy bird game isn't displaying the character as it's meant to do 训练神经网络用遗传算法玩飞鸟 - 为什么不能学习? - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? 试图提高 Canvas 游戏中障碍物的生成率 - Trying to Increase Spawn Rate of Obstacles in Canvas Game 如何在JavaScript游戏中随时间增加刷新率 - how to increase spawn rate over time in javascript game 有没有办法在前端获得货币汇率? - Is there a way to get currency rate on the frontend? 获得浏览器刷新率的一致方式 - Consistent way to get a browser's refresh rate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM