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 :

Comment faire pour faire sauter mon personnage


Sujet :

Programmation multimédia/Jeux Python

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2021
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2021
    Messages : 3
    Points : 5
    Points
    5
    Par défaut Comment faire pour faire sauter mon personnage
    Bonjour , j'aimerai que mon personnage saute mais je n'ai aucune idée comment je pourrais faire

    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    from tkinter import*
    from random import randint
     
     
    def defile() :
        global x4 , y4 , x1 , x2 , y2 , x
     
        x1 = x1 +1
        can.move('obstacle', 0,10)
        can.move('mob', -5,0)
        y4 = y4+13
     
     
     
     
        fen.after(50, defile)
        if (x2==50) :
           apparition()
           can.move('mob',0,0)
           x2=0
     
     
     
    def droite(event):
        global x1 , x2 , x3 , y2
     
        print(x2)
        if(x2>1160):
            can.move('perso',0,0)
     
        else :
            can.move('perso',10 , 0)
            x2=x2+10
     
    def gauche(event):
        global x1 , x2 , x3 , y2
     
        print(x2)
        if(x2<130):
            can.move('perso',0,0)
     
        else :
            can.move('perso',-10 , 0)
            x2=x2-10
     
     
    def apparition():
        global x4 , y4
        x4 , y4 = randint(500, 700) , randint(0, 10)
        obs1 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])    #Apparition obstacle au hasard
        obs2 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
        obs3 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
     
     
    x1 , y1 = 850 , 500
    x2 , y2 = 300 , 700
    x3 , y3 = 1500 ,700
    x4 , y4 = 1500, 1500
     
    fen = Tk()
    can = Canvas(fen , width = 1700 , height = 1000, bg = 'white')
    can.pack()
     
     
     
    Fond_jeu = PhotoImage(file = 'fond.png')
    Image_Affichee = can.create_image(x1 , y1 , image= Fond_jeu, anchor='center' , tag = ['route'])
     
    Perso = PhotoImage(file = 'perso.png')
    Image_Affichee = can.create_image(x2 , y2 , image= Perso, anchor='center' , tag = ['perso'])
     
    Mob = PhotoImage(file = 'mob.png')
    Image_Affichee = can.create_image(x3 , y3 , image= Mob, anchor='center' , tag = ['mob'])
     
    obs = PhotoImage(file='obstacle.png')
     
    obs1 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
     
    fen.bind("<Right>" , droite)
    fen.bind("<Left>" , gauche)
    apparition()
    defile()
     
    fen.mainloop()

    Merci d'avance

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Salut,

    Vous pouvez essayer de vous inspirer du code qui est dans cette discussion (voire poser des questions après avoir essayé de...)

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2021
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2021
    Messages : 3
    Points : 5
    Points
    5
    Par défaut
    J'ai changer de style de jeu en simplifiant maintenant le problème qui se pose c'est que je veux faire apparaitre plusieurs obstacle au hasard dans le canevas mais dans mon code il y'en a que 1 qui apparait

    Merci d'avance


    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    from tkinter import*
    from random import randint
     
     
    def defile() :
        global x4 , y4 , x1 , x2 , y2 , x
     
        x1 = x1 +1
        can.move('obstacle', 0,10)
        can.move('mob', -5,0)
        y4 = y4+13
     
        collision()
     
     
        fen.after(50, defile)
        if (y3==50) :
           apparition()
     
     
     
     
    def droite(event):
        global x1 , x2 , x3 , y2
     
        print(x2)
        if(x2>1160):
            can.move('perso',0,0)
     
        else :
            can.move('perso',10 , 0)
            x2=x2+10
            collision()
    def gauche(event):
        global x1 , x2 , x3 , y2
     
        print(x2)
        if(x2<130):
            can.move('perso',0,0)
     
        else :
            can.move('perso',-10 , 0)
            x2=x2-10
            collision()
     
    def apparition():
        global x4 , y4
        x4 , y4 = randint(500, 700) , randint(0, 10)
        obs1 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])    #Apparition obstacle au hasard
        obs2 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
        obs3 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
     
     
     
    def collision () :
        global x2 , x1 , x2 , y2 , x3 , y3 , x
     
     
        if (x4> 380 ) :
          if (( x2 > x4) and (x2<x4+170)) :
            print('Collision detecter')
            can.move('perso', 0 , 0)
            can.move('obstacle', 0 , 0)
            exit()
          elif ((x2 + 830>x4) and (x2+830< x4 + 170)) :
            print('Collision detecter')
            can.move('perso', 0 , 0)
            can.move('obstacle', 0 , 0)
            exit()
     
    x1 , y1 = 850 , 500
    x2 , y2 = 300 , 700
    x3 , y3 = 1500 ,700
    x4 , y4 = 1500, 1500
     
     
    fen = Tk()
    can = Canvas(fen , width = 1700 , height = 1000, bg = 'white')
    can.pack()
     
     
     
    Fond_jeu = PhotoImage(file = 'fond.png')
    Image_Affichee = can.create_image(x1 , y1 , image= Fond_jeu, anchor='center' , tag = ['route'])
     
    Perso = PhotoImage(file = 'perso.png')
    Image_Affichee = can.create_image(x2 , y2 , image= Perso, anchor='center' , tag = ['perso'])
     
    #Mob = PhotoImage(file = 'mob.png')
    #Image_Affichee = can.create_image(x3 , y3 , image= Mob, anchor='center' , tag = ['mob'])
     
    obs = PhotoImage(file='obstacle.png')
     
    obs1 = can.create_image(x4,y4, image = obs, anchor='center', tag = ['obstacle'])
     
    fen.bind("<Right>" , droite)
    fen.bind("<Left>" , gauche)
    apparition()
    defile()
    collision()
    fen.mainloop()

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

Discussions similaires

  1. comment faire crée mon forumlaire pour un débutant?
    Par keokaz dans le forum Débuter
    Réponses: 0
    Dernier message: 11/10/2008, 17h16
  2. Réponses: 4
    Dernier message: 28/07/2006, 13h10
  3. aide comment faire sauter un personnage
    Par MAXIMIX dans le forum SDL
    Réponses: 3
    Dernier message: 24/05/2006, 09h05
  4. Réponses: 1
    Dernier message: 23/01/2006, 22h23
  5. [XSL]Comment faire ceci ?? Mon for-each n'affiche pas tout !
    Par Devil666 dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 27/07/2005, 15h04

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