#NOTE : #Peut-être penser à définir des fonctions pour chaque partie (Niveau 1,2 et 3 / Barre) #Musique de fond ?? from tkinter import * #INITIALISATION FENETRE + FOND fenetre =Tk() fenetre.title("The Py Breaker !") fenetre.geometry("1100x800") Fond=Canvas(fenetre,width=1100,height=800,bg="black") Fond.place(x=0,y=0) Background=PhotoImage(file="Background.gif") Fond.create_image(0,0,image=Background,anchor="nw") #INITIALISATION DU NIVEAU #1 BV=PhotoImage(file="BV.gif") x,y=0,0 fichier=open('niveau.txt') V=[] for ligne in fichier: for i in range(11): #Nb. caractères dans une ligne case=ligne[i] if case=="V": Fond.create_image(x,y,image=BV,anchor="nw") a=Fond.create_rectangle(x,y,x+99,y+49,outline="green") V.append(a) x=x+100 x=0 y=y+100 #2 BJ=PhotoImage(file="BJ.gif") x,y=0,0 fichier=open('niveau.txt') J=[] for ligne in fichier: for i in range(11): #Nb. caractères dans une ligne case=ligne[i] if case=="J": Fond.create_image(x,y,image=BJ,anchor="nw") b=Fond.create_rectangle(x,y,x+99,y+49,outline="yellow") J.append(b) x=x+100 x=0 y=y+100 #3 BR=PhotoImage(file="BR.gif") x,y=0,0 fichier=open('niveau.txt') R=[] for ligne in fichier: for i in range(11): #Nb. caractères dans une ligne case=ligne[i] if case=="R": Fond.create_image(x,y,image=BR,anchor="nw") c=Fond.create_rectangle(x,y,x+99,y+49,outline="red") R.append(c) x=x+100 x=0 y=y+100 #INITIALISATION BARRE Barre=Fond.create_rectangle(480,775,620,750,fill="black") #INITIALISATION BALLE Balle=Fond.create_oval(530,720,560,750,fill='red') #REBODNDS BORDS ECRAN def deplacement(): global dx,dy if Fond.coords(Balle)[3]<=0: dy=-1*dy if (Fond.coords(Balle)[1]>800): dy=-1*dy if (Fond.coords(Balle)[0]<0) or (Fond.coords(Balle)[2]>1100): dx=-1*dx #REBONDS BRIQUES VERTES if (Fond.coords(Balle)[1]Fond.coords(V[0])[0]) and (Fond.coords(Balle)[3]>Fond.coords(V[0])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(V[1])[0]) and (Fond.coords(Balle)[3]>Fond.coords(V[1])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(V[2])[0]) and (Fond.coords(Balle)[3]>Fond.coords(V[2])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(V[3])[0]) and (Fond.coords(Balle)[3]>Fond.coords(V[3])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(V[4])[0]) and (Fond.coords(Balle)[3]>Fond.coords(V[4])[1]): dy=-1*dy #REBONDS BRIQUES JAUNES if (Fond.coords(Balle)[1]Fond.coords(J[0])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[0])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[1])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[1])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[2])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[2])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[3])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[3])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[4])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[4])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[5])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[5])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[6])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[6])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(J[7])[0]) and (Fond.coords(Balle)[3]>Fond.coords(J[7])[1]): dy=-1*dy #REBONDS BRIQUES ROUGES if (Fond.coords(Balle)[1]Fond.coords(R[0])[0]) and (Fond.coords(Balle)[3]>Fond.coords(R[0])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(R[1])[0]) and (Fond.coords(Balle)[3]>Fond.coords(R[1])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(R[2])[0]) and (Fond.coords(Balle)[3]>Fond.coords(R[2])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(R[3])[0]) and (Fond.coords(Balle)[3]>Fond.coords(R[3])[1]): dy=-1*dy if (Fond.coords(Balle)[1]Fond.coords(R[4])[0]) and (Fond.coords(Balle)[3]>Fond.coords(R[4])[1]): dy=-1*dy #REBONDS SUR BARRE if (Fond.coords(Balle)[3]>Fond.coords(Barre)[1]) and (Fond.coords(Balle)[0]Fond.coords(Barre)[0]): dy=-1*dy Fond.move(Balle,dx,dy) fenetre.after(1,deplacement) dx=-2 dy=-10 #DEPLACEMENT BARRE def droite(event): Fond.move(Barre,15,0) def gauche(event): Fond.move(Barre,-15,0) Fond.bind_all('',droite) Fond.bind_all('',gauche) #LANCEMENT DU JEU fichier.close() deplacement() fenetre.mainloop()