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
|
from tkinter import *
import random
L=500
x=100
y=200
xc=250
yc=250
Thx0=300
Thy1=150
Tby0=250
Tby1=500
dx=0
dy=0
dx1=-5
dy1=0
g=2
mult=6
'''l=[]'''
def chute():
global dx, dy, g, y
dy=dy+g
can.move(image_oiseau,dx,dy)
fen.after(50,chute)
y=y+dy
if (y<0)or (y>L):
can.delete(ALL)
can.create_text(xc, yc, anchor=CENTER, text="VOUS AVEZ PERDU. VOULEZ-VOUS REJOUER ?", font=('Helvetica', '15'))
def saut(event):
global dx, dy, g, mult
dy=-mult*g
def animation():
global tuyau_haut, tuyau_bas, dx1, dy1
'''for i in range(0, len(L)-1):
l.append('''
can.move(tuyau_haut,dx1,dy1)
can.move(tuyau_bas,dx1,dy1)
fen.after(50,animation)
#Interface Graphique
fen=Tk()
can= Canvas(fen,width = L, height = L , bd=0, bg="white")
oiseau = PhotoImage(file='flappy2.gif')
image_oiseau=can.create_image(x,y, anchor=CENTER, image=oiseau)
tuyau_haut=can.create_rectangle(Thx0, 0, Thx0+40, Thy1, fill="#74BF2E", outline="green")
tuyau_bas=can.create_rectangle(Thx0, Tby0, Thx0+40, Tby1, fill="#74BF2E", outline="green")
can.bind('<space>', saut)
can.focus_set()
animation()
Bouton_Demarrer=Button(fen, text='Démarrer', command=chute)
Bouton_Demarrer.pack(side=BOTTOM)
Bouton_Quitter=Button(fen, text ='Quitter', command = fen.destroy)
Bouton_Quitter.pack(side=BOTTOM)
can.pack()
fen.mainloop() |
Partager