Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème en pygame

    13 juillet 2019 à 20:38:41

    Bonjour,

    Je suis actuellement en tous début de création d'un petit jeu RPG,

    N'étant pas le meilleur graphiste au monde j'ai repris les graphisme du jeu : The Legend of Zelda : A Link to the past

    voilà le problème :

    J'ai voulu faire une animation lors du déplacement de link(en multi thread )

    Voici la classe pour le Thread:

    direction c'est l'orientation du Sprite(1 : Bas, 2 : Haut, 3: Droite, 4 : Gauche

    co C'est les coordonnées actuelle du Perso

    class LinkAnim(Thread):
        def __init__(self, direction, co):
            Thread.__init__(self)
            self.direction = direction
            self.co = co
        def run(self):
            if self.direction == 2:
                Test = 1
                self.co = self.co.move(0, -7)
                SMain.blit(Up_Anim_1, self.co)
                pygame.display.flip()
    
                self.co = self.co.move(0, -7)
                SMain.blit(Part1_Font1, (15, 0))
                SMain.blit(Up_Anim_2, self.co)
                pygame.display.flip()
    
                self.co = self.co.move(0, -7)
                SMain.blit(Part1_Font1, (15, 0))
                SMain.blit(Up_Anim_3, self.co)
                pygame.display.flip()
                
                SMain.blit(Part1_Font1, (15, 0))
                Test = 0

    Et l'endroit où elle est appelée

    !!!! C'est pas ici descendez !!!! 
    for event in pygame.event.get():
                if event.type == pygame.locals.KEYDOWN:
                    if event.key == K_DOWN:
                        go = 1
                        linkco = linkco.move(0, 15)
                        orientation = 1
                    if event.key == K_UP:
                        go = 2
                        linkco = linkco.move(0, -15)
                        orientation = 2
                    if event.key == K_RIGHT:
                        go = 3
                        linkco = linkco.move(15, 0)
                        orientation = 3
                    if event.key == K_LEFT:
                        go = 4
                        linkco = linkco.move(-15, 0)
                        orientation = 4
                        
                if event.type == pygame.locals.KEYUP:
                    if event.key == K_UP:
                        go = 0
                    if event.key == K_DOWN:
                        go = 0
                    if event.key == K_RIGHT:
                        go = 0
                    if event.key == K_LEFT:
                        go = 0
                
                        
                    if event.type == QUIT or event.key == K_ESCAPE:
                        continuer = False
                        print("on sort du programme")
    
            if go == 1:
                linkco = linkco.move(0, 15)
    
    !!!! ICI !!!!
    
            if go == 2:
                linkco.move(15, 0)
                VarAnim = LinkAnim(2, linkco)
                VarAnim.start()
                
            if go == 3:
                linkco = linkco.move(15, 0)
            if go == 4:
                linkco = linkco.move(-15, 0)
            SMain.blit(Part1_Font1, (15, 0))
            if orientation == 1:
                SMain.blit(Down_Basic_1, linkco)

    cela ne fonctionne(Cela ne fait pas ce que je veut) pas et je ne sais pas comment envoyer une vidéo du résultat.

    J'espère avoir été le plus clair possible,

    Si ce n'est pas le cas n'hésitez à m'en faire part !!!

    ;)

    :)


    -
    Edité par MathR6 13 juillet 2019 à 20:47:55

    • Partager sur Facebook
    • Partager sur Twitter
      13 juillet 2019 à 22:34:09

      Salut

      Si le code ne fait pas ce que tu souhaites, c'est un problème sémantique, et la cause en est l'auteur. Je vois que tu utilises le module thread, or, dans la playlist YT de Dan737, il n'utilise aucunement ce module pour les animations.

      Je ne vais pas t'aider par incapacité, mais, je m'interroge. Comment se fait-il que tu sois contraint d'utiliser le threading pour une animation quand Dan y arrive sans ? La programmation multithreadé est quand même relativement compliqué et complexe. Le mieux serait de reprendre ton animation sans threading, et si tu ne rencontres pas de problème majeur, laisser tel quel.

      • Partager sur Facebook
      • Partager sur Twitter
        14 juillet 2019 à 15:13:21

        D'autre part je propose des pistes améliorations, il y en surement d'autres

        !!!! C'est pas ici descendez !!!!
        sens = [0,0]
        speed = 15
        
        for event in pygame.event.get():
                    if event.type == pygame.locals.KEYDOWN:
                        if event.key == K_DOWN:
                            sens[1] = 1
                            linkco = linkco.move(0, 15)
                            orientation = 1
                        elif event.key == K_UP:
                            sens[1] = -1
                            linkco = linkco.move(0, -15)
                            orientation = 2
                        elif event.key == K_RIGHT:
                            sens[0] = 1
                            linkco = linkco.move(15, 0)
                            orientation = 3
                        elif event.key == K_LEFT:
                            sens[0] = -1
                            linkco = linkco.move(-15, 0)
                            orientation = 4
                             
                    if event.type == pygame.locals.KEYUP:
                        if event.key in [K_UP,K_DOWN,K_RIGHT,K_LEFT]:
                            go = 0
                     
                             
                        if event.type == QUIT or event.key == K_ESCAPE:
                            continuer = False
                            print("on sort du programme")
         
                linkco = linkco.move(speed*sens[0], speed*[1])
         
        !!!! ICI !!!!
         
                if go == 2:
                    VarAnim = LinkAnim(2, linkco)
                    VarAnim.start()
                     
                
                SMain.blit(Part1_Font1, (15, 0))
                if orientation == 1:
                    SMain.blit(Down_Basic_1, linkco)
        



        -
        Edité par Coliculus 14 juillet 2019 à 15:13:58

        • Partager sur Facebook
        • Partager sur Twitter

        Problème en pygame

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown