Bonjour,

Je Cherche à obtenir une solution à mon problème, je cherche à faire sauter un sprite de personnage, pour l'instant, j'ai ce code qui répond sur le fait de sauter quand la flèche du haut est enfoncé et il redescend quand la flèche est relaché mais j'aimerai que cela soit au bout d'un certain temps pour pas "tricher" et rester en l'air le temps qu'on reste appuyer.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def jeu():
    # Par défaut pas de game over
    lvl = 0
    game_over = False
 
 
    #animation du chevalier
    animationx = 0
 
    # initialisation des variables de déplacements et de position
    knightx = 50
    knighty = 180
    x_mouvement = 0
    y_mouvement = 0
 
    # Temps qui s'écoule
    temps = pygame.time.Clock()
 
    while not game_over: # tant que le jeu n'est pas fini on ne ferme pas la fenêtre
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
 
            # déplacements verticaux (avancer et reculer)
            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_LEFT and knightx > 0):
                    x_mouvement = -10
                    if animationx == 0:
                        animationx = 294
                    else:
                        animationx -= 42
                    knightx += x_mouvement
 
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    x_mouvement = +10
                    if animationx == 294:
                        animationx = 0
                    else:
                        animationx += 42
                    knightx += x_mouvement
 
            # Actualisation des mouvements
            x_mouvement = 0
 
            # Saut
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    y_mouvement = -30
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP:
                    y_mouvement = 30
 
            # Actualisation des mouvements
            knighty += y_mouvement
            y_mouvement = 0
 
            # blocage
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_DOWN:
                    knight = sprite_knight_block.subsurface(252, 0, 42, 42)
 
            else:
                knight = sprite_knight.subsurface(animationx, 0, 42, 42)
 
            # Attaque
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    knight = sprite_knight_attack.subsurface(420, 0, 42, 42)
Les sprite font référence à une image présente dans mon dossier et j'ai le même souci pour les attaques et les blocages car si je pouvais les ralentir, je pourrais en faire des animations plus fluides. Ce qui m'aiderat aussi plus tard pour programmer les ennemis. Merci d'avance

PS : J'ai essayé des choses du genre : pygame.time.wait(100) ou time.sleep(100) mais ça me ralentit mon programme en général en attendant pour toute les actions