微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何在 Turtle 中进行冷却?

如何解决我如何在 Turtle 中进行冷却?

我正在使用 Turtle 制作游戏,需要一个有冷却时间的投掷机制。我尝试使用时间模块,但尝试将变量分类int()float() 不起作用。

def throw(throwcdstart,throwcd):
  if throwcd >= 2:
    throwcdstart = int(time.time())
    print('Thrown!')    #this is put here as a placeholder

throwcd = int(time.time()) - throwcdstart #this part is in a while true at the bottom,by the way

我尝试在此处和 Google 上搜索,但我得到的唯一结果是 discord.py

编辑:我忘了说我确实在代码的开头将 throwcd 变量设置为 2。

编辑 2:还有其他事情发生,例如移动和敌人 AI。我曾尝试使用 time.sleep() 之类的东西,但是当我这样做时它会拖延整个游戏。我还没有尝试过 math,因为它看起来很复杂。

解决方法

相当厚脸皮,因为问题问得很不清楚:

def throw(throwcdstart,throwcd):
  if throwcd >= 2:
    throwcdstart = int(time.time())
    mycooldown = 0.5 # seconds <==============
    time.sleep(mycooldown)
    print('Thrown!')    #this is put here as a placeholder

throwcd = int(time.time()) - throwcdstart #this part is in a while true at the bottom,by the way

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。