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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
| from tkinter import *
import random
from random import randint
def sauter(event):
canvas.move(image_oiseau, 0, -10*DY)
def deplacement():
global mouvement
global tuyx,tuyx2,h,H,oisx,oisy,solx,sol2x,score,pause
x0, y0, x1, y1 = canvas.bbox(image_oiseau)
if y1 < 416 :
canvas.move(image_oiseau, 0, DY)
else :
fin()
if y1<=-5:
fin()
canvas.coords(image_sol,solx,512)
if solx >= -144:
solx=solx-5
else:
solx=144
canvas.coords(image_sol2,sol2x,512)
if sol2x >= 144:
sol2x=sol2x-5
else:
sol2x=432
canvas.coords(image_tuyau_haut,tuyx,h)
canvas.coords(image_tuyau_bas,tuyx,h-379.8)
if tuyx>=-28:
tuyx=tuyx-5
else:
tuyx=316
h=randint(272,523)
score+=1
canvas.coords(image_tuyau_haut2,tuyx2,H)
canvas.coords(image_tuyau_bas2,tuyx2,H-379.8)
if tuyx2>=-28:
tuyx2=tuyx2-5
else:
tuyx2=316
H=randint(272,523)
score+=1
collision()
lscore.config(text=str(score))
if pause == 1:
mouvement = canvas.after(40,deplacement)
def collision():
global liste_coords
x0, y0, x1, y1 = canvas.bbox(image_oiseau)
liste_coords=canvas.coords(image_oiseau)
liste_items=canvas.find_overlapping(x0,y0,x1,y1)
test_collision=False
if len(liste_items)>3:
for x in liste_items :
if x != image_oiseau:
test_collision=True
break
if test_collision==True:
fin()
def debut():
global pause
pause=1
if pause==1:
deplacement()
canvas.bind("<space>",sauter)
Eclair.destroy()
Jouer.destroy()
canvas.delete(image_menu_jeu)
def rapide():
debut()
debut()
Eclair.destroy()
Jouer.destroy()
canvas.delete(image_menu_jeu)
def rejouer():
global tuyx,tuyx2,oisx,oisy,solx,sol2x,score,finx,finy,jouerx,jouery,eclairx,eclairy,videx,videy,orx,ory,argx,argy,brox,broy
tuyx=316
tuyx2=488
oisx=67
oisy=244
solx=144
sol2x=432
score=0
finx=1000
finy=1000
jouerx=1000
jouery=1000
canvas.coords(image_menu_fin,finx,finy)
jouerx=1000
jouery=1000
canvas.create_window(jouerx,jouery,window=Jouer2)
eclairx=1000
eclairy=1000
canvas.create_window(eclairx,eclairy,window=Eclair2)
videx=1000
videy=1000
canvas.coords(image_medaille_vide,videx,videy)
orx=1000
ory=1000
canvas.coords(image_medaille_or,orx,ory)
argx=1000
argy=1000
canvas.coords(image_medaille_argent,argx,argy)
brox=1000
broy=1000
canvas.coords(image_medaille_bronze,brox,broy)
def fin():
global pause, texte_score
pause=0
if pause==0:
canvas.after_cancel(mouvement)
canvas.unbind("<space>")
finx=144
finy=256
canvas.coords(image_menu_fin,finx,finy)
jouerx=77.55
jouery=364
canvas.create_window(jouerx,jouery,window=Jouer2)
eclairx=210.45
eclairy=364
canvas.create_window(eclairx,eclairy,window=Eclair2)
scorex=211.59
scorey=258.59
canvas.create_text(scorex,scorey,text=str(score),font="04b_19 25",fill="white")
if score >= 0:
videx=78.66
videy=259.59
canvas.coords(image_medaille_vide,videx,videy)
if score >= 10:
brox=78.66
broy=259.59
canvas.coords(image_medaille_bronze,brox,broy)
if score >= 20:
argx=78.66
argy=259.59
canvas.coords(image_medaille_argent,argx,argy)
if score >= 30:
orx=78.66
ory=259.59
canvas.coords(image_medaille_or,orx,ory)
def debut2():
global pause
pause=1
if pause==1:
rejouer()
deplacement()
canvas.bind("<space>",sauter)
Jouer2.destroy()
Eclair2.destroy()
canvas.delete(image_medaille_vide)
canvas.delete(image_medaille_bronze)
canvas.delete(image_medaille_argent)
canvas.delete(image_medaille_or)
canvas.delete(image_menu_fin)
def rapide2():
debut2()
debut2()
LARGEUR = 286
HAUTEUR = 510
DY = 5
tuyx=316
tuyx2=488
h=randint(272,523)
H=randint(272,523)
oisx=67
oisy=244
solx=144
sol2x=432
score=0
mouvement=None
finx=1000
finy=1000
jouerx=1000
jouery=1000
eclairx=1000
eclairy=1000
eclairx=1000
videx=1000
videy=1000
orx=1000
ory=1000
argx=1000
argy=1000
brox=1000
broy=1000
fenetre = Tk()
canvas = Canvas(fenetre, width=LARGEUR, height=HAUTEUR)
fond = PhotoImage(file="background-day.png")
fond2 = PhotoImage(file="background-night.png")
fond=[fond,fond2]
F= random.choice(fond)
canvas.create_image(144,256, anchor=CENTER,image=F)
tuyau_haut = PhotoImage(file="tuyau_vers_le_haut.png")
image_tuyau_haut = canvas.create_image(tuyx,h,anchor=CENTER,image=tuyau_haut)
image_tuyau_haut2 = canvas.create_image(tuyx2,H,anchor=CENTER,image=tuyau_haut)
tuyau_bas = PhotoImage(file="tuyau_vers_le_bas.png")
image_tuyau_bas = canvas.create_image(tuyx,h,anchor=CENTER,image=tuyau_bas)
image_tuyau_bas2 = canvas.create_image(tuyx2,H,anchor=CENTER,image=tuyau_bas)
sol = PhotoImage(file="sol-day.png")
image_sol = canvas.create_image(144,512, anchor=S,image=sol)
image_sol2 = canvas.create_image(432,512, anchor=S,image=sol)
oiseau = PhotoImage(file="yellowbird-midflap.png")
oiseau2 = PhotoImage(file="bluebird-midflap.png")
oiseau3 = PhotoImage(file="redbird-midflap.png")
oiseau=[oiseau,oiseau2,oiseau3]
O=random.choice(oiseau)
image_oiseau=canvas.create_image(oisx,oisy, anchor=W,image=O)
lscore=Label(fenetre,text='0')
lscore.pack()
bouton_play=PhotoImage(file="bouton_play.gif")
Jouer=Button(fenetre,image=bouton_play,relief=FLAT,borderwidth=0,highlightthickness=0,command=debut)
canvas.create_window(77.55,364,window=Jouer)
bouton_eclair=PhotoImage(file="bouton_eclair.gif")
Eclair=Button(fenetre,image=bouton_eclair,relief=FLAT,borderwidth=0,highlightthickness=0,command=rapide)
canvas.create_window(210.45,364,window=Eclair)
bouton_quitter=PhotoImage(file="bouton_quitter.png")
Quitter=Button(fenetre,image=bouton_quitter,relief=FLAT,borderwidth=0,highlightthickness=0,command=fenetre.destroy)
canvas.create_window(255.5,29.63,window=Quitter)
bouton_play2=PhotoImage(file="bouton_play.gif")
Jouer2=Button(fenetre,image=bouton_play2,relief=FLAT,borderwidth=0,highlightthickness=0,command=debut2)
canvas.create_window(jouerx,jouery,window=Jouer2)
bouton_eclair2=PhotoImage(file="bouton_eclair.gif")
Eclair2=Button(fenetre,image=bouton_eclair2,relief=FLAT,borderwidth=0,highlightthickness=0,command=rapide2)
canvas.create_window(eclairx,eclairy,window=Eclair2)
menu_jeu = PhotoImage(file="menu_jeu.png")
image_menu_jeu = canvas.create_image(144,256,anchor=CENTER,image=menu_jeu)
menu_fin = PhotoImage(file="menu_fin.png")
image_menu_fin = canvas.create_image(finx,finy,anchor=CENTER,image=menu_fin)
medaille_vide = PhotoImage(file="medaille_vide.png")
image_medaille_vide = canvas.create_image(videx,videy,anchor=CENTER,image=medaille_vide)
medaille_bronze = PhotoImage(file="medaille_bronze.png")
image_medaille_bronze = canvas.create_image(brox,broy,anchor=CENTER,image=medaille_bronze)
medaille_argent = PhotoImage(file="medaille_argent.png")
image_medaille_argent = canvas.create_image(argx,argy,anchor=CENTER,image=medaille_argent)
medaille_or = PhotoImage(file="medaille_or.png")
image_medaille_or = canvas.create_image(orx,ory,anchor=CENTER,image=medaille_or)
canvas.pack()
canvas.focus_set()
fenetre.mainloop() |
Partager