Aide projet ISN BAC
Répondre à la discussion
Affichage des résultats 1 à 3 sur 3

Aide projet ISN BAC



  1. #1
    hugobsh

    Post Aide projet ISN BAC


    ------

    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://www.icloud.com/iclouddrive/0...The_Py_Breaker

    Et voilà le programme, en espérant que quelqu'un est en mesure de nous venir en aide.

    Cordialement, Hugo B.

    Code:
    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()

    -----

  2. #2
    hugobsh

    Re : Aide projet ISN BAC

    Le lien de téléchargement ne semble pas fonctionner pour tout le monde. Voici un nouveau: https://drive.google.com/drive/folde...H8?usp=sharing

  3. #3
    Chanur

    Re : Aide projet ISN BAC

    Bonjour,

    Quand tu calcules tes rebonds, tu ne modifies que dy, jamais dx, (sauf pour les rebonds sur les bords de l'écran).
    Alors forcément, ça ne rebondit pas ...
    Ce qui se conçoit bien s'énonce clairement ; et les mots pour le dire arrivent aisément.

Discussions similaires

  1. [Divers] Aide projet
    Par tenops dans le forum Jardinage
    Réponses: 1
    Dernier message: 24/10/2014, 09h46
  2. Aide sur un projet!
    Par invite78eadbaa dans le forum Physique
    Réponses: 3
    Dernier message: 17/07/2011, 14h26
  3. aide projet pic stp
    Par invited2c377e1 dans le forum Électronique
    Réponses: 1
    Dernier message: 04/06/2011, 05h41
  4. Aide projet
    Par invite5618529c dans le forum Électronique
    Réponses: 3
    Dernier message: 25/05/2009, 13h53
  5. [projet] aide
    Par invite61c076e8 dans le forum Électronique
    Réponses: 11
    Dernier message: 17/04/2006, 17h54