I am having a problem adding a booster to my game, for now I have it set to a toggle but I want it to be a time based e.g. press shift get boost for 5 seconds cant press for 30 seconds. But when I tried this the player would have a continuous boost as the loop would restart, for now I have made the boost a toggle without a timer, .sleep does not work as well because it pauses the program for the time.
while run:
clock.tick(FPS)
if len(enemies) == 0:
level += 1
wave_length += 5
for i in range(wave_length):
enemy = Em(random.randrange(50, WIDTH-10), random.randrange(-1500*level/5, -100), random.choice(["red","green","purple","blue"]))
enemies.append(enemy)
boost = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.x - player_vel > 0:
player.x -= player_vel
if keys[pygame.K_RIGHT] and player.x + player_vel + player.get_width() < WIDTH:
player.x += player_vel
if keys[pygame.K_UP] and player.y - player_vel > 0:
player.y -= player_vel
if keys[pygame.K_DOWN] and player.y + player_vel + player.get_height() < HEIGHT:
player.y += player_vel
if keys[pygame.K_LSHIFT]:
boost = True
start = time.time()
if boost == True:
player_vel = boost_speed