Bonjour,
je m'amuse à faire un petit programme où un bonhomme se déplace sur la scène.
J'arrive à le faire aller à droite et gauche (les images correspondantes s'affichent) mais je ne vois pas comment lui faire alterner le pas.
Voilà ce que j'ai fait pour l'instant:

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
marcheDGJG = 'marcheDGJG.png'
marcheDGJD = 'marcheDGJD.png'
marcheDDJG = 'marcheDDJG.png'
marcheDDJD = 'marcheDDJD.png'
marche=[marcheDGJG,marcheDGJD,marcheDDJG,marcheDDJD]
background_image_filename = 'fond.jpg'
 
 
import pygame
from sys import exit
from pygame.locals import *
from gameobjects.vector2 import Vector2
 
pygame.init()
 
screen = pygame.display.set_mode((640, 640), 0, 32)
pygame.display.set_caption("Combat!!")
 
 
background=pygame.image.load(background_image_filename).convert()
 
 
class combattant(pygame.sprite.Sprite):
 
    def __init__(self,img,posit):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.image.load(img)
        self.image_pos=posit
 
 
 
julien = combattant(marcheDGJG,Vector2(350,350))
 
while True:
    screen.blit(background,(0,0))
    screen.blit(julien.image,julien.image_pos)
 
    for event in pygame.event.get():
            if event.type == QUIT:
                  exit()
    tkey=pygame.key.get_pressed()
    if tkey[K_LEFT]: 
        julien.image_pos.x -= 1
        julien.image=pygame.image.load(marche[0])
    elif tkey[K_RIGHT]: 
        julien.image_pos.x += 1
        julien.image=pygame.image.load(marche[2])
 
    pygame.display.update()
C'est en fait un code inspiré de nombreux autres codes...il n'a rien de très original mais quand on apprend, c'est déjà ça...

Je vous remercie de vos bonnes idées...
@bientôt!