admin管理员组

文章数量:1291144

I've only just recently began coding in pygame, and I am currently making a platformer game. I am trying to implement a cooldown for a dash, and can't get it to work. This is the code I have done for the keybinds (the dash part is in bold).

 for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_RIGHT:
                moving_right = True
            if event.key == K_LEFT:
                moving_left = True
            if event.key == K_UP:
                if air_timer < 6:
                    player_y_momentum = -5
           ** if event.key == K_z:
                if player_dash == False:
                # if not player_rect+50.collideRect(tile_rects):
                    if player_flip == False:
                        moving_right == True
                        player_rect.x += 50
                    if player_flip == True:
                        moving_left == True
                        player_rect.x -= 50
                    player_y_momentum = 0
                    player_dash == True**
        if event.type == KEYUP:
            if event.key == K_RIGHT:
                moving_right = False
            if event.key == K_LEFT:
                moving_left = False

I tried this block of code, thinking it was an easy fix, but i started the game and it didn't work, I could spam the dash as much as I wanted

 if player_dash == True:
        pygame.time.wait(10000)
        player_dash == False

本文标签: Trying to make a cooldown for a dash in pygameStack Overflow