我正在使用 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
,因为它看起来很复杂。
答案 0 :(得分:0)
相当厚脸皮,因为问题问得很不清楚:
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