Aide projet ISN BAC
hugobsh
-
quent217 Messages postés 420 Date d'inscription Statut Membre Dernière intervention -
quent217 Messages postés 420 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Nous avons décidé de réaliser un casse brique en Python à l'aide module Tkinter.
Seulement voilà plusieurs jours que nous sommes bloqué sur un point. En effet la balle rebondit correctement sur la longueur de chaque rectangles (constituant les briques) mais pas sur la largeur. Cela implique plusieurs bugs puisque la balle entre à l'intérieur des rectangles tout en rebondissant sur la longueur de ces derniers.
Pouvez-vous m'aider à résoudre ce problème, je n'arrive vraiment pas à comprendre pourquoi la balle rebondit bien sur la longueur mais pas la largeur alors que j'ai utilisé le même procédé que pour la longueur.
PS : Nous n'avons pas l'autorisation d'utiliser le module PyGame.
Voici les images et le .txt nécessaire à l'exécution du programme : https://drive.google.com/drive/folders/1pTjOzKG2drO9T8tNkByrrbkueRsrCdH8?usp=sharing
Et voilà le programme, en espérant que quelqu'un est en mesure de nous venir en aide.
Cordialement, Hugo B.
Nous avons décidé de réaliser un casse brique en Python à l'aide module Tkinter.
Seulement voilà plusieurs jours que nous sommes bloqué sur un point. En effet la balle rebondit correctement sur la longueur de chaque rectangles (constituant les briques) mais pas sur la largeur. Cela implique plusieurs bugs puisque la balle entre à l'intérieur des rectangles tout en rebondissant sur la longueur de ces derniers.
Pouvez-vous m'aider à résoudre ce problème, je n'arrive vraiment pas à comprendre pourquoi la balle rebondit bien sur la longueur mais pas la largeur alors que j'ai utilisé le même procédé que pour la longueur.
PS : Nous n'avons pas l'autorisation d'utiliser le module PyGame.
Voici les images et le .txt nécessaire à l'exécution du programme : https://drive.google.com/drive/folders/1pTjOzKG2drO9T8tNkByrrbkueRsrCdH8?usp=sharing
Et voilà le programme, en espérant que quelqu'un est en mesure de nous venir en aide.
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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(V[0])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(V[1])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(V[2])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(V[3])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(V[4])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[0])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[1])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[2])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[3])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[4])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[5])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[6])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(J[7])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(R[0])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(R[1])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(R[2])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(R[3])[2]) and (Fond.coords(Balle)[2]>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])[3]) and (Fond.coords(Balle)[0]<Fond.coords(R[4])[2]) and (Fond.coords(Balle)[2]>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)[2]) and (Fond.coords(Balle)[2]>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('<Right>',droite)
Fond.bind_all('<Left>',gauche)
#LANCEMENT DU JEU
fichier.close()
deplacement()
fenetre.mainloop()
Cordialement, Hugo B.
A voir également:
- Aide projet ISN BAC
- Filigrane projet - Guide
- Bac a sable windows - Guide
- Gant projet - Télécharger - Gestion de projets
- Bac 2025 - Guide
- Projet x streaming vf - Forum MacOS