如何在海龟中冷却?

2024-05-14 23:33:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用乌龟做游戏,需要一个有冷却时间的投掷机械师。我尝试使用时间模块,但是尝试将变量分类为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

我试着在这里和谷歌上搜索,但我得到的唯一结果是discord.py

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

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


Tags: 模块the游戏编辑timeisdef时间
1条回答
网友
1楼 · 发布于 2024-05-14 23:33:31

非常厚颜无耻的表述,因为问题被问得非常不明确:

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

相关问题 更多 >

    热门问题