Partage
  • Partager sur Facebook
  • Partager sur Twitter

mini projet python

tkinter

    14 février 2016 à 22:56:24

    bonjour, je travaille sur un mini projet pour réaliser un jeu a l'aide de tkinter , je vous explique mon problème:

    j'ai réussie a programmer le déplacement d'une bille de 20 a chaque déplacement.

    j'ai programmer des polygone pour me servir de mur, j'aimerai que lorsque la balle passe sur un mur elle disparaisse et reviennene au point de départ, seulement je ne sait pas comment introduire des condition de positions. Est ce que cela est possible ? si oui,pouvez vous m'aider ?

    voici mon programme si cela peut vous éclairez :

    import Tkinter
    from Tkconstants import *

    tk = Tkinter.Tk()

    taille=580
    x=taille/2
    y=taille/2


    can= Tkinter.Canvas(tk,bg='black',height= taille, width=taille)
    can.pack()

    balle =can.create_oval(x-10,y*2-60,x+10,y*2-80,fill="red")

    can.create_polygon(0,580,0,540,580,540,580,580,fill="green")
    can.create_polygon(x-30,530,x-30,520,x+31,520,x+31,530,fill="green")
    can.create_polygon(0,530,0,540,580,540,580,530,fill="green")
    can.create_polygon(0,0,0,40,580,40,580,0,fill="green")
    can.create_polygon(x-30,40,x-30,50,x+31,50,x+31,40,fill="green")

    trait1=can.create_polygon(0,530,260,530,260,520,0,520,fill="white")
    trait2=can.create_polygon(320,530,580,530,580,520,320,520,fill="white")
    trait3=can.create_polygon(x-10,y*2-60,x-10,y*2-79,x-90,y*2-79,x-90,y*2-60,fill="white")
    trait4=can.create_polygon(x+11,y*2-60,x+51,y*2-60,x+51,y*2-79,x+11,y*2-79,fill="white")
    trait5=can.create_polygon(x-90,500,x-90,420,x-110,420,x-110,500,fill="white")
    trait6=can.create_polygon(x+70,500,x+110,500,x+110,480,x+70,480,fill="white")
    trait7=can.create_polygon(x+130,520,x+130,440,x+150,440,x+150,520,fill="white")
    trait8=can.create_polygon(x-70,480,x-10,480,x-10,460,x-70,460,fill="white")
    trait9=can.create_polygon(x+10,480,x+30,480,x+30,420,x+10,420,fill="white")
    trait10=can.create_polygon(x+30,480,x+30,460,x+70,460,x+70,480,fill="white")
    trait13=can.create_polygon(x-30,460,x-30,440,x-10,440,x-10,460,fill="white")
    trait14=can.create_polygon(x-110,420,x-110,360,x-130,360,x-130,420,fill="white")

    def anime(event):
        global x,y
        i=0
        if i!=trait13:
            x,y=x+20,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
        else:
            x,y=x,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
    tk.bind("<Right>",anime)

    def anime(event):
        global x,y
        i=0
        if i!=taille:
            x,y=x+20,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
        else:
            x,y=x,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
    tk.bind("<Right>",anime)

    def anime(event):
        global x,y
        i=0
        if i!=taille:
            x,y=x-20,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
        else:
            x,y=x,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
    tk.bind("<Left>",anime)

    def anime(event):
        global x,y
        i=0
        if i!=taille:
            x,y=x,y-10
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
        else:
            x,y=x,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
    tk.bind("<Up>",anime)

    def anime(event):
        global x,y
        i=0
        if i!=taille:
            x,y=x,y+10
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1
        else:
            x,y=x,y
            can.coords(balle,x-10,y*2-60,x+10,y*2-80)
            i=i+1

    tk.bind("<Down>",anime)


    frame = Tkinter.Frame(tk, relief=RIDGE, borderwidth=1)
    frame.pack(fill=BOTH,expand=1)
    frame.configure(background="purple")



    jeu = Tkinter.Label(frame, text="Bonjour et bienvenue dans Invisible Way !", background="purple")
    jeu.pack(fill=X, expand=1)


    button = Tkinter.Button(frame,text="QUITTER",command=tk.destroy,background="yellow")
    button.pack(side=BOTTOM)



    tk.mainloop()


    • Partager sur Facebook
    • Partager sur Twitter

    mini projet python

    × 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