IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Programmation multimédia/Jeux Python Discussion :

[pygame]deplacer perso quand touche reste enfoncée


Sujet :

Programmation multimédia/Jeux Python

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut [pygame]deplacer perso quand touche reste enfoncée
    Bonjour a tous!
    Voila mon problème, depuis hier j'essaye de faire en sorte que dans mon jeu le personnage continue de bouger quand les touches gauche et droite restent enfoncées. Voici le code du jeu:

    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
    #!/usr/bin/python
    import sys,pygame
    pygame.init()
    size=width,height=600,500
    screen=pygame.display.set_mode(size)
    pygame.display.set_caption("OpenMario")
    white=255,255,255,255
     
    def clavier():
            for event in pygame.event.get():
                while event.type==pygame.KEYDOWN:
                    if event.key==pygame.K_UP:
                        return("up")
                    if event.key==pygame.K_DOWN:
                        return("down")
                    if event.key==pygame.K_LEFT:
                        return("left")
                    if event.key==pygame.K_RIGHT:
                        return("right")
                    if event.key==pygame.K_q:
                        sys.exit()
     
                if event.type==pygame.QUIT:
                    sys.exit()
    mario=pygame.image.load("/home/hugo/Desktop/ball.gif")
    global mariorect
    mariorect=mario.get_rect()
    mariorect=mariorect.move([230,350])
    def move(direction):
        global mariorect
        if direction=="up":
            y=350
            x=y
            while x!=0:
                mariorect=mariorect.move([0,-1])
                screen.fill(white)
                screen.blit(mario,mariorect)
                pygame.display.flip()
                x=x-1
     
            x=y
            while x!=0:
                mariorect=mariorect.move([0,1])
                screen.fill(white)
                screen.blit(mario,mariorect)
                pygame.display.flip()
                x=x-1
     
        if direction=="left":
            newpos=[-20,0]
            essai=mariorect.move(newpos)
            if essai[0]>=0:
                mariorect=essai
        if direction=="right":
            newpos=[20,0]
            essai=mariorect.move(newpos)
            if essai[0]<width:
                mariorect=essai
     
     
     
    while 1:
        screen.fill(white)
        move(clavier())
        screen.blit(mario,mariorect)
        pygame.display.update()
    Quelqu'un a une idée ? Merci d'avance.
    Hugo

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut re
    peut etre la fonction pygame.key.set_repeat() que j'ai trouvé sur le forum, j'essaye

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut re
    ok, en mettant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    pygame.key.set_repeat(500,30)
    ça marche!!!

  4. #4
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    1 049
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 049
    Points : 1 380
    Points
    1 380
    Par défaut
    regardes aussi pygame.key.get_pressed() selon ce que tu veux faire.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. JButton comment faire pour qu'il reste enfoncé
    Par fievel dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 28/03/2006, 20h25
  2. Débutant : Touche reste Préssées
    Par jejeb dans le forum C
    Réponses: 5
    Dernier message: 08/03/2006, 14h43
  3. [IDE D9 perso] raccourcis touches
    Par Altaric dans le forum EDI
    Réponses: 3
    Dernier message: 03/12/2005, 11h55
  4. [KeyEvent] plusieurs touches simultanées enfoncées
    Par gege2mars dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 07/01/2004, 11h44
  5. TBitBtn reste enfoncé
    Par TRINCAL Sylvain dans le forum C++Builder
    Réponses: 8
    Dernier message: 25/06/2002, 16h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo