有人可以帮我在python中制作计时器吗?我需要帮助的是'Handle_caught'方法应该包含一个计时器,使玩家速度增加五秒钟,当全局变量改变时玩家速度增加为真。
速度令牌类:
class Addspeed(games.Sprite):
image = games.load_image('addspeed.png')
speed = 2
def __init__(self,x,y = 10):
super(Addspeed, self).__init__(image = Addspeed.image,
x = x, y = y,
dy = Addspeed.speed)
def update(self):
if self.bottom>games.screen.height:
self.destroy()
def handle_caught(self):
self.destroy()
def increasespeed(self):
global speedbuff
speedbuff = True
def decreasespeed(self):
global speedbuff
speedbuff = False
玩家速度如何提高:
speedbuff = False
def update(self):
global inventory
global speed
""" uses A and D keys to move the ship """
if games.keyboard.is_pressed(games.K_a):
if speedbuff == False:
self.x -= 3
elif speedbuff == True:
self.x -= 6
if games.keyboard.is_pressed(games.K_d):
if speedbuff == False:
self.x+= 3
elif speedbuff == True:
self.x+=6